@pickaxeproject/react 6.23.4 → 6.23.5

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.
@@ -31,6 +31,19 @@
31
31
  'transform', 'transform-origin', 'transform-box',
32
32
  'x', 'y', 'cx', 'cy', 'r', 'rx', 'ry', 'd'
33
33
  ];
34
+ // Mermaid HTML labels are static text inside foreignObject. Preserve their
35
+ // measured layout, but never serialize active elements or external resources.
36
+ const labelTags = new Set(['div', 'span', 'p', 'br', 'b', 'strong', 'i', 'em', 'u', 's', 'small', 'sub', 'sup', 'a']);
37
+ const labelProperties = [
38
+ 'display', 'visibility', 'opacity', 'box-sizing', 'width', 'height',
39
+ 'min-width', 'max-width', 'min-height', 'max-height',
40
+ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
41
+ 'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
42
+ 'color', 'background-color', 'font-family', 'font-size', 'font-weight',
43
+ 'font-style', 'line-height', 'letter-spacing', 'word-spacing',
44
+ 'white-space', 'text-align', 'text-decoration', 'text-transform',
45
+ 'vertical-align', 'overflow-wrap', 'word-break', 'direction'
46
+ ];
34
47
  sources.forEach((node, index) => {
35
48
  const target = targets[index];
36
49
  const tag = node.localName.toLowerCase();
@@ -38,7 +51,26 @@
38
51
  target.remove();
39
52
  return;
40
53
  }
41
- if (tag === 'foreignobject') throw new Error('SVG embedded HTML cannot be captured');
54
+ if (node.namespaceURI === 'http://www.w3.org/1999/xhtml') {
55
+ if (!node.closest('foreignObject') || !labelTags.has(tag))
56
+ throw new Error('Unsupported SVG HTML label');
57
+ const computed = getComputedStyle(node);
58
+ if (computed.backgroundImage !== 'none')
59
+ throw new Error('SVG HTML label requires an external resource');
60
+ for (const pseudo of ['::before', '::after']) {
61
+ const content = getComputedStyle(node, pseudo).content;
62
+ if (content && content !== 'none' && content !== 'normal' && content !== '""')
63
+ throw new Error('Unsupported SVG HTML label decoration');
64
+ }
65
+ for (const attr of Array.from(target.attributes)) target.removeAttributeNode(attr);
66
+ labelProperties.forEach(property => {
67
+ const value = computed.getPropertyValue(property);
68
+ if (value) target.style.setProperty(property, safeValue(value));
69
+ });
70
+ return;
71
+ }
72
+ if (node.namespaceURI !== 'http://www.w3.org/2000/svg')
73
+ throw new Error('Unsupported SVG namespace');
42
74
  // Referenced symbols inherit styles through a browser-created shadow tree.
43
75
  // Do not silently flatten them with the wrong colors or missing geometry.
44
76
  if (tag === 'use') throw new Error('SVG symbol instances cannot be captured');
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),t=require("./responseDownloadHtml.js"),o=require("./responseDownloadImages.js");exports.createResponseArtifactWordImages=(r,n)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;let i=t.createResponseDownloadDocument(`<div class="pxe-export-artifact">${r}</div>`,!0);const a=document.createElement("template");a.innerHTML=i;const l=yield o.embedResponseDownloadImages(a.content,"docx");for(const t of a.content.querySelectorAll("img")){if(l.has(t))continue;const o=document.createElement("span");o.textContent=`⚠ ${(null===(e=t.getAttribute("alt"))||void 0===e?void 0:e.trim())||"[…]"}`,t.replaceWith(o)}i=`<!doctype html>\n${a.innerHTML}`;const c=document.createElement("iframe");c.setAttribute("sandbox","allow-same-origin"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.cssText="position:fixed;left:-10000px;top:0;width:720px;height:600px;border:0;pointer-events:none";try{yield new Promise(((e,t)=>{const o=setTimeout((()=>t(new Error("Word snapshot timed out."))),5e3);c.onload=()=>{clearTimeout(o),e()},c.onerror=()=>{clearTimeout(o),t(new Error("Word snapshot failed."))},c.srcdoc=i,document.body.appendChild(c)}));const e=c.contentDocument,t=c.contentWindow,o=null==e?void 0:e.querySelector("main");if(!e||!t||!o)throw new Error("Word snapshot unavailable.");const r=e.createElement("style");r.textContent="main{display:flow-root;width:720px;max-width:none;padding:0;margin:0}\n.pxe-export-artifact{overflow:visible}\n.pxe-export-artifact:has(tr > :nth-child(6)) > div{min-width:0}\ntable{width:100%;table-layout:fixed} pre{white-space:pre-wrap;overflow-wrap:anywhere}\n*{animation:none!important;transition:none!important}",e.head.appendChild(r),e.querySelectorAll("details").forEach((e=>{e.open=!0}));const a=Math.ceil(Math.max(o.scrollWidth,o.getBoundingClientRect().width)),l=Math.ceil(o.getBoundingClientRect().height);if(a>1440||!l||l>16e3)throw new Error("Artifact is too large for a readable Word picture.");const s=o.cloneNode(!0),d=[o,...o.querySelectorAll("*")],h=[s,...s.querySelectorAll("*")];d.forEach(((e,o)=>{const r=h[o],n=t.getComputedStyle(e);r.removeAttribute("style");for(const e of Array.from(n))r.style.setProperty(e,n.getPropertyValue(e))})),s.setAttribute("xmlns","http://www.w3.org/1999/xhtml");const p=(new XMLSerializer).serializeToString(s);if(p.length>1e7)throw new Error("Word snapshot is too large.");const m=o.getBoundingClientRect().top,u=[],w=e.createTreeWalker(o,NodeFilter.SHOW_TEXT);for(;w.nextNode();){const t=e.createRange();t.selectNodeContents(w.currentNode);for(const e of Array.from(t.getClientRects()))e.height&&u.push({top:e.top-m,bottom:e.bottom-m})}o.querySelectorAll("tr,img").forEach((e=>{const t=e.getBoundingClientRect();t.height<=800&&u.push({top:t.top-m,bottom:t.bottom-m})}));const g=[];let f=0;for(let t=0;t<l;){let o=Math.min(l,t+800);if(o<l)for(let e=0;e<u.length;e++){const e=u.find((e=>e.top+1<o&&e.bottom-1>o));if(!e||e.top<=t)break;o=Math.ceil(e.top)}if(o<=t)throw new Error("Unable to paginate artifact picture.");const r=`<svg xmlns="http://www.w3.org/2000/svg" width="${a}" height="${o-t}" viewBox="0 ${t} ${a} ${o-t}"><foreignObject x="0" y="0" width="${a}" height="${l}">${p}</foreignObject></svg>`,i=new Image;yield new Promise(((e,t)=>{const o=setTimeout((()=>n(!1)),5e3),n=r=>{clearTimeout(o),i.onload=i.onerror=null,r?e():t(new Error("Unable to draw Word artifact picture."))};i.onload=()=>n(!0),i.onerror=()=>n(!1),i.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`}));const c=document.createElement("canvas");c.width=2*a,c.height=2*(o-t);const s=c.getContext("2d");if(!s)throw new Error("Word image capture unavailable.");s.fillStyle="white",s.fillRect(0,0,c.width,c.height),s.drawImage(i,0,0,c.width,c.height);const d=c.toDataURL("image/png");if(f+=d.length,f>1e7)throw new Error("Word artifact pictures are too large.");const h=e.createElement("img");h.src=d,h.width=a,h.height=o-t,h.alt=n;const m=e.createElement("p");m.appendChild(h),g.push(m.outerHTML),c.width=c.height=0,i.removeAttribute("src"),t=o}return g.join("")}finally{c.remove()}}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),t=require("./responseDownloadHtml.js"),o=require("./responseDownloadImages.js"),r=require("./responseArtifactStyles.js");exports.createResponseArtifactWordImages=(n,i)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;let a=t.createResponseDownloadDocument(`<div class="pxe-export-artifact">${n}</div>`,!0);const l=document.createElement("template");l.innerHTML=a;const s=yield o.embedResponseDownloadImages(l.content,"docx");for(const t of l.content.querySelectorAll("img")){if(s.has(t))continue;const o=document.createElement("span");o.textContent=`⚠ ${(null===(e=t.getAttribute("alt"))||void 0===e?void 0:e.trim())||"[…]"}`,t.replaceWith(o)}a=`<!doctype html>\n${l.innerHTML}`;const c=document.createElement("iframe");c.setAttribute("sandbox","allow-same-origin"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.cssText="position:fixed;left:-10000px;top:0;width:720px;height:600px;border:0;pointer-events:none";try{yield new Promise(((e,t)=>{const o=setTimeout((()=>t(new Error("Word snapshot timed out."))),5e3);c.onload=()=>{clearTimeout(o),e()},c.onerror=()=>{clearTimeout(o),t(new Error("Word snapshot failed."))},c.srcdoc=a,document.body.appendChild(c)}));const e=c.contentDocument,t=c.contentWindow,o=null==e?void 0:e.querySelector("main");if(!e||!t||!o)throw new Error("Word snapshot unavailable.");const n=e.createElement("style");n.textContent="body > main{display:flow-root;width:720px;max-width:none;padding:0;margin:0}\n.pxe-export-artifact{overflow:visible}\n.pxe-export-artifact:has(tr > :nth-child(6)) > div{min-width:0}\ntable{width:100%;table-layout:fixed} pre{white-space:pre-wrap;overflow-wrap:anywhere}\n*{animation:none!important;transition:none!important}",e.head.appendChild(n),e.querySelectorAll("details").forEach((e=>{e.open=!0}));const l=o.cloneNode(!0),s=[o,...o.querySelectorAll("*")],d=[l,...l.querySelectorAll("*")];s.forEach(((e,o)=>{const n=d[o],i=t.getComputedStyle(e);n.removeAttribute("style");for(const e of[...r.artifactStyleProperties,"direction","unicode-bidi","white-space","overflow-wrap","table-layout"])n.style.setProperty(e,i.getPropertyValue(e));"TABLE"===e.tagName&&(n.style.width="100%"),"IMG"===e.tagName&&(n.style.maxWidth="100%",n.style.height="auto")})),l.style.width="720px",o.replaceWith(l),e.querySelectorAll("style").forEach((e=>e.remove())),e.body.style.margin="0",yield Promise.all(Array.from(l.querySelectorAll("img"),(e=>e.decode())));const h=Math.ceil(Math.max(l.scrollWidth,l.getBoundingClientRect().width)),p=Math.ceil(l.getBoundingClientRect().height);if(h>1440||!p||p>16e3)throw new Error("Artifact is too large for a readable Word picture.");l.setAttribute("xmlns","http://www.w3.org/1999/xhtml");const m=(new XMLSerializer).serializeToString(l);if(m.length>1e7)throw new Error("Word snapshot is too large.");const u=l.getBoundingClientRect().top,w=[],g=e.createTreeWalker(l,NodeFilter.SHOW_TEXT);for(;g.nextNode();){const t=e.createRange();t.selectNodeContents(g.currentNode);for(const e of Array.from(t.getClientRects()))e.height&&w.push({top:e.top-u,bottom:e.bottom-u})}l.querySelectorAll("tr,img").forEach((e=>{const t=e.getBoundingClientRect();t.height<=800&&w.push({top:t.top-u,bottom:t.bottom-u})}));const f=[];let y=0;for(let t=0;t<p;){let o=Math.min(p,t+800);if(o<p)for(let e=0;e<w.length;e++){const e=w.find((e=>e.top+1<o&&e.bottom-1>o));if(!e||e.top<=t)break;o=Math.ceil(e.top)}if(o<=t)throw new Error("Unable to paginate artifact picture.");const r=`<svg xmlns="http://www.w3.org/2000/svg" width="${h}" height="${o-t}" viewBox="0 ${t} ${h} ${o-t}"><foreignObject x="0" y="0" width="${h}" height="${p}">${m}</foreignObject></svg>`,n=new Image;yield new Promise(((e,t)=>{const o=setTimeout((()=>i(!1)),5e3),i=r=>{clearTimeout(o),n.onload=n.onerror=null,r?e():t(new Error("Unable to draw Word artifact picture."))};n.onload=()=>i(!0),n.onerror=()=>i(!1),n.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`}));const a=document.createElement("canvas");a.width=2*h,a.height=2*(o-t);const l=a.getContext("2d");if(!l)throw new Error("Word image capture unavailable.");l.fillStyle="white",l.fillRect(0,0,a.width,a.height),l.drawImage(n,0,0,a.width,a.height);const s=a.toDataURL("image/png");if(y+=s.length,y>1e7)throw new Error("Word artifact pictures are too large.");const c=e.createElement("img");c.src=s,c.width=h,c.height=o-t,c.alt=i;const d=e.createElement("p");d.appendChild(c),f.push(d.outerHTML),a.width=a.height=0,n.removeAttribute("src"),t=o}return f.join("")}finally{c.remove()}}));
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),t=require("react"),r=require("react-dom/server"),n=require("react-markdown"),o=require("remark-gfm"),a=require("rehype-raw"),i=require("uuid"),s=require("./responseArtifactWordImages.js"),c=require("./responseStandaloneSvg.js"),l=require("./responseMermaid.js"),d=require("./responseInteractiveArtifactHtml.js"),p=require("./responseDownloadHtml.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=u(n),m=u(o),v=u(a);const h=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),g=e=>{var t,r;const n=document.createElement("template");return n.innerHTML=p.createResponseDownloadHtml(e),null!==(r=null===(t=n.content.querySelector("main"))||void 0===t?void 0:t.innerHTML)&&void 0!==r?r:""},b=(e,t)=>{const r=[];let n=[],o="",a=!1;for(let i=0;i<e.length;i++){const s=e[i];'"'===s?a&&'"'===e[i+1]?(o+='"',i++):a=!a:a||s!==t&&"\n"!==s&&"\r"!==s?o+=s:(n.push(o),o="",s!==t&&(r.push(n),n=[],"\r"===s&&"\n"===e[i+1]&&i++))}if(a)throw new Error("Incomplete artifact table.");return(o||n.length)&&r.push([...n,o]),`<table>${r.map(((e,t)=>`<tr>${e.map((e=>{const r=t?"td":"th";return`<${r}>${h(e).replace(/\n/g,"<br>")}</${r}>`})).join("")}</tr>`)).join("")}</table>`};exports.findResponseArtifacts=e=>{if(!/<artifact\b/i.test(e))return[];const n=[];return r.renderToStaticMarkup(t.createElement(f.default,{remarkPlugins:[m.default],rehypePlugins:[v.default],components:{artifact:({node:e})=>{var t,r,o,a;const i=null===(t=e.position)||void 0===t?void 0:t.start.offset,s=null===(r=e.position)||void 0===r?void 0:r.end.offset,c=String(null!==(o=e.properties.dataId)&&void 0!==o?o:""),l=Number(null!==(a=e.properties.dataVersion)&&void 0!==a?a:1);if(null==i||null==s||!c||!Number.isInteger(l)||l<1)throw new Error("Invalid response artifact reference.");return n.push({id:c,version:l,start:i,end:s}),null}}},e)),n.sort(((e,t)=>e.start-t.start))},exports.prepareResponseArtifactDownload=(t,r,n,o,a)=>e.__awaiter(void 0,void 0,void 0,(function*(){const e="txt"===o||"md"===o,u=[],f=[];let m=0;for(const d of r){const r=yield n(d);if(r.id!==d.id||r.version!==d.version||r.status&&"finished"!==r.status)throw new Error("Response artifact is not ready.");const p=t.slice(m,d.start);if(u.push(e?p:g(p)),e){const e="`".repeat(Math.max(3,...Array.from(r.content.matchAll(/`+/g),(e=>e[0].length+1))));u.push(`\n\n${r.title}\n\n${"md"===o&&"text/markdown"!==r.type?`${e}\n${r.content}\n${e}`:r.content}\n\n`)}else{let e;switch(r.type){case"text/markdown":e=g(r.content);break;case"text/csv":e=b(r.content,",");break;case"text/tab-separated-values":e=b(r.content,"\t");break;case"application/vnd.pxe.mermaid":e=yield l.createResponseMermaidImage(r.content,r.title);break;case"image/svg+xml":e=yield c.createResponseSvgImage(r.content,r.title);break;case"text/html":if("html"===o){const t=`artifact-${i.v4()}`;f.push({placeholder:t,title:r.title,content:r.content}),e=`<div id="${t}"></div>`;break}e=yield a(r.content),"docx"===o&&(e=yield s.createResponseArtifactWordImages(e,r.title));break;case"application/pdf":e=yield a(r.content);break;case"application/vnd.pxe.code":e=`<pre><code>${h(r.content)}</code></pre>`;break;default:throw new Error(`Artifact export is not supported for ${r.type}.`)}u.push(`<section><h2>${h(r.title)}</h2><div class="pxe-export-artifact">${e}</div></section>`)}m=d.end}return u.push(e?t.slice(m):g(t.slice(m))),e?u.join(""):d.embedInteractiveArtifacts(p.createResponseDownloadDocument(u.join("\n"),"html"===o||"pdf"===o),f)}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),t=require("react"),r=require("react-dom/server"),n=require("react-markdown"),a=require("remark-gfm"),i=require("rehype-raw"),o=require("uuid"),s=require("./responseArtifactWordImages.js"),l=require("./responseStandaloneSvg.js"),c=require("./responseMermaid.js"),d=require("./responseInteractiveArtifactHtml.js"),p=require("./responseDownloadHtml.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=u(n),m=u(a),v=u(i);const h=(e,t)=>{var r;const n=/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\/?([a-z][\w:-]*)(?:[^>"']|"[^"]*"|'[^']*')*>/gi;n.lastIndex=t;let a,i=0;for(;null!==(a=n.exec(e));){const t=null===(r=a[1])||void 0===r?void 0:r.toLowerCase();if(!t)continue;const o=a[0].startsWith("</");if("artifact"===t){if(o?i--:/\/\s*>$/.test(a[0])||i++,0===i)return n.lastIndex}else if(!o&&/^(script|style|textarea|title|xmp|iframe|noembed|noframes)$/.test(t)){const r=new RegExp(`</${t}\\s*>`,"gi");if(r.lastIndex=n.lastIndex,!r.exec(e))break;n.lastIndex=r.lastIndex}}return e.length},x=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),g=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,r;const n=document.createElement("template");return n.innerHTML=yield p.createResponseDownloadHtml(t),null!==(r=null===(e=n.content.querySelector("main"))||void 0===e?void 0:e.innerHTML)&&void 0!==r?r:""})),b=(e,t)=>{const r=[];let n=[],a="",i=!1;for(let o=0;o<e.length;o++){const s=e[o];'"'===s?i&&'"'===e[o+1]?(a+='"',o++):i=!i:i||s!==t&&"\n"!==s&&"\r"!==s?a+=s:(n.push(a),a="",s!==t&&(r.push(n),n=[],"\r"===s&&"\n"===e[o+1]&&o++))}if(i)throw new Error("Incomplete artifact table.");return(a||n.length)&&r.push([...n,a]),`<table>${r.map(((e,t)=>`<tr>${e.map((e=>{const r=t?"td":"th";return`<${r}>${x(e).replace(/\n/g,"<br>")}</${r}>`})).join("")}</tr>`)).join("")}</table>`};exports.findResponseArtifacts=e=>{if(!/<artifact\b/i.test(e))return[];const n=[];r.renderToStaticMarkup(t.createElement(f.default,{remarkPlugins:[m.default],rehypePlugins:[v.default],components:{artifact:({node:t})=>{var r,a,i;const o=null===(r=t.position)||void 0===r?void 0:r.start.offset,s=String(null!==(a=t.properties.dataId)&&void 0!==a?a:""),l=Number(null!==(i=t.properties.dataVersion)&&void 0!==i?i:1);if(null==o||!s||!Number.isInteger(l)||l<1)throw new Error("Invalid response artifact reference.");return n.push({id:s,version:l,start:o,end:h(e,o)}),null}}},e));let a=0;return n.sort(((e,t)=>e.start-t.start)).filter((e=>!(e.start<a)&&(a=e.end,!0)))},exports.prepareResponseArtifactDownload=(t,r,n,a,i)=>e.__awaiter(void 0,void 0,void 0,(function*(){const e="txt"===a||"md"===a,u=[],f=[];let m=0;for(const d of r){const r=yield n(d);if(r.id!==d.id||r.version!==d.version||r.status&&"finished"!==r.status)throw new Error("Response artifact is not ready.");const p=t.slice(m,d.start);if(u.push(e?p:yield g(p)),e){const e="`".repeat(Math.max(3,...Array.from(r.content.matchAll(/`+/g),(e=>e[0].length+1))));u.push(`\n\n${r.title}\n\n${"md"===a&&"text/markdown"!==r.type?`${e}\n${r.content}\n${e}`:r.content}\n\n`)}else{let e;switch(r.type){case"text/markdown":e=yield g(r.content);break;case"text/csv":e=b(r.content,",");break;case"text/tab-separated-values":e=b(r.content,"\t");break;case"application/vnd.pxe.mermaid":e=yield c.createResponseMermaidImage(r.content,r.title);break;case"image/svg+xml":e=yield l.createResponseSvgImage(r.content,r.title);break;case"text/html":if("html"===a){const t=`artifact-${o.v4()}`;f.push({placeholder:t,title:r.title,content:r.content}),e=`<div id="${t}"></div>`;break}e=yield i(r.content),"docx"===a&&(e=yield s.createResponseArtifactWordImages(e,r.title));break;case"application/pdf":e=yield i(r.content);break;case"application/vnd.pxe.code":e=`<pre><code>${x(r.content)}</code></pre>`;break;default:throw new Error(`Artifact export is not supported for ${r.type}.`)}u.push(`<section><h2>${x(r.title)}</h2><div class="pxe-export-artifact">${e}</div></section>`)}m=d.end}return u.push(e?t.slice(m):yield g(t.slice(m))),e?u.join(""):d.embedInteractiveArtifacts(p.createResponseDownloadDocument(u.join("\n"),"html"===a||"pdf"===a),f)}));
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),t=require("docx"),n=require("./responseDownloadHtml.js"),r=require("./responseDownloadImages.js");const a=720,i=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DD","DETAILS","DIV","DL","DT","FIGCAPTION","FIGURE","FOOTER","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","MAIN","NAV","OL","P","PRE","SECTION","SUMMARY","TABLE","UL"]),s=e=>{if(e&&/^(https?:|mailto:|tel:)/i.test(e.trim()))try{return new URL(e.trim()).href}catch(e){return}},o=(e,n)=>{const r=Object.assign({},n);switch(e.tagName){case"STRONG":case"B":r.bold=!0;break;case"EM":case"I":r.italics=!0;break;case"DEL":case"S":case"STRIKE":r.strike=!0;break;case"U":r.underline={type:t.UnderlineType.SINGLE};break;case"CODE":case"KBD":case"SAMP":r.font="Courier New";break;case"SUP":r.superScript=!0;break;case"SUB":r.subScript=!0}return r};exports.createResponseDownloadDocx=(l,c)=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=document.createElement("template");e.innerHTML=null!=c?c:n.createResponseDownloadHtml(l);const d=e.content.querySelector("main");if(!d)throw new Error("Unable to prepare the response document.");const u=yield r.embedResponseDownloadImages(d,"docx"),g=new Map;for(const e of u){const t=e.getAttribute("src")||"";if(t.length>1e7)throw new Error("Artifact image too large.");const n=Uint8Array.from(atob(t.slice(22)),(e=>e.charCodeAt(0))),r=new DataView(n.buffer);if(n.length<24||2303741511!==r.getUint32(0)||218765834!==r.getUint32(4)||1229472850!==r.getUint32(12))throw new Error("Invalid artifact image.");const a=r.getUint32(16),i=r.getUint32(20);if(!a||!i||a*i>16e6)throw new Error("Artifact image dimensions are unsupported.");yield new Promise(((e,n)=>{const r=new Image,s=t=>{clearTimeout(o),r.onload=r.onerror=null,r.removeAttribute("src"),t?e():n(new Error("Unable to read artifact image."))},o=setTimeout((()=>s(!1)),5e3);r.onload=()=>s(r.naturalWidth===a&&r.naturalHeight===i),r.onerror=()=>s(!1),r.src=t}));const s=Number(e.getAttribute("width")),o=s>0?Math.min(1,s/a):1;g.set(e,{data:n,width:a*o,height:i*o})}const h=[],m=(e,n,r)=>Array.from(e).flatMap((e=>{var a;if(3===e.nodeType){const r=e.textContent||"";return[new t.TextRun(Object.assign(Object.assign({},n),{text:(null===(a=e.parentElement)||void 0===a?void 0:a.closest("code"))?r:r.replace(/[\t\n\r ]+/g," ")}))]}if(1!==e.nodeType)return[];const i=e,l=o(i,n);if("BR"===i.tagName)return[new t.TextRun(Object.assign(Object.assign({},n),{break:1}))];if("IMG"===i.tagName){const e=g.get(i);if(e){const n=Math.min(1,Math.max(1,r/15)/e.width,900/e.height);return[new t.ImageRun(Object.assign(Object.assign({type:"png",data:e.data},i.getAttribute("alt")?{altText:{name:i.getAttribute("alt")||""}}:{}),{transformation:{width:e.width*n,height:e.height*n}}))]}const a=s(i.getAttribute("src")),o=i.getAttribute("alt")||a||"[…]",l=[new t.TextRun(Object.assign(Object.assign({},n),{text:o}))];return a&&!i.closest("a")?[new t.ExternalHyperlink({link:a,children:l})]:l}const c="A"===i.tagName?s(i.getAttribute("href")):void 0,d=m(i.childNodes,c?Object.assign(Object.assign({},l),{color:"174EA6",underline:{type:t.UnderlineType.SINGLE}}):l,r);return c?[new t.ExternalHyperlink({link:c,children:d})]:d})),p=(e,n,r={})=>{const a=n.marker&&!n.marker.used?n.marker:void 0;return a&&(a.used=!0),new t.Paragraph(Object.assign(Object.assign(Object.assign({children:e,spacing:{after:160},widowControl:!0},n.indent?{indent:Object.assign({left:n.indent},a?{hanging:360}:{})}:{}),null==a?void 0:a.properties),r))},b=(e,n)=>{var r;const a="OL"===e.tagName;let i="",s=!1;const o=e=>{i=`response-list-${h.length}`,s=0===e,h.push({reference:i,levels:[{level:0,format:t.LevelFormat.DECIMAL,text:s?"0.":"%1.",start:s?1:e,alignment:t.AlignmentType.LEFT}]})},l=e.hasAttribute("reversed"),c=Array.from(e.children).filter((e=>"LI"===e.tagName)),d=Number.parseInt(e.getAttribute("start")||"",10);let u=Number.isFinite(d)?d:l?c.length:1;a&&o(u);const g=[];for(const t of Array.from(e.children)){if("LI"!==t.tagName){g.push(...w([t],n));continue}const e=Number.parseInt(t.getAttribute("value")||"",10);a&&Number.isFinite(e)&&(u=e),a&&(l||s||0===u||Number.isFinite(e))&&o(u),u+=l?-1:1;const c=Object.assign(Object.assign({},n),{indent:Math.min(n.indent+720,5760),marker:{used:!1,properties:a?{numbering:{reference:i,level:0}}:{bullet:{level:0}}}}),d=w(t.childNodes,c);(null===(r=c.marker)||void 0===r?void 0:r.used)||d.unshift(p([],c)),g.push(...d)}return g},f=(e,n)=>{const r=[];let a=0;const i=Array.from(e.querySelectorAll("tr")).filter((t=>t.closest("table")===e)).map(((e,t)=>{let n=0;return{row:e,cells:Array.from(e.children).filter((e=>"TD"===e.tagName||"TH"===e.tagName)).map((e=>{for(;r[n]>t;)n++;const i=t=>Math.min(100,Math.max(1,parseInt(e.getAttribute(t)||"1",10)||1)),s=i("colspan"),o=i("rowspan"),l=n;for(let e=0;e<s;e++)r[n++]=t+o;return a=Math.max(a,n),{cell:e,start:l,columnSpan:s,rowSpan:o}}))}})),s=e=>Math.floor(e*n/a),o=Array.from({length:a},((e,t)=>s(t+1)-s(t))),l=i.flatMap((({row:e,cells:n})=>{var r;return n.length?[new t.TableRow({tableHeader:"THEAD"===(null===(r=e.parentElement)||void 0===r?void 0:r.tagName)||n.every((({cell:e})=>"TH"===e.tagName)),children:n.map((({cell:e,start:n,columnSpan:r,rowSpan:a})=>{const i=s(n+r)-s(n),o=w(e.childNodes,{indent:0,width:Math.max(1,i-200),run:{bold:"TH"===e.tagName}});return o[o.length-1]instanceof t.Paragraph||o.push(new t.Paragraph("")),new t.TableCell(Object.assign({children:o,columnSpan:r,rowSpan:a,width:{size:i,type:t.WidthType.DXA},margins:{top:80,bottom:80,left:100,right:100}},"TH"===e.tagName?{shading:{fill:"F0F0F0"}}:{}))}))})]:[]})),c=Array.from(e.children).filter((e=>"CAPTION"===e.tagName));return l.length?[...w(c,{indent:0,width:n,run:{}}),new t.Table({rows:l,width:{size:n,type:t.WidthType.DXA},columnWidths:o})]:w(e.childNodes,{indent:0,width:n,run:{}})},w=(e,n)=>{const r=[];let a=[];const s=()=>{a.some((e=>{var t;return(null===(t=e.textContent)||void 0===t?void 0:t.trim())||1===e.nodeType&&/^(BR|IMG)$/.test(e.tagName)||1===e.nodeType&&e.querySelector("br,img")}))&&r.push(p(m(a,n.run,n.width-n.indent),n)),a=[]};for(const l of Array.from(e)){if(1!==l.nodeType||!i.has(l.tagName)){1===l.nodeType&&Array.from(l.children).some((e=>i.has(e.tagName)))?(s(),r.push(...w(l.childNodes,Object.assign(Object.assign({},n),{run:o(l,n.run)})))):a.push(l);continue}s();const e=l,c=e.tagName;if("UL"===c||"OL"===c)n.marker&&!n.marker.used&&r.push(p([],n)),r.push(...b(e,n));else if("TABLE"===c)n.marker&&!n.marker.used&&r.push(p([],n)),r.push(...f(e,n.width));else if("PRE"===c){const a=(e.textContent||"").replace(/\r\n?/g,"\n").split("\n");r.push(p(a.map(((e,r)=>new t.TextRun(Object.assign(Object.assign(Object.assign({},n.run),{children:e.split("\t").flatMap(((e,n)=>n?[new t.Tab,e]:[e])),font:"Courier New",size:20}),r?{break:1}:{})))),n,{shading:{fill:"F4F4F4"},spacing:{before:120,after:160}}))}else if(/^H[1-6]$/.test(c)){const a=[t.HeadingLevel.HEADING_1,t.HeadingLevel.HEADING_2,t.HeadingLevel.HEADING_3,t.HeadingLevel.HEADING_4,t.HeadingLevel.HEADING_5,t.HeadingLevel.HEADING_6];r.push(p(m(e.childNodes,Object.assign(Object.assign({},n.run),{bold:!0,color:"202020"}),n.width-n.indent),n,{heading:a[Number(c[1])-1],keepNext:!0}))}else if("HR"===c)r.push(p([],n,{border:{bottom:{style:t.BorderStyle.SINGLE,color:"CCCCCC",size:4}}}));else{const t="BLOCKQUOTE"===c?Object.assign(Object.assign({},n),{indent:n.indent+360}):n,a=w(e.childNodes,t);r.push(...a),a.length||"P"!==c||r.push(p([],t))}}return s(),r},A=w(d.childNodes,{indent:0,width:10800,run:{}}),N=new t.Document({title:"Pickaxe",creator:"Pickaxe",styles:{default:{document:{run:{font:"Arial",size:22,color:"202020"}}}},numbering:{config:h},sections:[{properties:{page:{size:{width:12240,height:15840},margin:{top:a,bottom:a,left:a,right:a}}},children:A.length?A:[new t.Paragraph("")]}]});return t.Packer.toBlob(N)}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),t=require("docx"),n=require("./responseDownloadHtml.js"),r=require("./responseDownloadImages.js");const a=720,i=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DD","DETAILS","DIV","DL","DT","FIGCAPTION","FIGURE","FOOTER","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","MAIN","NAV","OL","P","PRE","SECTION","SUMMARY","TABLE","UL"]),s=e=>{if(e&&/^(https?:|mailto:|tel:)/i.test(e.trim()))try{return new URL(e.trim()).href}catch(e){return}},o=(e,n)=>{const r=Object.assign({},n);switch(e.tagName){case"STRONG":case"B":r.bold=!0;break;case"EM":case"I":r.italics=!0;break;case"DEL":case"S":case"STRIKE":r.strike=!0;break;case"U":r.underline={type:t.UnderlineType.SINGLE};break;case"CODE":case"KBD":case"SAMP":r.font="Courier New";break;case"SUP":r.superScript=!0;break;case"SUB":r.subScript=!0}return r};exports.createResponseDownloadDocx=(l,c)=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=document.createElement("template");e.innerHTML=null!=c?c:yield n.createResponseDownloadHtml(l);const d=e.content.querySelector("main");if(!d)throw new Error("Unable to prepare the response document.");const u=yield r.embedResponseDownloadImages(d,"docx"),g=new Map;for(const e of u){const t=e.getAttribute("src")||"";if(t.length>1e7)throw new Error("Artifact image too large.");const n=Uint8Array.from(atob(t.slice(22)),(e=>e.charCodeAt(0))),r=new DataView(n.buffer);if(n.length<24||2303741511!==r.getUint32(0)||218765834!==r.getUint32(4)||1229472850!==r.getUint32(12))throw new Error("Invalid artifact image.");const a=r.getUint32(16),i=r.getUint32(20);if(!a||!i||a*i>16e6)throw new Error("Artifact image dimensions are unsupported.");yield new Promise(((e,n)=>{const r=new Image,s=t=>{clearTimeout(o),r.onload=r.onerror=null,r.removeAttribute("src"),t?e():n(new Error("Unable to read artifact image."))},o=setTimeout((()=>s(!1)),5e3);r.onload=()=>s(r.naturalWidth===a&&r.naturalHeight===i),r.onerror=()=>s(!1),r.src=t}));const s=Number(e.getAttribute("width")),o=s>0?Math.min(1,s/a):1;g.set(e,{data:n,width:a*o,height:i*o})}const h=[],m=(e,n,r)=>Array.from(e).flatMap((e=>{var a;if(3===e.nodeType){const r=e.textContent||"";return[new t.TextRun(Object.assign(Object.assign({},n),{text:(null===(a=e.parentElement)||void 0===a?void 0:a.closest("code"))?r:r.replace(/[\t\n\r ]+/g," ")}))]}if(1!==e.nodeType)return[];const i=e,l=o(i,n);if("BR"===i.tagName)return[new t.TextRun(Object.assign(Object.assign({},n),{break:1}))];if("IMG"===i.tagName){const e=g.get(i);if(e){const n=Math.min(1,Math.max(1,r/15)/e.width,900/e.height);return[new t.ImageRun(Object.assign(Object.assign({type:"png",data:e.data},i.getAttribute("alt")?{altText:{name:i.getAttribute("alt")||""}}:{}),{transformation:{width:e.width*n,height:e.height*n}}))]}const a=s(i.getAttribute("src")),o=i.getAttribute("alt")||a||"[…]",l=[new t.TextRun(Object.assign(Object.assign({},n),{text:o}))];return a&&!i.closest("a")?[new t.ExternalHyperlink({link:a,children:l})]:l}const c="A"===i.tagName?s(i.getAttribute("href")):void 0,d=m(i.childNodes,c?Object.assign(Object.assign({},l),{color:"174EA6",underline:{type:t.UnderlineType.SINGLE}}):l,r);return c?[new t.ExternalHyperlink({link:c,children:d})]:d})),p=(e,n,r={})=>{const a=n.marker&&!n.marker.used?n.marker:void 0;return a&&(a.used=!0),new t.Paragraph(Object.assign(Object.assign(Object.assign({children:e,spacing:{after:160},widowControl:!0},n.indent?{indent:Object.assign({left:n.indent},a?{hanging:360}:{})}:{}),null==a?void 0:a.properties),r))},b=(e,n)=>{var r;const a="OL"===e.tagName;let i="",s=!1;const o=e=>{i=`response-list-${h.length}`,s=0===e,h.push({reference:i,levels:[{level:0,format:t.LevelFormat.DECIMAL,text:s?"0.":"%1.",start:s?1:e,alignment:t.AlignmentType.LEFT}]})},l=e.hasAttribute("reversed"),c=Array.from(e.children).filter((e=>"LI"===e.tagName)),d=Number.parseInt(e.getAttribute("start")||"",10);let u=Number.isFinite(d)?d:l?c.length:1;a&&o(u);const g=[];for(const t of Array.from(e.children)){if("LI"!==t.tagName){g.push(...w([t],n));continue}const e=Number.parseInt(t.getAttribute("value")||"",10);a&&Number.isFinite(e)&&(u=e),a&&(l||s||0===u||Number.isFinite(e))&&o(u),u+=l?-1:1;const c=Object.assign(Object.assign({},n),{indent:Math.min(n.indent+720,5760),marker:{used:!1,properties:a?{numbering:{reference:i,level:0}}:{bullet:{level:0}}}}),d=w(t.childNodes,c);(null===(r=c.marker)||void 0===r?void 0:r.used)||d.unshift(p([],c)),g.push(...d)}return g},f=(e,n)=>{const r=[];let a=0;const i=Array.from(e.querySelectorAll("tr")).filter((t=>t.closest("table")===e)).map(((e,t)=>{let n=0;return{row:e,cells:Array.from(e.children).filter((e=>"TD"===e.tagName||"TH"===e.tagName)).map((e=>{for(;r[n]>t;)n++;const i=t=>Math.min(100,Math.max(1,parseInt(e.getAttribute(t)||"1",10)||1)),s=i("colspan"),o=i("rowspan"),l=n;for(let e=0;e<s;e++)r[n++]=t+o;return a=Math.max(a,n),{cell:e,start:l,columnSpan:s,rowSpan:o}}))}})),s=e=>Math.floor(e*n/a),o=Array.from({length:a},((e,t)=>s(t+1)-s(t))),l=i.flatMap((({row:e,cells:n})=>{var r;return n.length?[new t.TableRow({tableHeader:"THEAD"===(null===(r=e.parentElement)||void 0===r?void 0:r.tagName)||n.every((({cell:e})=>"TH"===e.tagName)),children:n.map((({cell:e,start:n,columnSpan:r,rowSpan:a})=>{const i=s(n+r)-s(n),o=w(e.childNodes,{indent:0,width:Math.max(1,i-200),run:{bold:"TH"===e.tagName}});return o[o.length-1]instanceof t.Paragraph||o.push(new t.Paragraph("")),new t.TableCell(Object.assign({children:o,columnSpan:r,rowSpan:a,width:{size:i,type:t.WidthType.DXA},margins:{top:80,bottom:80,left:100,right:100}},"TH"===e.tagName?{shading:{fill:"F0F0F0"}}:{}))}))})]:[]})),c=Array.from(e.children).filter((e=>"CAPTION"===e.tagName));return l.length?[...w(c,{indent:0,width:n,run:{}}),new t.Table({rows:l,width:{size:n,type:t.WidthType.DXA},columnWidths:o})]:w(e.childNodes,{indent:0,width:n,run:{}})},w=(e,n)=>{const r=[];let a=[];const s=()=>{a.some((e=>{var t;return(null===(t=e.textContent)||void 0===t?void 0:t.trim())||1===e.nodeType&&/^(BR|IMG)$/.test(e.tagName)||1===e.nodeType&&e.querySelector("br,img")}))&&r.push(p(m(a,n.run,n.width-n.indent),n)),a=[]};for(const l of Array.from(e)){if(1!==l.nodeType||!i.has(l.tagName)){1===l.nodeType&&Array.from(l.children).some((e=>i.has(e.tagName)))?(s(),r.push(...w(l.childNodes,Object.assign(Object.assign({},n),{run:o(l,n.run)})))):a.push(l);continue}s();const e=l,c=e.tagName;if("UL"===c||"OL"===c)n.marker&&!n.marker.used&&r.push(p([],n)),r.push(...b(e,n));else if("TABLE"===c)n.marker&&!n.marker.used&&r.push(p([],n)),r.push(...f(e,n.width));else if("PRE"===c){const a=(e.textContent||"").replace(/\r\n?/g,"\n").split("\n");r.push(p(a.map(((e,r)=>new t.TextRun(Object.assign(Object.assign(Object.assign({},n.run),{children:e.split("\t").flatMap(((e,n)=>n?[new t.Tab,e]:[e])),font:"Courier New",size:20}),r?{break:1}:{})))),n,{shading:{fill:"F4F4F4"},spacing:{before:120,after:160}}))}else if(/^H[1-6]$/.test(c)){const a=[t.HeadingLevel.HEADING_1,t.HeadingLevel.HEADING_2,t.HeadingLevel.HEADING_3,t.HeadingLevel.HEADING_4,t.HeadingLevel.HEADING_5,t.HeadingLevel.HEADING_6];r.push(p(m(e.childNodes,Object.assign(Object.assign({},n.run),{bold:!0,color:"202020"}),n.width-n.indent),n,{heading:a[Number(c[1])-1],keepNext:!0}))}else if("HR"===c)r.push(p([],n,{border:{bottom:{style:t.BorderStyle.SINGLE,color:"CCCCCC",size:4}}}));else{const t="BLOCKQUOTE"===c?Object.assign(Object.assign({},n),{indent:n.indent+360}):n,a=w(e.childNodes,t);r.push(...a),a.length||"P"!==c||r.push(p([],t))}}return s(),r},A=w(d.childNodes,{indent:0,width:10800,run:{}}),N=new t.Document({title:"Pickaxe",creator:"Pickaxe",styles:{default:{document:{run:{font:"Arial",size:22,color:"202020"}}}},numbering:{config:h},sections:[{properties:{page:{size:{width:12240,height:15840},margin:{top:a,bottom:a,left:a,right:a}}},children:A.length?A:[new t.Paragraph("")]}]});return t.Packer.toBlob(N)}));
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),t=require("react"),r=require("react-dom/server"),n=require("react-markdown"),o=require("remark-gfm"),a=require("rehype-raw"),i=require("isomorphic-dompurify"),l=require("./responseArtifactStyles.js");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=d(n),p=d(o),s=d(a),h=d(i);const w=e=>{const n=r.renderToStaticMarkup(t.createElement(c.default,{remarkPlugins:[p.default],rehypePlugins:[s.default],components:{input:({type:e,checked:r})=>"checkbox"===(null==e?void 0:e.toLowerCase())?t.createElement("span",null,r?"☑":"☐"):null}},e));return m(n)},m=(e,t=!1)=>{let r=h.default.sanitize(e,{USE_PROFILES:{html:!0},FORBID_TAGS:["script","style","iframe","form","input","button","select","textarea","object","embed","link","meta","base","audio","video","source","track"],FORBID_ATTR:["srcset","ping","background",...t?[]:["style"]],ALLOW_DATA_ATTR:!1});if(t){const e=document.createElement("template");e.innerHTML=r,l.filterArtifactStyles(e.content),e.content.querySelectorAll("label").forEach((e=>{var t;(null===(t=e.textContent)||void 0===t?void 0:t.trim())||e.children.length||e.remove()})),r=e.innerHTML}return`<!doctype html>\n<html>\n<head>\n<meta charset="utf-8">\n<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src https: data:; base-uri 'none'; form-action 'none'">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>Pickaxe</title>\n<style>\nbody { margin: 0; background: white; color: #202020; font: 16px/1.6 system-ui, sans-serif; }\nmain { max-width: 900px; margin: 0 auto; padding: 24px; overflow-wrap: anywhere; }\nh1, h2, h3, h4, h5, h6 { line-height: 1.25; }\na { color: #174ea6; }\npre, code { font-family: ui-monospace, monospace; }\npre { padding: 16px; background: #f4f4f4; overflow-x: auto; white-space: pre; }\nblockquote { margin-left: 0; padding-left: 16px; border-left: 3px solid #ccc; }\ntable { border-collapse: collapse; max-width: 100%; }\nth, td { border: 1px solid #ccc; padding: 8px; text-align: start; }\nimg { max-width: 100%; height: auto; }\nsummary { cursor: pointer; }\n${t?"\n.pxe-export-artifact { max-width: 100%; overflow-x: auto; }\n.pxe-export-artifact:has(tr > :nth-child(6)) > div { min-width: 720px; }\n.pxe-export-artifact table { width: 100%; max-width: 100%; }\n.pxe-export-artifact th, .pxe-export-artifact td { overflow-wrap: anywhere; }\n@media print {\n .pxe-export-artifact { overflow: visible; }\n .pxe-export-artifact:has(tr > :nth-child(6)) > div { min-width: 0; }\n .pxe-export-artifact table { width: 100%; min-width: 0; max-width: 100%; table-layout: fixed; }\n .pxe-export-artifact th, .pxe-export-artifact td { padding: 5px !important; font-size: 10px !important; overflow-wrap: anywhere; }\n .pxe-export-artifact, .pxe-export-artifact * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }\n}\n":""}</style>\n</head>\n<body><main dir="auto">${r}</main></body>\n</html>`},u=(t,r)=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=null!=r?r:window.open("","_blank");if(!e||e.closed)throw new Error("Unable to open the response print window.");try{e.opener=null;const r=e.document;r.open(),r.write(t);const n=r.createElement("style");if(n.media="print",n.textContent="\n@page { margin: 12mm; }\nmain { max-width: none; padding: 0; }\npre { overflow: visible; }\npre, pre code { white-space: pre-wrap; overflow-wrap: anywhere; }\ntable { width: 100%; table-layout: fixed; }\nth, td { white-space: normal; overflow-wrap: anywhere; }\nthead { display: table-header-group; }\ntr, img { break-inside: avoid; }\nh1, h2, h3, h4, h5, h6 { break-after: avoid; }\np, li { orphans: 3; widows: 3; }\n",r.head.appendChild(n),r.querySelectorAll("details").forEach((e=>{e.open=!0})),r.querySelectorAll("img").forEach((e=>{e.loading="eager"})),r.close(),e.focus(),yield f(e,r),e.closed)throw new Error("The response print window was closed.");r.body.offsetHeight,e.focus(),e.print()}catch(t){throw e.close(),t}})),f=(t,r)=>new Promise(((n,o)=>{const a=new Set(Array.from(r.images)),i=e=>{if(c)return;a.delete(e);const t=r.createElement("span");t.textContent=`⚠ ${e.alt.trim()||"[…]"}`,t.style.cssText="display:inline-block;border:1px solid #999;padding:4px;white-space:normal;overflow-wrap:anywhere;",e.removeAttribute("src"),e.removeAttribute("srcset"),e.replaceWith(t)},l=window.setTimeout((()=>{a.forEach(i),p()}),15e3),d=window.setInterval((()=>{t.closed&&p(new Error("The response print window was closed."))}),100);let c=!1;function p(e){c||(c=!0,window.clearTimeout(l),window.clearInterval(d),e?o(e):n())}Promise.all([...Array.from(a,(t=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if(yield t.decode(),!t.complete||!t.naturalWidth||!t.naturalHeight)throw new Error("Unable to load a response print image.");a.delete(t)}catch(e){i(t)}})))),r.fonts.ready]).then((()=>p()),(()=>p(new Error("Unable to load the response print resources."))))}));exports.createResponseDownloadDocument=m,exports.createResponseDownloadHtml=w,exports.printResponseDownloadDocument=u,exports.printResponseDownloadHtml=e=>u(w(e));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),t=require("react"),r=require("react-dom/server"),n=require("react-markdown"),o=require("remark-gfm"),a=require("rehype-raw"),i=require("isomorphic-dompurify"),l=require("./responseArtifactStyles.js"),c=require("./responseStandaloneSvg.js");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=d(n),p=d(o),h=d(a),m=d(i);const u=n=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,o,a;const i=r.renderToStaticMarkup(t.createElement(s.default,{remarkPlugins:[p.default],rehypePlugins:[h.default],components:{input:({type:e,checked:r})=>"checkbox"===(null==e?void 0:e.toLowerCase())?t.createElement("span",null,r?"☑":"☐"):null}},n)),l=document.createElement("template");l.innerHTML=i;const d=(e=>{var t;let r=!1;const n=new Set(Array.from(e.querySelectorAll("img[src]"),(e=>e.getAttribute("src"))));for(const o of e.querySelectorAll("a[href]"))if(!o.closest("pre,code")&&!o.querySelector("img"))try{const e=new URL(o.getAttribute("href")||""),a=decodeURIComponent(e.pathname.split("/").pop()||"");if("https:"!==e.protocol||e.username||e.password||!e.pathname.includes("/action_generated_files/")||!/\.(png|jpe?g|gif|webp|svg)$/i.test(a)||n.has(e.href))continue;n.add(e.href);const i=document.createElement("img");i.src=e.href,i.alt=(null===(t=o.textContent)||void 0===t?void 0:t.trim())||a;const l=document.createElement("span");o.replaceWith(l),l.append(o,document.createElement("br"),i),r=!0}catch(e){}return r})(l.content),m=Array.from(l.content.querySelectorAll("svg")).filter((e=>{var t;return!(null===(t=e.parentElement)||void 0===t?void 0:t.closest("svg"))}));if(!m.length&&!d)return w(i);for(const t of m)try{const e=yield c.createResponseSvgImage(t.outerHTML,""),r=document.createElement("template");r.innerHTML=e,t.replaceWith(r.content)}catch(r){const n=document.createElement("span");n.textContent=`⚠ ${(null===(e=t.getAttribute("aria-label"))||void 0===e?void 0:e.trim())||(null===(a=null===(o=t.querySelector("title"))||void 0===o?void 0:o.textContent)||void 0===a?void 0:a.trim())||"[…]"}`,t.replaceWith(n)}return w(l.innerHTML)})),w=(e,t=!1)=>{let r=m.default.sanitize(e,{USE_PROFILES:{html:!0},FORBID_TAGS:["script","style","iframe","form","input","button","select","textarea","object","embed","link","meta","base","audio","video","source","track"],FORBID_ATTR:["srcset","ping","background",...t?[]:["style"]],ALLOW_DATA_ATTR:!1});if(t){const e=document.createElement("template");e.innerHTML=r,l.filterArtifactStyles(e.content),e.content.querySelectorAll("label").forEach((e=>{var t;(null===(t=e.textContent)||void 0===t?void 0:t.trim())||e.children.length||e.remove()})),r=e.innerHTML}return`<!doctype html>\n<html>\n<head>\n<meta charset="utf-8">\n<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src https: data:; base-uri 'none'; form-action 'none'">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>Pickaxe</title>\n<style>\nbody { margin: 0; background: white; color: #202020; font: 16px/1.6 system-ui, sans-serif; }\nmain { max-width: 900px; margin: 0 auto; padding: 24px; overflow-wrap: anywhere; }\nh1, h2, h3, h4, h5, h6 { line-height: 1.25; }\na { color: #174ea6; }\npre, code { font-family: ui-monospace, monospace; }\npre { padding: 16px; background: #f4f4f4; overflow-x: auto; white-space: pre; }\nblockquote { margin-left: 0; padding-left: 16px; border-left: 3px solid #ccc; }\ntable { border-collapse: collapse; max-width: 100%; }\nth, td { border: 1px solid #ccc; padding: 8px; text-align: start; }\nimg { max-width: 100%; height: auto; }\nsummary { cursor: pointer; }\n${t?"\n.pxe-export-artifact { max-width: 100%; overflow-x: auto; }\n.pxe-export-artifact:has(tr > :nth-child(6)) > div { min-width: 720px; }\n.pxe-export-artifact table { width: 100%; max-width: 100%; }\n.pxe-export-artifact th, .pxe-export-artifact td { overflow-wrap: anywhere; }\n@media print {\n .pxe-export-artifact { overflow: visible; }\n .pxe-export-artifact:has(tr > :nth-child(6)) > div { min-width: 0; }\n .pxe-export-artifact table { width: 100%; min-width: 0; max-width: 100%; table-layout: fixed; }\n .pxe-export-artifact th, .pxe-export-artifact td { padding: 5px !important; font-size: 10px !important; overflow-wrap: anywhere; }\n .pxe-export-artifact, .pxe-export-artifact * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }\n}\n":""}</style>\n</head>\n<body><main dir="auto">${r}</main></body>\n</html>`},f=(t,r)=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=null!=r?r:window.open("","_blank");if(!e||e.closed)throw new Error("Unable to open the response print window.");try{e.opener=null;const r=e.document;r.open(),r.write(t);const n=r.createElement("style");if(n.media="print",n.textContent="\n@page { margin: 12mm; }\nmain { max-width: none; padding: 0; }\npre { overflow: visible; }\npre, pre code { white-space: pre-wrap; overflow-wrap: anywhere; }\ntable { width: 100%; table-layout: fixed; }\nth, td { white-space: normal; overflow-wrap: anywhere; }\nthead { display: table-header-group; }\ntr, img { break-inside: avoid; }\nh1, h2, h3, h4, h5, h6 { break-after: avoid; }\np, li { orphans: 3; widows: 3; }\n",r.head.appendChild(n),r.querySelectorAll("details").forEach((e=>{e.open=!0})),r.querySelectorAll("img").forEach((e=>{e.loading="eager"})),r.close(),e.focus(),yield x(e,r),e.closed)throw new Error("The response print window was closed.");r.body.offsetHeight,e.focus(),e.print()}catch(t){throw e.close(),t}})),x=(t,r)=>new Promise(((n,o)=>{const a=new Set(Array.from(r.images)),i=e=>{if(d)return;a.delete(e);const t=r.createElement("span");t.textContent=`⚠ ${e.alt.trim()||"[…]"}`,t.style.cssText="display:inline-block;border:1px solid #999;padding:4px;white-space:normal;overflow-wrap:anywhere;",e.removeAttribute("src"),e.removeAttribute("srcset"),e.replaceWith(t)},l=window.setTimeout((()=>{a.forEach(i),s()}),15e3),c=window.setInterval((()=>{t.closed&&s(new Error("The response print window was closed."))}),100);let d=!1;function s(e){d||(d=!0,window.clearTimeout(l),window.clearInterval(c),e?o(e):n())}Promise.all([...Array.from(a,(t=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if(yield t.decode(),!t.complete||!t.naturalWidth||!t.naturalHeight)throw new Error("Unable to load a response print image.");a.delete(t)}catch(e){i(t)}})))),r.fonts.ready]).then((()=>s()),(()=>s(new Error("Unable to load the response print resources."))))}));exports.createResponseDownloadDocument=w,exports.createResponseDownloadHtml=u,exports.printResponseDownloadDocument=f,exports.printResponseDownloadHtml=t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=window.open("","_blank");if(!e)throw new Error("Unable to open the response print window.");e.opener=null;try{yield f(yield u(t),e)}catch(t){throw e.close(),t}}));
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.embedInteractiveArtifacts=(e,t)=>{var r;if(!t.length)return e;const n=(new DOMParser).parseFromString(e,"text/html"),i=n.querySelector('meta[http-equiv="Content-Security-Policy"]');if(!i)throw new Error("Missing response document policy.");i.setAttribute("content",i.getAttribute("content").replace("script-src 'none'","script-src 'unsafe-inline'"));const o=n.createElement("style");o.textContent="\nmain { max-width: 1200px; }\nmain > * { max-width: 900px; margin-left: auto; margin-right: auto; }\nmain > .pxe-interactive-section { max-width: none; }\n@media (max-width: 600px) { main { padding: 12px; } }\n",n.head.appendChild(o);for(const e of t){const t=n.getElementById(e.placeholder);if(!t)throw new Error("Missing response artifact placeholder.");null===(r=t.closest("section"))||void 0===r||r.classList.add("pxe-interactive-section");const i=n.createElement("iframe");i.setAttribute("sandbox","allow-scripts"),i.setAttribute("referrerpolicy","no-referrer"),i.title=e.title,i.style.cssText="display:block;width:100%;height:85vh;min-height:360px;border:0;resize:vertical;overflow:auto;",i.srcdoc=e.content,t.replaceWith(i)}return`<!doctype html>\n${n.documentElement.outerHTML}`};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=t=>{var e;const n=new Set;for(const r of t){const t=document.createElement("template");t.innerHTML=r.content;for(const r of t.content.querySelectorAll("script[src]"))try{const t=new URL(null!==(e=r.getAttribute("src"))&&void 0!==e?e:"");t.username||t.password||!/^https:\/\/[a-z0-9.-]+(?::\d+)?$/i.test(t.origin)||n.add(t.origin)}catch(t){}}return[...n]};exports.embedInteractiveArtifacts=(e,n)=>{var r;if(!n.length)return e;const i=(new DOMParser).parseFromString(e,"text/html"),o=i.querySelector('meta[http-equiv="Content-Security-Policy"]');if(!o)throw new Error("Missing response document policy.");const s=["'unsafe-inline'",...t(n)].join(" ");o.setAttribute("content",o.getAttribute("content").replace("script-src 'none'",`script-src ${s}`));const c=i.createElement("style");c.textContent="\nmain { max-width: 1200px; }\nmain > * { max-width: 900px; margin-left: auto; margin-right: auto; }\nmain > .pxe-interactive-section { max-width: none; }\n@media (max-width: 600px) { main { padding: 12px; } }\n",i.head.appendChild(c);for(const t of n){const e=i.getElementById(t.placeholder);if(!e)throw new Error("Missing response artifact placeholder.");null===(r=e.closest("section"))||void 0===r||r.classList.add("pxe-interactive-section");const n=i.createElement("iframe");n.setAttribute("sandbox","allow-scripts"),n.setAttribute("referrerpolicy","no-referrer"),n.title=t.title,n.style.cssText="display:block;width:100%;height:85vh;min-height:360px;border:0;resize:vertical;overflow:auto;",n.srcdoc=t.content,e.replaceWith(n)}return`<!doctype html>\n${i.documentElement.outerHTML}`};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),o=require("react"),n=require("react-dom"),r=require("uuid"),s=require("file-saver"),i=require("../../../common/responseDownloadDocx.js"),l=require("../../../common/responseDownloadImages.js"),a=require("../../../common/responseDownloadHtml.js"),u=require("../../../common/responseDownloadArtifacts.js"),d=require("../../../common/responseArtifactSnapshot.js"),c=require("../Addons/Artifact/hooks/useArtifactContext.js"),f=require("../Addons/Artifact/hooks/useArtifactData.js"),p=require("../Addons/Auth/hooks/useAuthContext.js"),m=require("../../../hooks/pickaxe/usePickaxeContext.js"),x=require("../../../hooks/core/useOutsideAlerter.js"),v=require("../../Icons/download.svg.js"),w=require("../../Core/Menu/index.js"),y=require("../../Core/Menu/List.js");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var b=h(s);const g=[{extension:"txt",label:"TXT",mimeType:"text/plain;charset=utf-8"},{extension:"md",label:"Markdown (.md)",mimeType:"text/markdown;charset=utf-8"},{extension:"html",label:"HTML (.html)",mimeType:"text/html;charset=utf-8"},{extension:"pdf",label:"PDF"},{extension:"docx",label:"DOCX"}];exports.default=({color:s,text:h,disabled:j=!1})=>{const{translations:k,colors:A,styles:D,isRtl:q,sender:C,senderType:O,pickaxe:R}=m.usePickaxeContext(),{artifacts:T=[]}=c.useArtifactContext(),{token:S}=p.useAuthContext(),P=f.useArtifactData(),[_,E]=o.useState(""),[H,I]=o.useState(!1),[M,N]=o.useState(),[$,B]=o.useState(!1),F=o.useRef(!1),L=o.useRef(null),K=o.useRef(null),U=o.useRef([]),X=o.useRef(0),W=(null==k?void 0:k.download)||"Download",z=j||$||!h.trim();o.useEffect((()=>{E(`response-download-${r.v4()}`)}),[]),o.useEffect((()=>{z&&I(!1)}),[z]),o.useEffect((()=>{H&&L.current&&N(getComputedStyle(L.current).fontFamily)}),[H,D.font]),x.useOutsideAlerter({ref:[L,K],callback:()=>I(!1)});const G=()=>{var e;I(!1),null===(e=L.current)||void 0===e||e.focus({preventScroll:!0})},J=e=>{var t;if(!z)if("Escape"===e.key&&H)e.preventDefault(),e.stopPropagation(),G();else if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault(),e.stopPropagation();const o=U.current.indexOf(e.currentTarget),n="ArrowDown"===e.key?1:-1,r=g.length,s=-1===o?1===n?0:r-1:(o+n+r)%r;X.current=s,I(!0),null===(t=U.current[s])||void 0===t||t.focus({preventScroll:!0})}else"Tab"===e.key&&I(!1)},Q=e=>{e.relatedTarget===L.current||U.current.some((t=>t===e.relatedTarget))||I(!1)};return t.jsxs(w.default,Object.assign({id:_,className:"h-4 w-4 shrink-0",isOpen:H&&!z,onChange:I,closeOnSelect:!1,closeOnClickOutside:!1},{children:[t.jsx("button",Object.assign({ref:L,id:_||void 0,type:"button",className:"flex h-4 w-4 shrink-0 items-center justify-center rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-30",style:{color:s},title:W,"aria-label":W,"aria-haspopup":"menu","aria-busy":$,"aria-expanded":H&&!z,"aria-controls":H&&!z?`${_}-menu`:void 0,disabled:z,onClick:e=>{e.stopPropagation(),X.current=0,I((e=>!e))},onKeyDown:J,onBlur:Q},{children:t.jsx(v.default,{className:"h-4 w-4 shrink-0","aria-hidden":"true"})})),_&&!z&&n.createPortal(t.jsx("div",Object.assign({ref:K,style:{fontFamily:M},dir:q?"rtl":"ltr"},{children:t.jsx(y.default,Object.assign({id:`${_}-menu`,role:"menu",align:"right",width:"auto",className:"p-1 text-sm",style:{backgroundColor:A.primary,color:A.text,maxWidth:"calc(100vw - 32px)"},imperativeModeOnly:!0,afterShow:()=>{var e;return null===(e=U.current[X.current])||void 0===e?void 0:e.focus({preventScroll:!0})}},{children:g.map(((o,n)=>t.jsx("button",Object.assign({ref:e=>{U.current[n]=e},type:"button",role:"menuitem",tabIndex:-1,className:"rounded-sm px-3 py-2 text-left hover:bg-black/10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-[-2px]",onClick:t=>{((t,o)=>{e.__awaiter(void 0,void 0,void 0,(function*(){var n;if(t.stopPropagation(),z||F.current)return;let r;G();try{const t=u.findResponseArtifacts(h);let s;if(t.length){if(F.current=!0,B(!0),"pdf"===o.extension){if(r=null!==(n=window.open("","_blank"))&&void 0!==n?n:void 0,!r)throw new Error("Unable to open the print window.");r.opener=null;const e=r.document.createElement("p");e.textContent=(null==k?void 0:k.loading)||"Loading...",e.setAttribute("role","status"),e.style.cssText="margin:32px;font:16px system-ui,sans-serif",r.document.body.appendChild(e)}s=yield u.prepareResponseArtifactDownload(h,t,(t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=T.find((e=>e.id===t.id&&e.version===t.version));return null!=e?e:P.mutateAsync({artifactId:t.id,version:t.version,studioId:null==R?void 0:R.studioid,senderType:O,sender:C||void 0,studioSessionToken:S||void 0})}))),o.extension,(e=>d.renderResponseArtifactHtml(e,"pdf"===o.extension||"docx"===o.extension,r)))}if("docx"===o.extension){F.current=!0,B(!0);const e=yield i.createResponseDownloadDocx(h,s);return void b.default(e,"response.docx")}if("pdf"===o.extension)return F.current=!0,B(!0),void(s?yield a.printResponseDownloadDocument(s,r):yield a.printResponseDownloadHtml(h));let c=null!=s?s:"html"===o.extension?a.createResponseDownloadHtml(h):h;"html"===o.extension&&(F.current=!0,B(!0),c=yield l.embedResponseDownloadHtmlImages(c));const f=new Blob([c],{type:o.mimeType});b.default(f,`response.${o.extension}`)}catch(e){console.error("Response download failed",{format:o.extension,error:e}),null==r||r.close(),window.alert((null==k?void 0:k["something-went-wrong"])||"Something went wrong.")}finally{F.current=!1,B(!1)}}))})(t,o)},onKeyDown:J,onBlur:Q},{children:o.label}),o.extension)))}))})),document.body)]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),o=require("react"),n=require("react-dom"),r=require("uuid"),s=require("file-saver"),i=require("../../../common/responseDownloadDocx.js"),l=require("../../../common/responseDownloadImages.js"),a=require("../../../common/responseDownloadHtml.js"),u=require("../../../common/responseDownloadArtifacts.js"),d=require("../../../common/responseArtifactSnapshot.js"),c=require("../Addons/Artifact/hooks/useArtifactContext.js"),f=require("../Addons/Artifact/hooks/useArtifactData.js"),p=require("../Addons/Auth/hooks/useAuthContext.js"),m=require("../../../hooks/pickaxe/usePickaxeContext.js"),x=require("../../../hooks/core/useOutsideAlerter.js"),v=require("../../Icons/download.svg.js"),y=require("../../Core/Menu/index.js"),h=require("../../Core/Menu/List.js");function w(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var b=w(s);const g=[{extension:"txt",label:"TXT",mimeType:"text/plain;charset=utf-8"},{extension:"md",label:"Markdown (.md)",mimeType:"text/markdown;charset=utf-8"},{extension:"html",label:"HTML (.html)",mimeType:"text/html;charset=utf-8"},{extension:"pdf",label:"PDF"},{extension:"docx",label:"DOCX"}];exports.default=({color:s,text:w,disabled:j=!1})=>{const{translations:k,colors:A,styles:D,isRtl:q,sender:C,senderType:O,pickaxe:R}=m.usePickaxeContext(),{artifacts:T=[]}=c.useArtifactContext(),{token:S}=p.useAuthContext(),P=f.useArtifactData(),[_,E]=o.useState(""),[H,I]=o.useState(!1),[M,N]=o.useState(),[$,B]=o.useState(!1),F=o.useRef(!1),L=o.useRef(null),K=o.useRef(null),U=o.useRef([]),X=o.useRef(0),W=(null==k?void 0:k.download)||"Download",z=j||$||!w.trim();o.useEffect((()=>{E(`response-download-${r.v4()}`)}),[]),o.useEffect((()=>{z&&I(!1)}),[z]),o.useEffect((()=>{H&&L.current&&N(getComputedStyle(L.current).fontFamily)}),[H,D.font]),x.useOutsideAlerter({ref:[L,K],callback:()=>I(!1)});const G=()=>{var e;I(!1),null===(e=L.current)||void 0===e||e.focus({preventScroll:!0})},J=e=>{var t;if(!z)if("Escape"===e.key&&H)e.preventDefault(),e.stopPropagation(),G();else if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault(),e.stopPropagation();const o=U.current.indexOf(e.currentTarget),n="ArrowDown"===e.key?1:-1,r=g.length,s=-1===o?1===n?0:r-1:(o+n+r)%r;X.current=s,I(!0),null===(t=U.current[s])||void 0===t||t.focus({preventScroll:!0})}else"Tab"===e.key&&I(!1)},Q=e=>{e.relatedTarget===L.current||U.current.some((t=>t===e.relatedTarget))||I(!1)};return t.jsxs(y.default,Object.assign({id:_,className:"h-4 w-4 shrink-0",isOpen:H&&!z,onChange:I,closeOnSelect:!1,closeOnClickOutside:!1},{children:[t.jsx("button",Object.assign({ref:L,id:_||void 0,type:"button",className:"flex h-4 w-4 shrink-0 items-center justify-center rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-30",style:{color:s},title:W,"aria-label":W,"aria-haspopup":"menu","aria-busy":$,"aria-expanded":H&&!z,"aria-controls":H&&!z?`${_}-menu`:void 0,disabled:z,onClick:e=>{e.stopPropagation(),X.current=0,I((e=>!e))},onKeyDown:J,onBlur:Q},{children:t.jsx(v.default,{className:"h-4 w-4 shrink-0","aria-hidden":"true"})})),_&&!z&&n.createPortal(t.jsx("div",Object.assign({ref:K,style:{fontFamily:M},dir:q?"rtl":"ltr"},{children:t.jsx(h.default,Object.assign({id:`${_}-menu`,role:"menu",align:"right",width:"auto",className:"p-1 text-sm",style:{backgroundColor:A.primary,color:A.text,maxWidth:"calc(100vw - 32px)"},imperativeModeOnly:!0,afterShow:()=>{var e;return null===(e=U.current[X.current])||void 0===e?void 0:e.focus({preventScroll:!0})}},{children:g.map(((o,n)=>t.jsx("button",Object.assign({ref:e=>{U.current[n]=e},type:"button",role:"menuitem",tabIndex:-1,className:"rounded-sm px-3 py-2 text-left hover:bg-black/10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-[-2px]",onClick:t=>{((t,o)=>{e.__awaiter(void 0,void 0,void 0,(function*(){var n;if(t.stopPropagation(),z||F.current)return;let r;G();try{const t=u.findResponseArtifacts(w);let s;if(t.length){if(F.current=!0,B(!0),"pdf"===o.extension){if(r=null!==(n=window.open("","_blank"))&&void 0!==n?n:void 0,!r)throw new Error("Unable to open the print window.");r.opener=null;const e=r.document.createElement("p");e.textContent=(null==k?void 0:k.loading)||"Loading...",e.setAttribute("role","status"),e.style.cssText="margin:32px;font:16px system-ui,sans-serif",r.document.body.appendChild(e)}s=yield u.prepareResponseArtifactDownload(w,t,(t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=T.find((e=>e.id===t.id&&e.version===t.version));return null!=e?e:P.mutateAsync({artifactId:t.id,version:t.version,studioId:null==R?void 0:R.studioid,senderType:O,sender:C||void 0,studioSessionToken:S||void 0})}))),o.extension,(e=>d.renderResponseArtifactHtml(e,"pdf"===o.extension||"docx"===o.extension,r)))}if("docx"===o.extension){F.current=!0,B(!0);const e=yield i.createResponseDownloadDocx(w,s);return void b.default(e,"response.docx")}if("pdf"===o.extension)return F.current=!0,B(!0),void(s?yield a.printResponseDownloadDocument(s,r):yield a.printResponseDownloadHtml(w));"html"===o.extension&&(F.current=!0,B(!0));let c=null!=s?s:"html"===o.extension?yield a.createResponseDownloadHtml(w):w;"html"===o.extension&&(F.current=!0,B(!0),c=yield l.embedResponseDownloadHtmlImages(c));const f=new Blob([c],{type:o.mimeType});b.default(f,`response.${o.extension}`)}catch(e){console.error("Response download failed",{format:o.extension,error:e}),null==r||r.close(),window.alert((null==k?void 0:k["something-went-wrong"])||"Something went wrong.")}finally{F.current=!1,B(!1)}}))})(t,o)},onKeyDown:J,onBlur:Q},{children:o.label}),o.extension)))}))})),document.body)]}))};
@@ -3,7 +3,7 @@
3
3
  * Does not mount the chat renderer, run response scripts, or fetch linked content.
4
4
  * Code fences stay literal; only the export gets these stricter HTML rules.
5
5
  */
6
- export declare const createResponseDownloadHtml: (text: string) => string;
6
+ export declare const createResponseDownloadHtml: (text: string) => Promise<string>;
7
7
  /** All assembled content, including artifact snapshots, crosses this boundary. */
8
8
  export declare const createResponseDownloadDocument: (rendered: string, preserveArtifactStyles?: boolean) => string;
9
9
  /** Opens a print copy from the user's click without changing the live response. */
@@ -31,6 +31,19 @@ const e=String.raw`async (source) => {
31
31
  'transform', 'transform-origin', 'transform-box',
32
32
  'x', 'y', 'cx', 'cy', 'r', 'rx', 'ry', 'd'
33
33
  ];
34
+ // Mermaid HTML labels are static text inside foreignObject. Preserve their
35
+ // measured layout, but never serialize active elements or external resources.
36
+ const labelTags = new Set(['div', 'span', 'p', 'br', 'b', 'strong', 'i', 'em', 'u', 's', 'small', 'sub', 'sup', 'a']);
37
+ const labelProperties = [
38
+ 'display', 'visibility', 'opacity', 'box-sizing', 'width', 'height',
39
+ 'min-width', 'max-width', 'min-height', 'max-height',
40
+ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
41
+ 'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
42
+ 'color', 'background-color', 'font-family', 'font-size', 'font-weight',
43
+ 'font-style', 'line-height', 'letter-spacing', 'word-spacing',
44
+ 'white-space', 'text-align', 'text-decoration', 'text-transform',
45
+ 'vertical-align', 'overflow-wrap', 'word-break', 'direction'
46
+ ];
34
47
  sources.forEach((node, index) => {
35
48
  const target = targets[index];
36
49
  const tag = node.localName.toLowerCase();
@@ -38,7 +51,26 @@ const e=String.raw`async (source) => {
38
51
  target.remove();
39
52
  return;
40
53
  }
41
- if (tag === 'foreignobject') throw new Error('SVG embedded HTML cannot be captured');
54
+ if (node.namespaceURI === 'http://www.w3.org/1999/xhtml') {
55
+ if (!node.closest('foreignObject') || !labelTags.has(tag))
56
+ throw new Error('Unsupported SVG HTML label');
57
+ const computed = getComputedStyle(node);
58
+ if (computed.backgroundImage !== 'none')
59
+ throw new Error('SVG HTML label requires an external resource');
60
+ for (const pseudo of ['::before', '::after']) {
61
+ const content = getComputedStyle(node, pseudo).content;
62
+ if (content && content !== 'none' && content !== 'normal' && content !== '""')
63
+ throw new Error('Unsupported SVG HTML label decoration');
64
+ }
65
+ for (const attr of Array.from(target.attributes)) target.removeAttributeNode(attr);
66
+ labelProperties.forEach(property => {
67
+ const value = computed.getPropertyValue(property);
68
+ if (value) target.style.setProperty(property, safeValue(value));
69
+ });
70
+ return;
71
+ }
72
+ if (node.namespaceURI !== 'http://www.w3.org/2000/svg')
73
+ throw new Error('Unsupported SVG namespace');
42
74
  // Referenced symbols inherit styles through a browser-created shadow tree.
43
75
  // Do not silently flatten them with the wrong colors or missing geometry.
44
76
  if (tag === 'use') throw new Error('SVG symbol instances cannot be captured');
@@ -1 +1 @@
1
- import{__awaiter as t}from"../_virtual/_tslib.js";import{createResponseDownloadDocument as e}from"./responseDownloadHtml.js";import{embedResponseDownloadImages as o}from"./responseDownloadImages.js";const r=(r,n)=>t(void 0,void 0,void 0,(function*(){var t;let i=e(`<div class="pxe-export-artifact">${r}</div>`,!0);const a=document.createElement("template");a.innerHTML=i;const l=yield o(a.content,"docx");for(const e of a.content.querySelectorAll("img")){if(l.has(e))continue;const o=document.createElement("span");o.textContent=`⚠ ${(null===(t=e.getAttribute("alt"))||void 0===t?void 0:t.trim())||"[…]"}`,e.replaceWith(o)}i=`<!doctype html>\n${a.innerHTML}`;const c=document.createElement("iframe");c.setAttribute("sandbox","allow-same-origin"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.cssText="position:fixed;left:-10000px;top:0;width:720px;height:600px;border:0;pointer-events:none";try{yield new Promise(((t,e)=>{const o=setTimeout((()=>e(new Error("Word snapshot timed out."))),5e3);c.onload=()=>{clearTimeout(o),t()},c.onerror=()=>{clearTimeout(o),e(new Error("Word snapshot failed."))},c.srcdoc=i,document.body.appendChild(c)}));const t=c.contentDocument,e=c.contentWindow,o=null==t?void 0:t.querySelector("main");if(!t||!e||!o)throw new Error("Word snapshot unavailable.");const r=t.createElement("style");r.textContent="main{display:flow-root;width:720px;max-width:none;padding:0;margin:0}\n.pxe-export-artifact{overflow:visible}\n.pxe-export-artifact:has(tr > :nth-child(6)) > div{min-width:0}\ntable{width:100%;table-layout:fixed} pre{white-space:pre-wrap;overflow-wrap:anywhere}\n*{animation:none!important;transition:none!important}",t.head.appendChild(r),t.querySelectorAll("details").forEach((t=>{t.open=!0}));const a=Math.ceil(Math.max(o.scrollWidth,o.getBoundingClientRect().width)),l=Math.ceil(o.getBoundingClientRect().height);if(a>1440||!l||l>16e3)throw new Error("Artifact is too large for a readable Word picture.");const s=o.cloneNode(!0),d=[o,...o.querySelectorAll("*")],h=[s,...s.querySelectorAll("*")];d.forEach(((t,o)=>{const r=h[o],n=e.getComputedStyle(t);r.removeAttribute("style");for(const t of Array.from(n))r.style.setProperty(t,n.getPropertyValue(t))})),s.setAttribute("xmlns","http://www.w3.org/1999/xhtml");const m=(new XMLSerializer).serializeToString(s);if(m.length>1e7)throw new Error("Word snapshot is too large.");const p=o.getBoundingClientRect().top,w=[],g=t.createTreeWalker(o,NodeFilter.SHOW_TEXT);for(;g.nextNode();){const e=t.createRange();e.selectNodeContents(g.currentNode);for(const t of Array.from(e.getClientRects()))t.height&&w.push({top:t.top-p,bottom:t.bottom-p})}o.querySelectorAll("tr,img").forEach((t=>{const e=t.getBoundingClientRect();e.height<=800&&w.push({top:e.top-p,bottom:e.bottom-p})}));const u=[];let f=0;for(let e=0;e<l;){let o=Math.min(l,e+800);if(o<l)for(let t=0;t<w.length;t++){const t=w.find((t=>t.top+1<o&&t.bottom-1>o));if(!t||t.top<=e)break;o=Math.ceil(t.top)}if(o<=e)throw new Error("Unable to paginate artifact picture.");const r=`<svg xmlns="http://www.w3.org/2000/svg" width="${a}" height="${o-e}" viewBox="0 ${e} ${a} ${o-e}"><foreignObject x="0" y="0" width="${a}" height="${l}">${m}</foreignObject></svg>`,i=new Image;yield new Promise(((t,e)=>{const o=setTimeout((()=>n(!1)),5e3),n=r=>{clearTimeout(o),i.onload=i.onerror=null,r?t():e(new Error("Unable to draw Word artifact picture."))};i.onload=()=>n(!0),i.onerror=()=>n(!1),i.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`}));const c=document.createElement("canvas");c.width=2*a,c.height=2*(o-e);const s=c.getContext("2d");if(!s)throw new Error("Word image capture unavailable.");s.fillStyle="white",s.fillRect(0,0,c.width,c.height),s.drawImage(i,0,0,c.width,c.height);const d=c.toDataURL("image/png");if(f+=d.length,f>1e7)throw new Error("Word artifact pictures are too large.");const h=t.createElement("img");h.src=d,h.width=a,h.height=o-e,h.alt=n;const p=t.createElement("p");p.appendChild(h),u.push(p.outerHTML),c.width=c.height=0,i.removeAttribute("src"),e=o}return u.join("")}finally{c.remove()}}));export{r as createResponseArtifactWordImages};
1
+ import{__awaiter as t}from"../_virtual/_tslib.js";import{createResponseDownloadDocument as e}from"./responseDownloadHtml.js";import{embedResponseDownloadImages as o}from"./responseDownloadImages.js";import{artifactStyleProperties as r}from"./responseArtifactStyles.js";const n=(n,i)=>t(void 0,void 0,void 0,(function*(){var t;let a=e(`<div class="pxe-export-artifact">${n}</div>`,!0);const l=document.createElement("template");l.innerHTML=a;const c=yield o(l.content,"docx");for(const e of l.content.querySelectorAll("img")){if(c.has(e))continue;const o=document.createElement("span");o.textContent=`⚠ ${(null===(t=e.getAttribute("alt"))||void 0===t?void 0:t.trim())||"[…]"}`,e.replaceWith(o)}a=`<!doctype html>\n${l.innerHTML}`;const s=document.createElement("iframe");s.setAttribute("sandbox","allow-same-origin"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.style.cssText="position:fixed;left:-10000px;top:0;width:720px;height:600px;border:0;pointer-events:none";try{yield new Promise(((t,e)=>{const o=setTimeout((()=>e(new Error("Word snapshot timed out."))),5e3);s.onload=()=>{clearTimeout(o),t()},s.onerror=()=>{clearTimeout(o),e(new Error("Word snapshot failed."))},s.srcdoc=a,document.body.appendChild(s)}));const t=s.contentDocument,e=s.contentWindow,o=null==t?void 0:t.querySelector("main");if(!t||!e||!o)throw new Error("Word snapshot unavailable.");const n=t.createElement("style");n.textContent="body > main{display:flow-root;width:720px;max-width:none;padding:0;margin:0}\n.pxe-export-artifact{overflow:visible}\n.pxe-export-artifact:has(tr > :nth-child(6)) > div{min-width:0}\ntable{width:100%;table-layout:fixed} pre{white-space:pre-wrap;overflow-wrap:anywhere}\n*{animation:none!important;transition:none!important}",t.head.appendChild(n),t.querySelectorAll("details").forEach((t=>{t.open=!0}));const l=o.cloneNode(!0),c=[o,...o.querySelectorAll("*")],d=[l,...l.querySelectorAll("*")];c.forEach(((t,o)=>{const n=d[o],i=e.getComputedStyle(t);n.removeAttribute("style");for(const t of[...r,"direction","unicode-bidi","white-space","overflow-wrap","table-layout"])n.style.setProperty(t,i.getPropertyValue(t));"TABLE"===t.tagName&&(n.style.width="100%"),"IMG"===t.tagName&&(n.style.maxWidth="100%",n.style.height="auto")})),l.style.width="720px",o.replaceWith(l),t.querySelectorAll("style").forEach((t=>t.remove())),t.body.style.margin="0",yield Promise.all(Array.from(l.querySelectorAll("img"),(t=>t.decode())));const h=Math.ceil(Math.max(l.scrollWidth,l.getBoundingClientRect().width)),m=Math.ceil(l.getBoundingClientRect().height);if(h>1440||!m||m>16e3)throw new Error("Artifact is too large for a readable Word picture.");l.setAttribute("xmlns","http://www.w3.org/1999/xhtml");const p=(new XMLSerializer).serializeToString(l);if(p.length>1e7)throw new Error("Word snapshot is too large.");const w=l.getBoundingClientRect().top,g=[],u=t.createTreeWalker(l,NodeFilter.SHOW_TEXT);for(;u.nextNode();){const e=t.createRange();e.selectNodeContents(u.currentNode);for(const t of Array.from(e.getClientRects()))t.height&&g.push({top:t.top-w,bottom:t.bottom-w})}l.querySelectorAll("tr,img").forEach((t=>{const e=t.getBoundingClientRect();e.height<=800&&g.push({top:e.top-w,bottom:e.bottom-w})}));const f=[];let y=0;for(let e=0;e<m;){let o=Math.min(m,e+800);if(o<m)for(let t=0;t<g.length;t++){const t=g.find((t=>t.top+1<o&&t.bottom-1>o));if(!t||t.top<=e)break;o=Math.ceil(t.top)}if(o<=e)throw new Error("Unable to paginate artifact picture.");const r=`<svg xmlns="http://www.w3.org/2000/svg" width="${h}" height="${o-e}" viewBox="0 ${e} ${h} ${o-e}"><foreignObject x="0" y="0" width="${h}" height="${m}">${p}</foreignObject></svg>`,n=new Image;yield new Promise(((t,e)=>{const o=setTimeout((()=>i(!1)),5e3),i=r=>{clearTimeout(o),n.onload=n.onerror=null,r?t():e(new Error("Unable to draw Word artifact picture."))};n.onload=()=>i(!0),n.onerror=()=>i(!1),n.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`}));const a=document.createElement("canvas");a.width=2*h,a.height=2*(o-e);const l=a.getContext("2d");if(!l)throw new Error("Word image capture unavailable.");l.fillStyle="white",l.fillRect(0,0,a.width,a.height),l.drawImage(n,0,0,a.width,a.height);const c=a.toDataURL("image/png");if(y+=c.length,y>1e7)throw new Error("Word artifact pictures are too large.");const s=t.createElement("img");s.src=c,s.width=h,s.height=o-e,s.alt=i;const d=t.createElement("p");d.appendChild(s),f.push(d.outerHTML),a.width=a.height=0,n.removeAttribute("src"),e=o}return f.join("")}finally{s.remove()}}));export{n as createResponseArtifactWordImages};
@@ -1 +1 @@
1
- import{__awaiter as t}from"../_virtual/_tslib.js";import{createElement as e}from"react";import{renderToStaticMarkup as r}from"react-dom/server";import n from"react-markdown";import o from"remark-gfm";import i from"rehype-raw";import{v4 as a}from"uuid";import{createResponseArtifactWordImages as s}from"./responseArtifactWordImages.js";import{createResponseSvgImage as c}from"./responseStandaloneSvg.js";import{createResponseMermaidImage as l}from"./responseMermaid.js";import{embedInteractiveArtifacts as p}from"./responseInteractiveArtifactHtml.js";import{createResponseDownloadDocument as d,createResponseDownloadHtml as m}from"./responseDownloadHtml.js";const f=t=>{if(!/<artifact\b/i.test(t))return[];const a=[];return r(e(n,{remarkPlugins:[o],rehypePlugins:[i],components:{artifact:({node:t})=>{var e,r,n,o;const i=null===(e=t.position)||void 0===e?void 0:e.start.offset,s=null===(r=t.position)||void 0===r?void 0:r.end.offset,c=String(null!==(n=t.properties.dataId)&&void 0!==n?n:""),l=Number(null!==(o=t.properties.dataVersion)&&void 0!==o?o:1);if(null==i||null==s||!c||!Number.isInteger(l)||l<1)throw new Error("Invalid response artifact reference.");return a.push({id:c,version:l,start:i,end:s}),null}}},t)),a.sort(((t,e)=>t.start-e.start))},u=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),v=t=>{var e,r;const n=document.createElement("template");return n.innerHTML=m(t),null!==(r=null===(e=n.content.querySelector("main"))||void 0===e?void 0:e.innerHTML)&&void 0!==r?r:""},h=(t,e)=>{const r=[];let n=[],o="",i=!1;for(let a=0;a<t.length;a++){const s=t[a];'"'===s?i&&'"'===t[a+1]?(o+='"',a++):i=!i:i||s!==e&&"\n"!==s&&"\r"!==s?o+=s:(n.push(o),o="",s!==e&&(r.push(n),n=[],"\r"===s&&"\n"===t[a+1]&&a++))}if(i)throw new Error("Incomplete artifact table.");return(o||n.length)&&r.push([...n,o]),`<table>${r.map(((t,e)=>`<tr>${t.map((t=>{const r=e?"td":"th";return`<${r}>${u(t).replace(/\n/g,"<br>")}</${r}>`})).join("")}</tr>`)).join("")}</table>`},g=(e,r,n,o,i)=>t(void 0,void 0,void 0,(function*(){const t="txt"===o||"md"===o,m=[],f=[];let g=0;for(const p of r){const r=yield n(p);if(r.id!==p.id||r.version!==p.version||r.status&&"finished"!==r.status)throw new Error("Response artifact is not ready.");const d=e.slice(g,p.start);if(m.push(t?d:v(d)),t){const t="`".repeat(Math.max(3,...Array.from(r.content.matchAll(/`+/g),(t=>t[0].length+1))));m.push(`\n\n${r.title}\n\n${"md"===o&&"text/markdown"!==r.type?`${t}\n${r.content}\n${t}`:r.content}\n\n`)}else{let t;switch(r.type){case"text/markdown":t=v(r.content);break;case"text/csv":t=h(r.content,",");break;case"text/tab-separated-values":t=h(r.content,"\t");break;case"application/vnd.pxe.mermaid":t=yield l(r.content,r.title);break;case"image/svg+xml":t=yield c(r.content,r.title);break;case"text/html":if("html"===o){const e=`artifact-${a()}`;f.push({placeholder:e,title:r.title,content:r.content}),t=`<div id="${e}"></div>`;break}t=yield i(r.content),"docx"===o&&(t=yield s(t,r.title));break;case"application/pdf":t=yield i(r.content);break;case"application/vnd.pxe.code":t=`<pre><code>${u(r.content)}</code></pre>`;break;default:throw new Error(`Artifact export is not supported for ${r.type}.`)}m.push(`<section><h2>${u(r.title)}</h2><div class="pxe-export-artifact">${t}</div></section>`)}g=p.end}return m.push(t?e.slice(g):v(e.slice(g))),t?m.join(""):p(d(m.join("\n"),"html"===o||"pdf"===o),f)}));export{f as findResponseArtifacts,g as prepareResponseArtifactDownload};
1
+ import{__awaiter as t}from"../_virtual/_tslib.js";import{createElement as e}from"react";import{renderToStaticMarkup as r}from"react-dom/server";import n from"react-markdown";import o from"remark-gfm";import i from"rehype-raw";import{v4 as a}from"uuid";import{createResponseArtifactWordImages as s}from"./responseArtifactWordImages.js";import{createResponseSvgImage as l}from"./responseStandaloneSvg.js";import{createResponseMermaidImage as c}from"./responseMermaid.js";import{embedInteractiveArtifacts as d}from"./responseInteractiveArtifactHtml.js";import{createResponseDownloadDocument as p,createResponseDownloadHtml as m}from"./responseDownloadHtml.js";const f=(t,e)=>{var r;const n=/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\/?([a-z][\w:-]*)(?:[^>"']|"[^"]*"|'[^']*')*>/gi;n.lastIndex=e;let o,i=0;for(;null!==(o=n.exec(t));){const e=null===(r=o[1])||void 0===r?void 0:r.toLowerCase();if(!e)continue;const a=o[0].startsWith("</");if("artifact"===e){if(a?i--:/\/\s*>$/.test(o[0])||i++,0===i)return n.lastIndex}else if(!a&&/^(script|style|textarea|title|xmp|iframe|noembed|noframes)$/.test(e)){const r=new RegExp(`</${e}\\s*>`,"gi");if(r.lastIndex=n.lastIndex,!r.exec(t))break;n.lastIndex=r.lastIndex}}return t.length},u=t=>{if(!/<artifact\b/i.test(t))return[];const a=[];r(e(n,{remarkPlugins:[o],rehypePlugins:[i],components:{artifact:({node:e})=>{var r,n,o;const i=null===(r=e.position)||void 0===r?void 0:r.start.offset,s=String(null!==(n=e.properties.dataId)&&void 0!==n?n:""),l=Number(null!==(o=e.properties.dataVersion)&&void 0!==o?o:1);if(null==i||!s||!Number.isInteger(l)||l<1)throw new Error("Invalid response artifact reference.");return a.push({id:s,version:l,start:i,end:f(t,i)}),null}}},t));let s=0;return a.sort(((t,e)=>t.start-e.start)).filter((t=>!(t.start<s)&&(s=t.end,!0)))},v=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),h=e=>t(void 0,void 0,void 0,(function*(){var t,r;const n=document.createElement("template");return n.innerHTML=yield m(e),null!==(r=null===(t=n.content.querySelector("main"))||void 0===t?void 0:t.innerHTML)&&void 0!==r?r:""})),x=(t,e)=>{const r=[];let n=[],o="",i=!1;for(let a=0;a<t.length;a++){const s=t[a];'"'===s?i&&'"'===t[a+1]?(o+='"',a++):i=!i:i||s!==e&&"\n"!==s&&"\r"!==s?o+=s:(n.push(o),o="",s!==e&&(r.push(n),n=[],"\r"===s&&"\n"===t[a+1]&&a++))}if(i)throw new Error("Incomplete artifact table.");return(o||n.length)&&r.push([...n,o]),`<table>${r.map(((t,e)=>`<tr>${t.map((t=>{const r=e?"td":"th";return`<${r}>${v(t).replace(/\n/g,"<br>")}</${r}>`})).join("")}</tr>`)).join("")}</table>`},g=(e,r,n,o,i)=>t(void 0,void 0,void 0,(function*(){const t="txt"===o||"md"===o,m=[],f=[];let u=0;for(const d of r){const r=yield n(d);if(r.id!==d.id||r.version!==d.version||r.status&&"finished"!==r.status)throw new Error("Response artifact is not ready.");const p=e.slice(u,d.start);if(m.push(t?p:yield h(p)),t){const t="`".repeat(Math.max(3,...Array.from(r.content.matchAll(/`+/g),(t=>t[0].length+1))));m.push(`\n\n${r.title}\n\n${"md"===o&&"text/markdown"!==r.type?`${t}\n${r.content}\n${t}`:r.content}\n\n`)}else{let t;switch(r.type){case"text/markdown":t=yield h(r.content);break;case"text/csv":t=x(r.content,",");break;case"text/tab-separated-values":t=x(r.content,"\t");break;case"application/vnd.pxe.mermaid":t=yield c(r.content,r.title);break;case"image/svg+xml":t=yield l(r.content,r.title);break;case"text/html":if("html"===o){const e=`artifact-${a()}`;f.push({placeholder:e,title:r.title,content:r.content}),t=`<div id="${e}"></div>`;break}t=yield i(r.content),"docx"===o&&(t=yield s(t,r.title));break;case"application/pdf":t=yield i(r.content);break;case"application/vnd.pxe.code":t=`<pre><code>${v(r.content)}</code></pre>`;break;default:throw new Error(`Artifact export is not supported for ${r.type}.`)}m.push(`<section><h2>${v(r.title)}</h2><div class="pxe-export-artifact">${t}</div></section>`)}u=d.end}return m.push(t?e.slice(u):yield h(e.slice(u))),t?m.join(""):d(p(m.join("\n"),"html"===o||"pdf"===o),f)}));export{u as findResponseArtifacts,g as prepareResponseArtifactDownload};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../_virtual/_tslib.js";import{Document as t,Paragraph as r,Packer as n,TextRun as i,Tab as a,HeadingLevel as s,BorderStyle as o,UnderlineType as l,ImageRun as c,ExternalHyperlink as d,TableRow as u,TableCell as m,WidthType as g,Table as h,LevelFormat as p,AlignmentType as b}from"docx";import{createResponseDownloadHtml as f}from"./responseDownloadHtml.js";import{embedResponseDownloadImages as w}from"./responseDownloadImages.js";const A=720,N=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DD","DETAILS","DIV","DL","DT","FIGCAPTION","FIGURE","FOOTER","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","MAIN","NAV","OL","P","PRE","SECTION","SUMMARY","TABLE","UL"]),O=e=>{if(e&&/^(https?:|mailto:|tel:)/i.test(e.trim()))try{return new URL(e.trim()).href}catch(e){return}},E=(e,t)=>{const r=Object.assign({},t);switch(e.tagName){case"STRONG":case"B":r.bold=!0;break;case"EM":case"I":r.italics=!0;break;case"DEL":case"S":case"STRIKE":r.strike=!0;break;case"U":r.underline={type:l.SINGLE};break;case"CODE":case"KBD":case"SAMP":r.font="Courier New";break;case"SUP":r.superScript=!0;break;case"SUB":r.subScript=!0}return r},I=(I,j)=>e(void 0,void 0,void 0,(function*(){const e=document.createElement("template");e.innerHTML=null!=j?j:f(I);const y=e.content.querySelector("main");if(!y)throw new Error("Unable to prepare the response document.");const T=yield w(y,"docx"),v=new Map;for(const e of T){const t=e.getAttribute("src")||"";if(t.length>1e7)throw new Error("Artifact image too large.");const r=Uint8Array.from(atob(t.slice(22)),(e=>e.charCodeAt(0))),n=new DataView(r.buffer);if(r.length<24||2303741511!==n.getUint32(0)||218765834!==n.getUint32(4)||1229472850!==n.getUint32(12))throw new Error("Invalid artifact image.");const i=n.getUint32(16),a=n.getUint32(20);if(!i||!a||i*a>16e6)throw new Error("Artifact image dimensions are unsupported.");yield new Promise(((e,r)=>{const n=new Image,s=t=>{clearTimeout(o),n.onload=n.onerror=null,n.removeAttribute("src"),t?e():r(new Error("Unable to read artifact image."))},o=setTimeout((()=>s(!1)),5e3);n.onload=()=>s(n.naturalWidth===i&&n.naturalHeight===a),n.onerror=()=>s(!1),n.src=t}));const s=Number(e.getAttribute("width")),o=s>0?Math.min(1,s/i):1;v.set(e,{data:r,width:i*o,height:a*o})}const D=[],S=(e,t,r)=>Array.from(e).flatMap((e=>{var n;if(3===e.nodeType){const r=e.textContent||"";return[new i(Object.assign(Object.assign({},t),{text:(null===(n=e.parentElement)||void 0===n?void 0:n.closest("code"))?r:r.replace(/[\t\n\r ]+/g," ")}))]}if(1!==e.nodeType)return[];const a=e,s=E(a,t);if("BR"===a.tagName)return[new i(Object.assign(Object.assign({},t),{break:1}))];if("IMG"===a.tagName){const e=v.get(a);if(e){const t=Math.min(1,Math.max(1,r/15)/e.width,900/e.height);return[new c(Object.assign(Object.assign({type:"png",data:e.data},a.getAttribute("alt")?{altText:{name:a.getAttribute("alt")||""}}:{}),{transformation:{width:e.width*t,height:e.height*t}}))]}const n=O(a.getAttribute("src")),s=a.getAttribute("alt")||n||"[…]",o=[new i(Object.assign(Object.assign({},t),{text:s}))];return n&&!a.closest("a")?[new d({link:n,children:o})]:o}const o="A"===a.tagName?O(a.getAttribute("href")):void 0,u=S(a.childNodes,o?Object.assign(Object.assign({},s),{color:"174EA6",underline:{type:l.SINGLE}}):s,r);return o?[new d({link:o,children:u})]:u})),H=(e,t,n={})=>{const i=t.marker&&!t.marker.used?t.marker:void 0;return i&&(i.used=!0),new r(Object.assign(Object.assign(Object.assign({children:e,spacing:{after:160},widowControl:!0},t.indent?{indent:Object.assign({left:t.indent},i?{hanging:360}:{})}:{}),null==i?void 0:i.properties),n))},k=(e,t)=>{var r;const n="OL"===e.tagName;let i="",a=!1;const s=e=>{i=`response-list-${D.length}`,a=0===e,D.push({reference:i,levels:[{level:0,format:p.DECIMAL,text:a?"0.":"%1.",start:a?1:e,alignment:b.LEFT}]})},o=e.hasAttribute("reversed"),l=Array.from(e.children).filter((e=>"LI"===e.tagName)),c=Number.parseInt(e.getAttribute("start")||"",10);let d=Number.isFinite(c)?c:o?l.length:1;n&&s(d);const u=[];for(const l of Array.from(e.children)){if("LI"!==l.tagName){u.push(...M([l],t));continue}const e=Number.parseInt(l.getAttribute("value")||"",10);n&&Number.isFinite(e)&&(d=e),n&&(o||a||0===d||Number.isFinite(e))&&s(d),d+=o?-1:1;const c=Object.assign(Object.assign({},t),{indent:Math.min(t.indent+720,5760),marker:{used:!1,properties:n?{numbering:{reference:i,level:0}}:{bullet:{level:0}}}}),m=M(l.childNodes,c);(null===(r=c.marker)||void 0===r?void 0:r.used)||m.unshift(H([],c)),u.push(...m)}return u},L=(e,t)=>{const n=[];let i=0;const a=Array.from(e.querySelectorAll("tr")).filter((t=>t.closest("table")===e)).map(((e,t)=>{let r=0;return{row:e,cells:Array.from(e.children).filter((e=>"TD"===e.tagName||"TH"===e.tagName)).map((e=>{for(;n[r]>t;)r++;const a=t=>Math.min(100,Math.max(1,parseInt(e.getAttribute(t)||"1",10)||1)),s=a("colspan"),o=a("rowspan"),l=r;for(let e=0;e<s;e++)n[r++]=t+o;return i=Math.max(i,r),{cell:e,start:l,columnSpan:s,rowSpan:o}}))}})),s=e=>Math.floor(e*t/i),o=Array.from({length:i},((e,t)=>s(t+1)-s(t))),l=a.flatMap((({row:e,cells:t})=>{var n;return t.length?[new u({tableHeader:"THEAD"===(null===(n=e.parentElement)||void 0===n?void 0:n.tagName)||t.every((({cell:e})=>"TH"===e.tagName)),children:t.map((({cell:e,start:t,columnSpan:n,rowSpan:i})=>{const a=s(t+n)-s(t),o=M(e.childNodes,{indent:0,width:Math.max(1,a-200),run:{bold:"TH"===e.tagName}});return o[o.length-1]instanceof r||o.push(new r("")),new m(Object.assign({children:o,columnSpan:n,rowSpan:i,width:{size:a,type:g.DXA},margins:{top:80,bottom:80,left:100,right:100}},"TH"===e.tagName?{shading:{fill:"F0F0F0"}}:{}))}))})]:[]})),c=Array.from(e.children).filter((e=>"CAPTION"===e.tagName));return l.length?[...M(c,{indent:0,width:t,run:{}}),new h({rows:l,width:{size:t,type:g.DXA},columnWidths:o})]:M(e.childNodes,{indent:0,width:t,run:{}})},M=(e,t)=>{const r=[];let n=[];const l=()=>{n.some((e=>{var t;return(null===(t=e.textContent)||void 0===t?void 0:t.trim())||1===e.nodeType&&/^(BR|IMG)$/.test(e.tagName)||1===e.nodeType&&e.querySelector("br,img")}))&&r.push(H(S(n,t.run,t.width-t.indent),t)),n=[]};for(const c of Array.from(e)){if(1!==c.nodeType||!N.has(c.tagName)){1===c.nodeType&&Array.from(c.children).some((e=>N.has(e.tagName)))?(l(),r.push(...M(c.childNodes,Object.assign(Object.assign({},t),{run:E(c,t.run)})))):n.push(c);continue}l();const e=c,d=e.tagName;if("UL"===d||"OL"===d)t.marker&&!t.marker.used&&r.push(H([],t)),r.push(...k(e,t));else if("TABLE"===d)t.marker&&!t.marker.used&&r.push(H([],t)),r.push(...L(e,t.width));else if("PRE"===d){const n=(e.textContent||"").replace(/\r\n?/g,"\n").split("\n");r.push(H(n.map(((e,r)=>new i(Object.assign(Object.assign(Object.assign({},t.run),{children:e.split("\t").flatMap(((e,t)=>t?[new a,e]:[e])),font:"Courier New",size:20}),r?{break:1}:{})))),t,{shading:{fill:"F4F4F4"},spacing:{before:120,after:160}}))}else if(/^H[1-6]$/.test(d)){const n=[s.HEADING_1,s.HEADING_2,s.HEADING_3,s.HEADING_4,s.HEADING_5,s.HEADING_6];r.push(H(S(e.childNodes,Object.assign(Object.assign({},t.run),{bold:!0,color:"202020"}),t.width-t.indent),t,{heading:n[Number(d[1])-1],keepNext:!0}))}else if("HR"===d)r.push(H([],t,{border:{bottom:{style:o.SINGLE,color:"CCCCCC",size:4}}}));else{const n="BLOCKQUOTE"===d?Object.assign(Object.assign({},t),{indent:t.indent+360}):t,i=M(e.childNodes,n);r.push(...i),i.length||"P"!==d||r.push(H([],n))}}return l(),r},C=M(y.childNodes,{indent:0,width:10800,run:{}}),U=new t({title:"Pickaxe",creator:"Pickaxe",styles:{default:{document:{run:{font:"Arial",size:22,color:"202020"}}}},numbering:{config:D},sections:[{properties:{page:{size:{width:12240,height:15840},margin:{top:A,bottom:A,left:A,right:A}}},children:C.length?C:[new r("")]}]});return n.toBlob(U)}));export{I as createResponseDownloadDocx};
1
+ import{__awaiter as e}from"../_virtual/_tslib.js";import{Document as t,Paragraph as r,Packer as n,TextRun as i,Tab as a,HeadingLevel as s,BorderStyle as o,UnderlineType as l,ImageRun as c,ExternalHyperlink as d,TableRow as u,TableCell as m,WidthType as g,Table as h,LevelFormat as p,AlignmentType as b}from"docx";import{createResponseDownloadHtml as f}from"./responseDownloadHtml.js";import{embedResponseDownloadImages as w}from"./responseDownloadImages.js";const A=720,N=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DD","DETAILS","DIV","DL","DT","FIGCAPTION","FIGURE","FOOTER","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","MAIN","NAV","OL","P","PRE","SECTION","SUMMARY","TABLE","UL"]),O=e=>{if(e&&/^(https?:|mailto:|tel:)/i.test(e.trim()))try{return new URL(e.trim()).href}catch(e){return}},E=(e,t)=>{const r=Object.assign({},t);switch(e.tagName){case"STRONG":case"B":r.bold=!0;break;case"EM":case"I":r.italics=!0;break;case"DEL":case"S":case"STRIKE":r.strike=!0;break;case"U":r.underline={type:l.SINGLE};break;case"CODE":case"KBD":case"SAMP":r.font="Courier New";break;case"SUP":r.superScript=!0;break;case"SUB":r.subScript=!0}return r},I=(I,y)=>e(void 0,void 0,void 0,(function*(){const e=document.createElement("template");e.innerHTML=null!=y?y:yield f(I);const j=e.content.querySelector("main");if(!j)throw new Error("Unable to prepare the response document.");const T=yield w(j,"docx"),v=new Map;for(const e of T){const t=e.getAttribute("src")||"";if(t.length>1e7)throw new Error("Artifact image too large.");const r=Uint8Array.from(atob(t.slice(22)),(e=>e.charCodeAt(0))),n=new DataView(r.buffer);if(r.length<24||2303741511!==n.getUint32(0)||218765834!==n.getUint32(4)||1229472850!==n.getUint32(12))throw new Error("Invalid artifact image.");const i=n.getUint32(16),a=n.getUint32(20);if(!i||!a||i*a>16e6)throw new Error("Artifact image dimensions are unsupported.");yield new Promise(((e,r)=>{const n=new Image,s=t=>{clearTimeout(o),n.onload=n.onerror=null,n.removeAttribute("src"),t?e():r(new Error("Unable to read artifact image."))},o=setTimeout((()=>s(!1)),5e3);n.onload=()=>s(n.naturalWidth===i&&n.naturalHeight===a),n.onerror=()=>s(!1),n.src=t}));const s=Number(e.getAttribute("width")),o=s>0?Math.min(1,s/i):1;v.set(e,{data:r,width:i*o,height:a*o})}const D=[],S=(e,t,r)=>Array.from(e).flatMap((e=>{var n;if(3===e.nodeType){const r=e.textContent||"";return[new i(Object.assign(Object.assign({},t),{text:(null===(n=e.parentElement)||void 0===n?void 0:n.closest("code"))?r:r.replace(/[\t\n\r ]+/g," ")}))]}if(1!==e.nodeType)return[];const a=e,s=E(a,t);if("BR"===a.tagName)return[new i(Object.assign(Object.assign({},t),{break:1}))];if("IMG"===a.tagName){const e=v.get(a);if(e){const t=Math.min(1,Math.max(1,r/15)/e.width,900/e.height);return[new c(Object.assign(Object.assign({type:"png",data:e.data},a.getAttribute("alt")?{altText:{name:a.getAttribute("alt")||""}}:{}),{transformation:{width:e.width*t,height:e.height*t}}))]}const n=O(a.getAttribute("src")),s=a.getAttribute("alt")||n||"[…]",o=[new i(Object.assign(Object.assign({},t),{text:s}))];return n&&!a.closest("a")?[new d({link:n,children:o})]:o}const o="A"===a.tagName?O(a.getAttribute("href")):void 0,u=S(a.childNodes,o?Object.assign(Object.assign({},s),{color:"174EA6",underline:{type:l.SINGLE}}):s,r);return o?[new d({link:o,children:u})]:u})),H=(e,t,n={})=>{const i=t.marker&&!t.marker.used?t.marker:void 0;return i&&(i.used=!0),new r(Object.assign(Object.assign(Object.assign({children:e,spacing:{after:160},widowControl:!0},t.indent?{indent:Object.assign({left:t.indent},i?{hanging:360}:{})}:{}),null==i?void 0:i.properties),n))},k=(e,t)=>{var r;const n="OL"===e.tagName;let i="",a=!1;const s=e=>{i=`response-list-${D.length}`,a=0===e,D.push({reference:i,levels:[{level:0,format:p.DECIMAL,text:a?"0.":"%1.",start:a?1:e,alignment:b.LEFT}]})},o=e.hasAttribute("reversed"),l=Array.from(e.children).filter((e=>"LI"===e.tagName)),c=Number.parseInt(e.getAttribute("start")||"",10);let d=Number.isFinite(c)?c:o?l.length:1;n&&s(d);const u=[];for(const l of Array.from(e.children)){if("LI"!==l.tagName){u.push(...M([l],t));continue}const e=Number.parseInt(l.getAttribute("value")||"",10);n&&Number.isFinite(e)&&(d=e),n&&(o||a||0===d||Number.isFinite(e))&&s(d),d+=o?-1:1;const c=Object.assign(Object.assign({},t),{indent:Math.min(t.indent+720,5760),marker:{used:!1,properties:n?{numbering:{reference:i,level:0}}:{bullet:{level:0}}}}),m=M(l.childNodes,c);(null===(r=c.marker)||void 0===r?void 0:r.used)||m.unshift(H([],c)),u.push(...m)}return u},L=(e,t)=>{const n=[];let i=0;const a=Array.from(e.querySelectorAll("tr")).filter((t=>t.closest("table")===e)).map(((e,t)=>{let r=0;return{row:e,cells:Array.from(e.children).filter((e=>"TD"===e.tagName||"TH"===e.tagName)).map((e=>{for(;n[r]>t;)r++;const a=t=>Math.min(100,Math.max(1,parseInt(e.getAttribute(t)||"1",10)||1)),s=a("colspan"),o=a("rowspan"),l=r;for(let e=0;e<s;e++)n[r++]=t+o;return i=Math.max(i,r),{cell:e,start:l,columnSpan:s,rowSpan:o}}))}})),s=e=>Math.floor(e*t/i),o=Array.from({length:i},((e,t)=>s(t+1)-s(t))),l=a.flatMap((({row:e,cells:t})=>{var n;return t.length?[new u({tableHeader:"THEAD"===(null===(n=e.parentElement)||void 0===n?void 0:n.tagName)||t.every((({cell:e})=>"TH"===e.tagName)),children:t.map((({cell:e,start:t,columnSpan:n,rowSpan:i})=>{const a=s(t+n)-s(t),o=M(e.childNodes,{indent:0,width:Math.max(1,a-200),run:{bold:"TH"===e.tagName}});return o[o.length-1]instanceof r||o.push(new r("")),new m(Object.assign({children:o,columnSpan:n,rowSpan:i,width:{size:a,type:g.DXA},margins:{top:80,bottom:80,left:100,right:100}},"TH"===e.tagName?{shading:{fill:"F0F0F0"}}:{}))}))})]:[]})),c=Array.from(e.children).filter((e=>"CAPTION"===e.tagName));return l.length?[...M(c,{indent:0,width:t,run:{}}),new h({rows:l,width:{size:t,type:g.DXA},columnWidths:o})]:M(e.childNodes,{indent:0,width:t,run:{}})},M=(e,t)=>{const r=[];let n=[];const l=()=>{n.some((e=>{var t;return(null===(t=e.textContent)||void 0===t?void 0:t.trim())||1===e.nodeType&&/^(BR|IMG)$/.test(e.tagName)||1===e.nodeType&&e.querySelector("br,img")}))&&r.push(H(S(n,t.run,t.width-t.indent),t)),n=[]};for(const c of Array.from(e)){if(1!==c.nodeType||!N.has(c.tagName)){1===c.nodeType&&Array.from(c.children).some((e=>N.has(e.tagName)))?(l(),r.push(...M(c.childNodes,Object.assign(Object.assign({},t),{run:E(c,t.run)})))):n.push(c);continue}l();const e=c,d=e.tagName;if("UL"===d||"OL"===d)t.marker&&!t.marker.used&&r.push(H([],t)),r.push(...k(e,t));else if("TABLE"===d)t.marker&&!t.marker.used&&r.push(H([],t)),r.push(...L(e,t.width));else if("PRE"===d){const n=(e.textContent||"").replace(/\r\n?/g,"\n").split("\n");r.push(H(n.map(((e,r)=>new i(Object.assign(Object.assign(Object.assign({},t.run),{children:e.split("\t").flatMap(((e,t)=>t?[new a,e]:[e])),font:"Courier New",size:20}),r?{break:1}:{})))),t,{shading:{fill:"F4F4F4"},spacing:{before:120,after:160}}))}else if(/^H[1-6]$/.test(d)){const n=[s.HEADING_1,s.HEADING_2,s.HEADING_3,s.HEADING_4,s.HEADING_5,s.HEADING_6];r.push(H(S(e.childNodes,Object.assign(Object.assign({},t.run),{bold:!0,color:"202020"}),t.width-t.indent),t,{heading:n[Number(d[1])-1],keepNext:!0}))}else if("HR"===d)r.push(H([],t,{border:{bottom:{style:o.SINGLE,color:"CCCCCC",size:4}}}));else{const n="BLOCKQUOTE"===d?Object.assign(Object.assign({},t),{indent:t.indent+360}):t,i=M(e.childNodes,n);r.push(...i),i.length||"P"!==d||r.push(H([],n))}}return l(),r},C=M(j.childNodes,{indent:0,width:10800,run:{}}),U=new t({title:"Pickaxe",creator:"Pickaxe",styles:{default:{document:{run:{font:"Arial",size:22,color:"202020"}}}},numbering:{config:D},sections:[{properties:{page:{size:{width:12240,height:15840},margin:{top:A,bottom:A,left:A,right:A}}},children:C.length?C:[new r("")]}]});return n.toBlob(U)}));export{I as createResponseDownloadDocx};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../_virtual/_tslib.js";import{createElement as t}from"react";import{renderToStaticMarkup as r}from"react-dom/server";import o from"react-markdown";import n from"remark-gfm";import i from"rehype-raw";import a from"isomorphic-dompurify";import{filterArtifactStyles as l}from"./responseArtifactStyles.js";const p=e=>{const a=r(t(o,{remarkPlugins:[n],rehypePlugins:[i],components:{input:({type:e,checked:r})=>"checkbox"===(null==e?void 0:e.toLowerCase())?t("span",null,r?"☑":"☐"):null}},e));return c(a)},c=(e,t=!1)=>{let r=a.sanitize(e,{USE_PROFILES:{html:!0},FORBID_TAGS:["script","style","iframe","form","input","button","select","textarea","object","embed","link","meta","base","audio","video","source","track"],FORBID_ATTR:["srcset","ping","background",...t?[]:["style"]],ALLOW_DATA_ATTR:!1});if(t){const e=document.createElement("template");e.innerHTML=r,l(e.content),e.content.querySelectorAll("label").forEach((e=>{var t;(null===(t=e.textContent)||void 0===t?void 0:t.trim())||e.children.length||e.remove()})),r=e.innerHTML}return`<!doctype html>\n<html>\n<head>\n<meta charset="utf-8">\n<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src https: data:; base-uri 'none'; form-action 'none'">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>Pickaxe</title>\n<style>\nbody { margin: 0; background: white; color: #202020; font: 16px/1.6 system-ui, sans-serif; }\nmain { max-width: 900px; margin: 0 auto; padding: 24px; overflow-wrap: anywhere; }\nh1, h2, h3, h4, h5, h6 { line-height: 1.25; }\na { color: #174ea6; }\npre, code { font-family: ui-monospace, monospace; }\npre { padding: 16px; background: #f4f4f4; overflow-x: auto; white-space: pre; }\nblockquote { margin-left: 0; padding-left: 16px; border-left: 3px solid #ccc; }\ntable { border-collapse: collapse; max-width: 100%; }\nth, td { border: 1px solid #ccc; padding: 8px; text-align: start; }\nimg { max-width: 100%; height: auto; }\nsummary { cursor: pointer; }\n${t?"\n.pxe-export-artifact { max-width: 100%; overflow-x: auto; }\n.pxe-export-artifact:has(tr > :nth-child(6)) > div { min-width: 720px; }\n.pxe-export-artifact table { width: 100%; max-width: 100%; }\n.pxe-export-artifact th, .pxe-export-artifact td { overflow-wrap: anywhere; }\n@media print {\n .pxe-export-artifact { overflow: visible; }\n .pxe-export-artifact:has(tr > :nth-child(6)) > div { min-width: 0; }\n .pxe-export-artifact table { width: 100%; min-width: 0; max-width: 100%; table-layout: fixed; }\n .pxe-export-artifact th, .pxe-export-artifact td { padding: 5px !important; font-size: 10px !important; overflow-wrap: anywhere; }\n .pxe-export-artifact, .pxe-export-artifact * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }\n}\n":""}</style>\n</head>\n<body><main dir="auto">${r}</main></body>\n</html>`},d=e=>s(p(e)),s=(t,r)=>e(void 0,void 0,void 0,(function*(){const e=null!=r?r:window.open("","_blank");if(!e||e.closed)throw new Error("Unable to open the response print window.");try{e.opener=null;const r=e.document;r.open(),r.write(t);const o=r.createElement("style");if(o.media="print",o.textContent="\n@page { margin: 12mm; }\nmain { max-width: none; padding: 0; }\npre { overflow: visible; }\npre, pre code { white-space: pre-wrap; overflow-wrap: anywhere; }\ntable { width: 100%; table-layout: fixed; }\nth, td { white-space: normal; overflow-wrap: anywhere; }\nthead { display: table-header-group; }\ntr, img { break-inside: avoid; }\nh1, h2, h3, h4, h5, h6 { break-after: avoid; }\np, li { orphans: 3; widows: 3; }\n",r.head.appendChild(o),r.querySelectorAll("details").forEach((e=>{e.open=!0})),r.querySelectorAll("img").forEach((e=>{e.loading="eager"})),r.close(),e.focus(),yield m(e,r),e.closed)throw new Error("The response print window was closed.");r.body.offsetHeight,e.focus(),e.print()}catch(t){throw e.close(),t}})),m=(t,r)=>new Promise(((o,n)=>{const i=new Set(Array.from(r.images)),a=e=>{if(c)return;i.delete(e);const t=r.createElement("span");t.textContent=`⚠ ${e.alt.trim()||"[…]"}`,t.style.cssText="display:inline-block;border:1px solid #999;padding:4px;white-space:normal;overflow-wrap:anywhere;",e.removeAttribute("src"),e.removeAttribute("srcset"),e.replaceWith(t)},l=window.setTimeout((()=>{i.forEach(a),d()}),15e3),p=window.setInterval((()=>{t.closed&&d(new Error("The response print window was closed."))}),100);let c=!1;function d(e){c||(c=!0,window.clearTimeout(l),window.clearInterval(p),e?n(e):o())}Promise.all([...Array.from(i,(t=>e(void 0,void 0,void 0,(function*(){try{if(yield t.decode(),!t.complete||!t.naturalWidth||!t.naturalHeight)throw new Error("Unable to load a response print image.");i.delete(t)}catch(e){a(t)}})))),r.fonts.ready]).then((()=>d()),(()=>d(new Error("Unable to load the response print resources."))))}));export{c as createResponseDownloadDocument,p as createResponseDownloadHtml,s as printResponseDownloadDocument,d as printResponseDownloadHtml};
1
+ import{__awaiter as e}from"../_virtual/_tslib.js";import{createElement as t}from"react";import{renderToStaticMarkup as r}from"react-dom/server";import n from"react-markdown";import o from"remark-gfm";import i from"rehype-raw";import a from"isomorphic-dompurify";import{filterArtifactStyles as l}from"./responseArtifactStyles.js";import{createResponseSvgImage as c}from"./responseStandaloneSvg.js";const d=a=>e(void 0,void 0,void 0,(function*(){var e,l,d;const s=r(t(n,{remarkPlugins:[o],rehypePlugins:[i],components:{input:({type:e,checked:r})=>"checkbox"===(null==e?void 0:e.toLowerCase())?t("span",null,r?"☑":"☐"):null}},a)),m=document.createElement("template");m.innerHTML=s;const h=(e=>{var t;let r=!1;const n=new Set(Array.from(e.querySelectorAll("img[src]"),(e=>e.getAttribute("src"))));for(const o of e.querySelectorAll("a[href]"))if(!o.closest("pre,code")&&!o.querySelector("img"))try{const e=new URL(o.getAttribute("href")||""),i=decodeURIComponent(e.pathname.split("/").pop()||"");if("https:"!==e.protocol||e.username||e.password||!e.pathname.includes("/action_generated_files/")||!/\.(png|jpe?g|gif|webp|svg)$/i.test(i)||n.has(e.href))continue;n.add(e.href);const a=document.createElement("img");a.src=e.href,a.alt=(null===(t=o.textContent)||void 0===t?void 0:t.trim())||i;const l=document.createElement("span");o.replaceWith(l),l.append(o,document.createElement("br"),a),r=!0}catch(e){}return r})(m.content),f=Array.from(m.content.querySelectorAll("svg")).filter((e=>{var t;return!(null===(t=e.parentElement)||void 0===t?void 0:t.closest("svg"))}));if(!f.length&&!h)return p(s);for(const t of f)try{const e=yield c(t.outerHTML,""),r=document.createElement("template");r.innerHTML=e,t.replaceWith(r.content)}catch(r){const n=document.createElement("span");n.textContent=`⚠ ${(null===(e=t.getAttribute("aria-label"))||void 0===e?void 0:e.trim())||(null===(d=null===(l=t.querySelector("title"))||void 0===l?void 0:l.textContent)||void 0===d?void 0:d.trim())||"[…]"}`,t.replaceWith(n)}return p(m.innerHTML)})),p=(e,t=!1)=>{let r=a.sanitize(e,{USE_PROFILES:{html:!0},FORBID_TAGS:["script","style","iframe","form","input","button","select","textarea","object","embed","link","meta","base","audio","video","source","track"],FORBID_ATTR:["srcset","ping","background",...t?[]:["style"]],ALLOW_DATA_ATTR:!1});if(t){const e=document.createElement("template");e.innerHTML=r,l(e.content),e.content.querySelectorAll("label").forEach((e=>{var t;(null===(t=e.textContent)||void 0===t?void 0:t.trim())||e.children.length||e.remove()})),r=e.innerHTML}return`<!doctype html>\n<html>\n<head>\n<meta charset="utf-8">\n<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src https: data:; base-uri 'none'; form-action 'none'">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>Pickaxe</title>\n<style>\nbody { margin: 0; background: white; color: #202020; font: 16px/1.6 system-ui, sans-serif; }\nmain { max-width: 900px; margin: 0 auto; padding: 24px; overflow-wrap: anywhere; }\nh1, h2, h3, h4, h5, h6 { line-height: 1.25; }\na { color: #174ea6; }\npre, code { font-family: ui-monospace, monospace; }\npre { padding: 16px; background: #f4f4f4; overflow-x: auto; white-space: pre; }\nblockquote { margin-left: 0; padding-left: 16px; border-left: 3px solid #ccc; }\ntable { border-collapse: collapse; max-width: 100%; }\nth, td { border: 1px solid #ccc; padding: 8px; text-align: start; }\nimg { max-width: 100%; height: auto; }\nsummary { cursor: pointer; }\n${t?"\n.pxe-export-artifact { max-width: 100%; overflow-x: auto; }\n.pxe-export-artifact:has(tr > :nth-child(6)) > div { min-width: 720px; }\n.pxe-export-artifact table { width: 100%; max-width: 100%; }\n.pxe-export-artifact th, .pxe-export-artifact td { overflow-wrap: anywhere; }\n@media print {\n .pxe-export-artifact { overflow: visible; }\n .pxe-export-artifact:has(tr > :nth-child(6)) > div { min-width: 0; }\n .pxe-export-artifact table { width: 100%; min-width: 0; max-width: 100%; table-layout: fixed; }\n .pxe-export-artifact th, .pxe-export-artifact td { padding: 5px !important; font-size: 10px !important; overflow-wrap: anywhere; }\n .pxe-export-artifact, .pxe-export-artifact * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }\n}\n":""}</style>\n</head>\n<body><main dir="auto">${r}</main></body>\n</html>`},s=t=>e(void 0,void 0,void 0,(function*(){const e=window.open("","_blank");if(!e)throw new Error("Unable to open the response print window.");e.opener=null;try{yield m(yield d(t),e)}catch(t){throw e.close(),t}})),m=(t,r)=>e(void 0,void 0,void 0,(function*(){const e=null!=r?r:window.open("","_blank");if(!e||e.closed)throw new Error("Unable to open the response print window.");try{e.opener=null;const r=e.document;r.open(),r.write(t);const n=r.createElement("style");if(n.media="print",n.textContent="\n@page { margin: 12mm; }\nmain { max-width: none; padding: 0; }\npre { overflow: visible; }\npre, pre code { white-space: pre-wrap; overflow-wrap: anywhere; }\ntable { width: 100%; table-layout: fixed; }\nth, td { white-space: normal; overflow-wrap: anywhere; }\nthead { display: table-header-group; }\ntr, img { break-inside: avoid; }\nh1, h2, h3, h4, h5, h6 { break-after: avoid; }\np, li { orphans: 3; widows: 3; }\n",r.head.appendChild(n),r.querySelectorAll("details").forEach((e=>{e.open=!0})),r.querySelectorAll("img").forEach((e=>{e.loading="eager"})),r.close(),e.focus(),yield h(e,r),e.closed)throw new Error("The response print window was closed.");r.body.offsetHeight,e.focus(),e.print()}catch(t){throw e.close(),t}})),h=(t,r)=>new Promise(((n,o)=>{const i=new Set(Array.from(r.images)),a=e=>{if(d)return;i.delete(e);const t=r.createElement("span");t.textContent=`⚠ ${e.alt.trim()||"[…]"}`,t.style.cssText="display:inline-block;border:1px solid #999;padding:4px;white-space:normal;overflow-wrap:anywhere;",e.removeAttribute("src"),e.removeAttribute("srcset"),e.replaceWith(t)},l=window.setTimeout((()=>{i.forEach(a),p()}),15e3),c=window.setInterval((()=>{t.closed&&p(new Error("The response print window was closed."))}),100);let d=!1;function p(e){d||(d=!0,window.clearTimeout(l),window.clearInterval(c),e?o(e):n())}Promise.all([...Array.from(i,(t=>e(void 0,void 0,void 0,(function*(){try{if(yield t.decode(),!t.complete||!t.naturalWidth||!t.naturalHeight)throw new Error("Unable to load a response print image.");i.delete(t)}catch(e){a(t)}})))),r.fonts.ready]).then((()=>p()),(()=>p(new Error("Unable to load the response print resources."))))}));export{p as createResponseDownloadDocument,d as createResponseDownloadHtml,m as printResponseDownloadDocument,s as printResponseDownloadHtml};
@@ -1 +1 @@
1
- const e=(e,t)=>{var n;if(!t.length)return e;const r=(new DOMParser).parseFromString(e,"text/html"),i=r.querySelector('meta[http-equiv="Content-Security-Policy"]');if(!i)throw new Error("Missing response document policy.");i.setAttribute("content",i.getAttribute("content").replace("script-src 'none'","script-src 'unsafe-inline'"));const o=r.createElement("style");o.textContent="\nmain { max-width: 1200px; }\nmain > * { max-width: 900px; margin-left: auto; margin-right: auto; }\nmain > .pxe-interactive-section { max-width: none; }\n@media (max-width: 600px) { main { padding: 12px; } }\n",r.head.appendChild(o);for(const e of t){const t=r.getElementById(e.placeholder);if(!t)throw new Error("Missing response artifact placeholder.");null===(n=t.closest("section"))||void 0===n||n.classList.add("pxe-interactive-section");const i=r.createElement("iframe");i.setAttribute("sandbox","allow-scripts"),i.setAttribute("referrerpolicy","no-referrer"),i.title=e.title,i.style.cssText="display:block;width:100%;height:85vh;min-height:360px;border:0;resize:vertical;overflow:auto;",i.srcdoc=e.content,t.replaceWith(i)}return`<!doctype html>\n${r.documentElement.outerHTML}`};export{e as embedInteractiveArtifacts};
1
+ const t=t=>{var e;const n=new Set;for(const r of t){const t=document.createElement("template");t.innerHTML=r.content;for(const r of t.content.querySelectorAll("script[src]"))try{const t=new URL(null!==(e=r.getAttribute("src"))&&void 0!==e?e:"");t.username||t.password||!/^https:\/\/[a-z0-9.-]+(?::\d+)?$/i.test(t.origin)||n.add(t.origin)}catch(t){}}return[...n]},e=(e,n)=>{var r;if(!n.length)return e;const o=(new DOMParser).parseFromString(e,"text/html"),i=o.querySelector('meta[http-equiv="Content-Security-Policy"]');if(!i)throw new Error("Missing response document policy.");const c=["'unsafe-inline'",...t(n)].join(" ");i.setAttribute("content",i.getAttribute("content").replace("script-src 'none'",`script-src ${c}`));const s=o.createElement("style");s.textContent="\nmain { max-width: 1200px; }\nmain > * { max-width: 900px; margin-left: auto; margin-right: auto; }\nmain > .pxe-interactive-section { max-width: none; }\n@media (max-width: 600px) { main { padding: 12px; } }\n",o.head.appendChild(s);for(const t of n){const e=o.getElementById(t.placeholder);if(!e)throw new Error("Missing response artifact placeholder.");null===(r=e.closest("section"))||void 0===r||r.classList.add("pxe-interactive-section");const n=o.createElement("iframe");n.setAttribute("sandbox","allow-scripts"),n.setAttribute("referrerpolicy","no-referrer"),n.title=t.title,n.style.cssText="display:block;width:100%;height:85vh;min-height:360px;border:0;resize:vertical;overflow:auto;",n.srcdoc=t.content,e.replaceWith(n)}return`<!doctype html>\n${o.documentElement.outerHTML}`};export{e as embedInteractiveArtifacts};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../_virtual/_tslib.js";import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as r,useEffect as i}from"react";import{createPortal as s}from"react-dom";import{v4 as l}from"uuid";import a from"file-saver";import{createResponseDownloadDocx as d}from"../../../common/responseDownloadDocx.js";import{embedResponseDownloadHtmlImages as c}from"../../../common/responseDownloadImages.js";import{printResponseDownloadDocument as u,printResponseDownloadHtml as m,createResponseDownloadHtml as p}from"../../../common/responseDownloadHtml.js";import{findResponseArtifacts as f,prepareResponseArtifactDownload as x}from"../../../common/responseDownloadArtifacts.js";import{renderResponseArtifactHtml as v}from"../../../common/responseArtifactSnapshot.js";import{useArtifactContext as h}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useArtifactData as y}from"../Addons/Artifact/hooks/useArtifactData.js";import{useAuthContext as b}from"../Addons/Auth/hooks/useAuthContext.js";import{usePickaxeContext as w}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useOutsideAlerter as g}from"../../../hooks/core/useOutsideAlerter.js";import k from"../../Icons/download.svg.js";import j from"../../Core/Menu/index.js";import A from"../../Core/Menu/List.js";const D=[{extension:"txt",label:"TXT",mimeType:"text/plain;charset=utf-8"},{extension:"md",label:"Markdown (.md)",mimeType:"text/markdown;charset=utf-8"},{extension:"html",label:"HTML (.html)",mimeType:"text/html;charset=utf-8"},{extension:"pdf",label:"PDF"},{extension:"docx",label:"DOCX"}],T=({color:T,text:C,disabled:O=!1})=>{const{translations:S,colors:P,styles:I,isRtl:M,sender:N,senderType:$,pickaxe:B}=w(),{artifacts:E=[]}=h(),{token:F}=b(),L=y(),[_,H]=n(""),[K,R]=n(!1),[U,X]=n(),[W,q]=n(!1),z=r(!1),G=r(null),J=r(null),Q=r([]),V=r(0),Y=(null==S?void 0:S.download)||"Download",Z=O||W||!C.trim();i((()=>{H(`response-download-${l()}`)}),[]),i((()=>{Z&&R(!1)}),[Z]),i((()=>{K&&G.current&&X(getComputedStyle(G.current).fontFamily)}),[K,I.font]),g({ref:[G,J],callback:()=>R(!1)});const ee=()=>{var e;R(!1),null===(e=G.current)||void 0===e||e.focus({preventScroll:!0})},oe=e=>{var o;if(!Z)if("Escape"===e.key&&K)e.preventDefault(),e.stopPropagation(),ee();else if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault(),e.stopPropagation();const t=Q.current.indexOf(e.currentTarget),n="ArrowDown"===e.key?1:-1,r=D.length,i=-1===t?1===n?0:r-1:(t+n+r)%r;V.current=i,R(!0),null===(o=Q.current[i])||void 0===o||o.focus({preventScroll:!0})}else"Tab"===e.key&&R(!1)},te=e=>{e.relatedTarget===G.current||Q.current.some((o=>o===e.relatedTarget))||R(!1)};return o(j,Object.assign({id:_,className:"h-4 w-4 shrink-0",isOpen:K&&!Z,onChange:R,closeOnSelect:!1,closeOnClickOutside:!1},{children:[t("button",Object.assign({ref:G,id:_||void 0,type:"button",className:"flex h-4 w-4 shrink-0 items-center justify-center rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-30",style:{color:T},title:Y,"aria-label":Y,"aria-haspopup":"menu","aria-busy":W,"aria-expanded":K&&!Z,"aria-controls":K&&!Z?`${_}-menu`:void 0,disabled:Z,onClick:e=>{e.stopPropagation(),V.current=0,R((e=>!e))},onKeyDown:oe,onBlur:te},{children:t(k,{className:"h-4 w-4 shrink-0","aria-hidden":"true"})})),_&&!Z&&s(t("div",Object.assign({ref:J,style:{fontFamily:U},dir:M?"rtl":"ltr"},{children:t(A,Object.assign({id:`${_}-menu`,role:"menu",align:"right",width:"auto",className:"p-1 text-sm",style:{backgroundColor:P.primary,color:P.text,maxWidth:"calc(100vw - 32px)"},imperativeModeOnly:!0,afterShow:()=>{var e;return null===(e=Q.current[V.current])||void 0===e?void 0:e.focus({preventScroll:!0})}},{children:D.map(((o,n)=>t("button",Object.assign({ref:e=>{Q.current[n]=e},type:"button",role:"menuitem",tabIndex:-1,className:"rounded-sm px-3 py-2 text-left hover:bg-black/10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-[-2px]",onClick:t=>{((o,t)=>{e(void 0,void 0,void 0,(function*(){var n;if(o.stopPropagation(),Z||z.current)return;let r;ee();try{const o=f(C);let i;if(o.length){if(z.current=!0,q(!0),"pdf"===t.extension){if(r=null!==(n=window.open("","_blank"))&&void 0!==n?n:void 0,!r)throw new Error("Unable to open the print window.");r.opener=null;const e=r.document.createElement("p");e.textContent=(null==S?void 0:S.loading)||"Loading...",e.setAttribute("role","status"),e.style.cssText="margin:32px;font:16px system-ui,sans-serif",r.document.body.appendChild(e)}i=yield x(C,o,(o=>e(void 0,void 0,void 0,(function*(){const e=E.find((e=>e.id===o.id&&e.version===o.version));return null!=e?e:L.mutateAsync({artifactId:o.id,version:o.version,studioId:null==B?void 0:B.studioid,senderType:$,sender:N||void 0,studioSessionToken:F||void 0})}))),t.extension,(e=>v(e,"pdf"===t.extension||"docx"===t.extension,r)))}if("docx"===t.extension){z.current=!0,q(!0);const e=yield d(C,i);return void a(e,"response.docx")}if("pdf"===t.extension)return z.current=!0,q(!0),void(i?yield u(i,r):yield m(C));let s=null!=i?i:"html"===t.extension?p(C):C;"html"===t.extension&&(z.current=!0,q(!0),s=yield c(s));const l=new Blob([s],{type:t.mimeType});a(l,`response.${t.extension}`)}catch(e){console.error("Response download failed",{format:t.extension,error:e}),null==r||r.close(),window.alert((null==S?void 0:S["something-went-wrong"])||"Something went wrong.")}finally{z.current=!1,q(!1)}}))})(t,o)},onKeyDown:oe,onBlur:te},{children:o.label}),o.extension)))}))})),document.body)]}))};export{T as default};
1
+ import{__awaiter as e}from"../../../_virtual/_tslib.js";import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as r,useEffect as i}from"react";import{createPortal as s}from"react-dom";import{v4 as l}from"uuid";import a from"file-saver";import{createResponseDownloadDocx as d}from"../../../common/responseDownloadDocx.js";import{embedResponseDownloadHtmlImages as c}from"../../../common/responseDownloadImages.js";import{printResponseDownloadDocument as u,printResponseDownloadHtml as m,createResponseDownloadHtml as p}from"../../../common/responseDownloadHtml.js";import{findResponseArtifacts as f,prepareResponseArtifactDownload as x}from"../../../common/responseDownloadArtifacts.js";import{renderResponseArtifactHtml as v}from"../../../common/responseArtifactSnapshot.js";import{useArtifactContext as h}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useArtifactData as y}from"../Addons/Artifact/hooks/useArtifactData.js";import{useAuthContext as b}from"../Addons/Auth/hooks/useAuthContext.js";import{usePickaxeContext as w}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useOutsideAlerter as g}from"../../../hooks/core/useOutsideAlerter.js";import k from"../../Icons/download.svg.js";import j from"../../Core/Menu/index.js";import A from"../../Core/Menu/List.js";const D=[{extension:"txt",label:"TXT",mimeType:"text/plain;charset=utf-8"},{extension:"md",label:"Markdown (.md)",mimeType:"text/markdown;charset=utf-8"},{extension:"html",label:"HTML (.html)",mimeType:"text/html;charset=utf-8"},{extension:"pdf",label:"PDF"},{extension:"docx",label:"DOCX"}],T=({color:T,text:C,disabled:O=!1})=>{const{translations:S,colors:P,styles:I,isRtl:M,sender:N,senderType:$,pickaxe:B}=w(),{artifacts:E=[]}=h(),{token:F}=b(),L=y(),[_,H]=n(""),[K,R]=n(!1),[U,X]=n(),[W,q]=n(!1),z=r(!1),G=r(null),J=r(null),Q=r([]),V=r(0),Y=(null==S?void 0:S.download)||"Download",Z=O||W||!C.trim();i((()=>{H(`response-download-${l()}`)}),[]),i((()=>{Z&&R(!1)}),[Z]),i((()=>{K&&G.current&&X(getComputedStyle(G.current).fontFamily)}),[K,I.font]),g({ref:[G,J],callback:()=>R(!1)});const ee=()=>{var e;R(!1),null===(e=G.current)||void 0===e||e.focus({preventScroll:!0})},oe=e=>{var o;if(!Z)if("Escape"===e.key&&K)e.preventDefault(),e.stopPropagation(),ee();else if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault(),e.stopPropagation();const t=Q.current.indexOf(e.currentTarget),n="ArrowDown"===e.key?1:-1,r=D.length,i=-1===t?1===n?0:r-1:(t+n+r)%r;V.current=i,R(!0),null===(o=Q.current[i])||void 0===o||o.focus({preventScroll:!0})}else"Tab"===e.key&&R(!1)},te=e=>{e.relatedTarget===G.current||Q.current.some((o=>o===e.relatedTarget))||R(!1)};return o(j,Object.assign({id:_,className:"h-4 w-4 shrink-0",isOpen:K&&!Z,onChange:R,closeOnSelect:!1,closeOnClickOutside:!1},{children:[t("button",Object.assign({ref:G,id:_||void 0,type:"button",className:"flex h-4 w-4 shrink-0 items-center justify-center rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-30",style:{color:T},title:Y,"aria-label":Y,"aria-haspopup":"menu","aria-busy":W,"aria-expanded":K&&!Z,"aria-controls":K&&!Z?`${_}-menu`:void 0,disabled:Z,onClick:e=>{e.stopPropagation(),V.current=0,R((e=>!e))},onKeyDown:oe,onBlur:te},{children:t(k,{className:"h-4 w-4 shrink-0","aria-hidden":"true"})})),_&&!Z&&s(t("div",Object.assign({ref:J,style:{fontFamily:U},dir:M?"rtl":"ltr"},{children:t(A,Object.assign({id:`${_}-menu`,role:"menu",align:"right",width:"auto",className:"p-1 text-sm",style:{backgroundColor:P.primary,color:P.text,maxWidth:"calc(100vw - 32px)"},imperativeModeOnly:!0,afterShow:()=>{var e;return null===(e=Q.current[V.current])||void 0===e?void 0:e.focus({preventScroll:!0})}},{children:D.map(((o,n)=>t("button",Object.assign({ref:e=>{Q.current[n]=e},type:"button",role:"menuitem",tabIndex:-1,className:"rounded-sm px-3 py-2 text-left hover:bg-black/10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-[-2px]",onClick:t=>{((o,t)=>{e(void 0,void 0,void 0,(function*(){var n;if(o.stopPropagation(),Z||z.current)return;let r;ee();try{const o=f(C);let i;if(o.length){if(z.current=!0,q(!0),"pdf"===t.extension){if(r=null!==(n=window.open("","_blank"))&&void 0!==n?n:void 0,!r)throw new Error("Unable to open the print window.");r.opener=null;const e=r.document.createElement("p");e.textContent=(null==S?void 0:S.loading)||"Loading...",e.setAttribute("role","status"),e.style.cssText="margin:32px;font:16px system-ui,sans-serif",r.document.body.appendChild(e)}i=yield x(C,o,(o=>e(void 0,void 0,void 0,(function*(){const e=E.find((e=>e.id===o.id&&e.version===o.version));return null!=e?e:L.mutateAsync({artifactId:o.id,version:o.version,studioId:null==B?void 0:B.studioid,senderType:$,sender:N||void 0,studioSessionToken:F||void 0})}))),t.extension,(e=>v(e,"pdf"===t.extension||"docx"===t.extension,r)))}if("docx"===t.extension){z.current=!0,q(!0);const e=yield d(C,i);return void a(e,"response.docx")}if("pdf"===t.extension)return z.current=!0,q(!0),void(i?yield u(i,r):yield m(C));"html"===t.extension&&(z.current=!0,q(!0));let s=null!=i?i:"html"===t.extension?yield p(C):C;"html"===t.extension&&(z.current=!0,q(!0),s=yield c(s));const l=new Blob([s],{type:t.mimeType});a(l,`response.${t.extension}`)}catch(e){console.error("Response download failed",{format:t.extension,error:e}),null==r||r.close(),window.alert((null==S?void 0:S["something-went-wrong"])||"Something went wrong.")}finally{z.current=!1,q(!1)}}))})(t,o)},onKeyDown:oe,onBlur:te},{children:o.label}),o.extension)))}))})),document.body)]}))};export{T as default};
@@ -3,7 +3,7 @@
3
3
  * Does not mount the chat renderer, run response scripts, or fetch linked content.
4
4
  * Code fences stay literal; only the export gets these stricter HTML rules.
5
5
  */
6
- export declare const createResponseDownloadHtml: (text: string) => string;
6
+ export declare const createResponseDownloadHtml: (text: string) => Promise<string>;
7
7
  /** All assembled content, including artifact snapshots, crosses this boundary. */
8
8
  export declare const createResponseDownloadDocument: (rendered: string, preserveArtifactStyles?: boolean) => string;
9
9
  /** Opens a print copy from the user's click without changing the live response. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "6.23.4",
3
+ "version": "6.23.5",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",