@alwith/module-editor 0.1.0-rc.13 → 0.1.0-rc.14

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.
Files changed (68) hide show
  1. package/README.md +6 -0
  2. package/dist/chunk-0m07f1rf.js +2 -0
  3. package/dist/chunk-68dtjjm4.js +2 -0
  4. package/dist/chunk-6nvrc7p7.js +9 -0
  5. package/dist/chunk-7zewhyx6.js +2 -0
  6. package/dist/chunk-83qapya5.js +3 -0
  7. package/dist/chunk-9mb4nnsc.js +2 -0
  8. package/dist/chunk-b1xr49tw.js +2 -0
  9. package/dist/chunk-b5q2ys0a.js +2 -0
  10. package/dist/chunk-bh9vgt8q.js +2 -0
  11. package/dist/chunk-czgs93zj.js +3 -0
  12. package/dist/chunk-dr1ebnb1.js +2 -0
  13. package/dist/chunk-e5hxq2gn.js +2 -0
  14. package/dist/chunk-gq1eh0tx.js +2 -0
  15. package/dist/chunk-jdjcp0ak.js +4 -0
  16. package/dist/chunk-nn5x2ear.js +2 -0
  17. package/dist/chunk-qanrx7j1.js +2 -0
  18. package/dist/chunk-qt0cfrrv.js +2 -0
  19. package/dist/chunk-s6jrc7pq.js +2 -0
  20. package/dist/chunk-sq7vxhx3.js +2 -0
  21. package/dist/chunk-yhtn3t0e.js +2 -0
  22. package/dist/core.js +1 -8
  23. package/dist/index.d.ts +8 -8
  24. package/dist/index.js +1 -1
  25. package/dist/monaco.d.ts +2 -2
  26. package/dist/monaco.js +1 -1
  27. package/dist/new-tab.d.ts +2 -2
  28. package/dist/new-tab.js +1 -1
  29. package/dist/preview-source-mode-toggle.js +1 -1
  30. package/dist/previews/excel-data.js +1 -3
  31. package/dist/previews/excel-navigation.js +1 -1
  32. package/dist/previews/excel.d.ts +1 -1
  33. package/dist/previews/excel.js +2 -1
  34. package/dist/previews/html-resources.d.ts +1 -1
  35. package/dist/previews/html-resources.js +1 -2
  36. package/dist/previews/html-session.d.ts +1 -1
  37. package/dist/previews/html-session.js +1 -1
  38. package/dist/previews/html.d.ts +1 -1
  39. package/dist/previews/html.js +2 -1
  40. package/dist/previews/index.d.ts +3 -3
  41. package/dist/previews/index.js +2 -1
  42. package/dist/previews/markdown-outline.d.ts +1 -1
  43. package/dist/previews/markdown-outline.js +2 -1
  44. package/dist/previews/markdown-readonly.d.ts +1 -1
  45. package/dist/previews/markdown-readonly.js +2 -2
  46. package/dist/previews/markdown.d.ts +1 -1
  47. package/dist/previews/markdown.js +2 -1
  48. package/dist/previews/media-types.js +1 -1
  49. package/dist/previews/media.d.ts +1 -1
  50. package/dist/previews/media.js +2 -1
  51. package/dist/previews/pdf-controls.js +1 -1
  52. package/dist/previews/pdf.d.ts +1 -1
  53. package/dist/previews/pdf.js +2 -1
  54. package/dist/previews/shared.d.ts +1 -1
  55. package/dist/previews/shared.js +2 -1
  56. package/dist/previews/tiff.d.ts +1 -1
  57. package/dist/previews/tiff.js +2 -1
  58. package/dist/previews/word.d.ts +1 -1
  59. package/dist/previews/word.js +2 -1
  60. package/dist/quick-start-assets.js +1 -1
  61. package/dist/quick-start-data.js +1 -1
  62. package/dist/quick-start-icons.js +1 -1
  63. package/dist/workspace-assets.js +1 -1
  64. package/dist/workspace-tabs.d.ts +2 -2
  65. package/dist/workspace-tabs.js +1 -1
  66. package/dist/workspace.d.ts +1 -1
  67. package/dist/workspace.js +1 -1
  68. package/package.json +21 -21
@@ -1 +1,2 @@
1
- import{jsx as E,jsxs as X}from"react/jsx-runtime";import{defaultValueCtx as Y,Editor as Z,EditorStatus as p,editorViewCtx as tt,editorViewOptionsCtx as et,rootCtx as rt,serializerCtx as nt}from"@milkdown/core";import{history as ot}from"@milkdown/plugin-history";import{math as ct}from"@milkdown/plugin-math";import{commonmark as it,imageSchema as at}from"@milkdown/preset-commonmark";import{gfm as ut}from"@milkdown/preset-gfm";import{Plugin as st}from"@milkdown/prose/state";import{$prose as lt,getMarkdown as C,replaceAll as _}from"@milkdown/utils";import{useCallback as dt,useEffect as L,useEffectEvent as j,useMemo as z,useRef as k,useState as v}from"react";import{MarkdownOutline as mt}from"./markdown-outline.js";import{MarkdownReadonly as ft}from"./markdown-readonly.js";import"katex/dist/katex.min.css";import"@milkdown/prose/view/style/prosemirror.css";import"@milkdown/prose/tables/style/tables.css";import{ErrorMessage as ht,errorText as q}from"./shared.js";function wt(t){let[x,m]=v(null),e=dt(()=>m(t.document.id),[t.document.id]),w=z(()=>t.document.text.replace(/^\s*<!--\s*plate-metadata:[\s\S]*?-->\s*/i,"").replace(/\s*<!--\s*plate-metadata:[\s\S]*?-->\s*$/i,""),[t.document.text]),T=z(()=>({...t.document,text:w}),[t.document,w]);if(z(()=>new TextEncoder().encode(w).byteLength,[w])>=1048576&&x!==t.document.id)return E(ft,{...t,document:T,onSwitchToEditor:e});return E(yt,{...t,document:T})}function yt(t){let x=k(null),m=k(null),e=k(t);e.current=t;let[w,T]=v(()=>({id:t.document.id,host:t.host,integration:t.host.createMarkdownIntegration?.(t.document,t.context)})),o=w.integration;if(w.id!==t.document.id||w.host!==t.host)o=t.host.createMarkdownIntegration?.(t.document,t.context),T({id:t.document.id,host:t.host,integration:o});let f=k(t.document.text),M=k(!1),u=k(null),[A,D]=v(0),[B,O]=v(null),[F,I]=v(!1);L(()=>{if(!x.current)throw Error("Markdown container is missing");let c=x.current;f.current=e.current.document.text,I(!1),O(null);let h=!1,S=new Set,g=(r)=>{if(!h)O(q(r)),e.current.context.onError(r)},b=null,P=new MutationObserver(()=>{if(b)clearTimeout(b);b=setTimeout(()=>{b=null,D((r)=>r+1)},800)});P.observe(c,{childList:!0,subtree:!0,characterData:!0});let d=Z.make().config((r)=>{r.update(at.key,(a)=>(s)=>{let n=a(s);return{...n,parseMarkdown:{...n.parseMarkdown,runner:(y,i,R)=>n.parseMarkdown.runner(y,{...i,alt:i.alt??"",title:i.title??""},R)}}}),r.set(rt,c),r.set(Y,e.current.document.text),r.update(et,(a)=>({...a,attributes:(s)=>({...typeof a.attributes==="function"?a.attributes(s):a.attributes,"aria-label":e.current.document.path}),editable:()=>!e.current.context.readOnly&&(o?.editable()??!0),nodeViews:{...a.nodeViews,image:(s)=>{let n=window.document.createElement("img"),y=0,i=null,R=(l,H,J)=>{let Q=++y;if(i)URL.revokeObjectURL(i),S.delete(i),i=null;if(n.removeAttribute("src"),n.alt=H,n.title=J,!l)return;if(/^data:image\//i.test(l)){n.src=l;return}if(/^https:\/\//i.test(l)&&e.current.host.allowRemoteResources){n.referrerPolicy="no-referrer",n.src=l;return}if(/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(l)){g(Error(`Remote Markdown image is blocked: ${l}`));return}e.current.host.resolveResource(e.current.document.path,l).then((U)=>{if(h||Q!==y)return;if(!U.mimeType.startsWith("image/"))throw Error("Markdown resource is not an image");i=URL.createObjectURL(new Blob([new Uint8Array(U.bytes).buffer],{type:U.mimeType})),S.add(i),n.src=i}).catch(g)};return R(String(s.attrs.src||""),String(s.attrs.alt||""),String(s.attrs.title||"")),{dom:n,update:(l)=>{if(l.type!==s.type)return!1;return R(String(l.attrs.src||""),String(l.attrs.alt||""),String(l.attrs.title||"")),!0},destroy:()=>{if(y++,i)URL.revokeObjectURL(i),S.delete(i)}}}}}))}).use(it).use(ut).use(ct).use(ot).use(lt((r)=>new st({view:()=>({update:(a,s)=>{if(h||M.current||m.current!==d||e.current.context.readOnly||o?.editable()===!1||a.state.doc.eq(s.doc))return;try{let n=r.get(nt)(a.state.doc);if(n===f.current)return;if(f.current=n,e.current.context.onChange(o?.serialize(n)??n),u.current)clearTimeout(u.current);let y=e.current.host.autoSaveDelay;if(y!==void 0)u.current=setTimeout(()=>{if(u.current=null,!h&&!e.current.context.readOnly&&(o?.editable()??!0))try{e.current.context.onSave()}catch(i){g(i)}},y)}catch(n){g(n)}}})})));o?.configure(d),d.create().then(async()=>{if(h){d.destroy().catch(e.current.context.onError);return}if(e.current.document.text!==f.current)f.current=e.current.document.text,d.action(_(f.current)),f.current=d.action(C());if(f.current=d.action(C()),m.current=d,o?.applyExternal(d,e.current.document),await o?.ready(d),h)return;D((r)=>r+1),I(!0)}).catch(g);let N=(r)=>{if((r.metaKey||r.ctrlKey)&&r.key.toLowerCase()==="s"){if(r.preventDefault(),r.stopPropagation(),u.current)clearTimeout(u.current),u.current=null;if(!e.current.context.readOnly&&(o?.editable()??!0))try{e.current.context.onSave()}catch(a){g(a)}}},K=(r)=>{let a=r.target.closest("a");if(!a)return;r.preventDefault();let s=a.getAttribute("href");if(s)e.current.host.openLink?.(s).catch(g)};return c.addEventListener("keydown",N),c.addEventListener("click",K),()=>{if(h=!0,u.current)clearTimeout(u.current),u.current=null;if(m.current=null,o?.dispose(),P.disconnect(),b)clearTimeout(b);c.removeEventListener("keydown",N),c.removeEventListener("click",K);for(let r of S)URL.revokeObjectURL(r);if(d.status===p.Created)d.destroy().catch(e.current.context.onError)}},[t.document.id,o]);let W=j(()=>t.document),G=j((c)=>t.context.onError(c));L(()=>{let c=W();if(!m.current||c.text===f.current)return;if(u.current)clearTimeout(u.current),u.current=null;M.current=!0;try{if(!o?.applyExternal(m.current,c))m.current.action(_(c.text));f.current=m.current.action(C())}catch(h){O(q(h)),G(h)}finally{M.current=!1}},[t.document.text,o]),L(()=>{m.current?.action((c)=>c.get(tt).setProps({editable:()=>!t.context.readOnly&&(o?.editable()??!0)}))},[t.context.readOnly,F,o]);let V=j((c)=>t.context.setToolbarActions?.(c));return L(()=>(V(E(mt,{host:t.host,container:x.current,revision:A})),()=>V(null)),[t.context.setToolbarActions,t.host,A]),X("div",{className:"alwith-preview-markdown alwith-markdown-view",children:[E(ht,{error:B}),o?.render(),E("div",{className:"alwith-markdown-scroll",ref:x})]})}export{wt as default};
1
+ import"../chunk-czgs93zj.js";import{j}from"../chunk-9mb4nnsc.js";import{z}from"../chunk-7zewhyx6.js";import{D,N}from"../chunk-0m07f1rf.js";import{r}from"../chunk-83qapya5.js";j(import.meta.url,["pc0wr96w","czgs93zj","9mb4nnsc","7zewhyx6","0m07f1rf","83qapya5","rpk588j2","x6e3x53v","g5mn8gma","ft3hwgj5","pm5mxznh","ewq910t8","b5q2ys0a","6nvrc7p7","gq1eh0tx","dr1ebnb1","qt0cfrrv","qanrx7j1","nn5x2ear","68dtjjm4","b1xr49tw","sq7vxhx3","e5hxq2gn","s6jrc7pq","yhtn3t0e","jdjcp0ak","bh9vgt8q"],[["./markdown.js",1,2,3,4,5],["../chunk-czgs93zj.js"],["../chunk-9mb4nnsc.js"],["../chunk-7zewhyx6.js",2],["../chunk-0m07f1rf.js",2],["../chunk-83qapya5.js",2,3,4],["./tiff.js",12,13,14,15,16,17,18,19,20,21,1,2,4],["./html.js",1,22,2,4],["./word.js",1,2,4],["./pdf.js",1,2,23,4],["./media.js",1,2,24,4],["./excel.js",25,26,1,2,4],["../chunk-b5q2ys0a.js"],["../chunk-6nvrc7p7.js"],["../chunk-gq1eh0tx.js"],["../chunk-dr1ebnb1.js"],["../chunk-qt0cfrrv.js"],["../chunk-qanrx7j1.js"],["../chunk-nn5x2ear.js"],["../chunk-68dtjjm4.js",16,17,18],["../chunk-b1xr49tw.js"],["../chunk-sq7vxhx3.js",12],["../chunk-e5hxq2gn.js",1],["../chunk-s6jrc7pq.js"],["../chunk-yhtn3t0e.js"],["../chunk-jdjcp0ak.js"],["../chunk-bh9vgt8q.js"]],0);
2
+ import{defaultValueCtx as tt,Editor as et,EditorStatus as rt,editorViewCtx as nt,editorViewOptionsCtx as ot,rootCtx as it,serializerCtx as ct}from"@milkdown/core";import{history as at}from"@milkdown/plugin-history";import{math as ut}from"@milkdown/plugin-math";import{commonmark as st,imageSchema as lt}from"@milkdown/preset-commonmark";import{gfm as dt}from"@milkdown/preset-gfm";import{Plugin as mt}from"@milkdown/prose/state";import{$prose as ft,getMarkdown as C,replaceAll as p}from"@milkdown/utils";import{useCallback as wt,useEffect as L,useEffectEvent as A,useMemo as I,useRef as E,useState as T}from"react";import"katex/dist/katex.min.css";import"@milkdown/prose/view/style/prosemirror.css";import"@milkdown/prose/tables/style/tables.css";import{jsxDEV as b}from"react/jsx-dev-runtime";function ht(t){let[k,f]=T(null),e=wt(()=>f(t.document.id),[t.document.id]),y=I(()=>t.document.text.replace(/^\s*<!--\s*plate-metadata:[\s\S]*?-->\s*/i,"").replace(/\s*<!--\s*plate-metadata:[\s\S]*?-->\s*$/i,""),[t.document.text]),R=I(()=>({...t.document,text:y}),[t.document,y]);if(I(()=>new TextEncoder().encode(y).byteLength,[y])>=1048576&&k!==t.document.id)return b(r,{...t,document:R,onSwitchToEditor:e},void 0,!1,void 0,this);return b(yt,{...t,document:R},void 0,!1,void 0,this)}function yt(t){let k=E(null),f=E(null),e=E(t);e.current=t;let[y,R]=T(()=>({id:t.document.id,host:t.host,integration:t.host.createMarkdownIntegration?.(t.document,t.context)})),i=y.integration;if(y.id!==t.document.id||y.host!==t.host)i=t.host.createMarkdownIntegration?.(t.document,t.context),R({id:t.document.id,host:t.host,integration:i});let w=E(t.document.text),O=E(!1),s=E(null),[V,K]=T(0),[G,P]=T(null),[J,q]=T(!1);L(()=>{if(!k.current)throw Error("Markdown container is missing");let c=k.current;w.current=e.current.document.text,q(!1),P(null);let h=!1,M=new Set,v=(n)=>{if(!h)P(N(n)),e.current.context.onError(n)},x=null,F=new MutationObserver(()=>{if(x)clearTimeout(x);x=setTimeout(()=>{x=null,K((n)=>n+1)},800)});F.observe(c,{childList:!0,subtree:!0,characterData:!0});let m=et.make().config((n)=>{n.update(lt.key,(u)=>(l)=>{let o=u(l);return{...o,parseMarkdown:{...o.parseMarkdown,runner:(g,a,S)=>o.parseMarkdown.runner(g,{...a,alt:a.alt??"",title:a.title??""},S)}}}),n.set(it,c),n.set(tt,e.current.document.text),n.update(ot,(u)=>({...u,attributes:(l)=>({...typeof u.attributes==="function"?u.attributes(l):u.attributes,"aria-label":e.current.document.path}),editable:()=>!e.current.context.readOnly&&(i?.editable()??!0),nodeViews:{...u.nodeViews,image:(l)=>{let o=window.document.createElement("img"),g=0,a=null,S=(d,Y,Z)=>{let _=++g;if(a)URL.revokeObjectURL(a),M.delete(a),a=null;if(o.removeAttribute("src"),o.alt=Y,o.title=Z,!d)return;if(/^data:image\//i.test(d)){o.src=d;return}if(/^https:\/\//i.test(d)&&e.current.host.allowRemoteResources){o.referrerPolicy="no-referrer",o.src=d;return}if(/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(d)){v(Error(`Remote Markdown image is blocked: ${d}`));return}e.current.host.resolveResource(e.current.document.path,d).then((U)=>{if(h||_!==g)return;if(!U.mimeType.startsWith("image/"))throw Error("Markdown resource is not an image");a=URL.createObjectURL(new Blob([new Uint8Array(U.bytes).buffer],{type:U.mimeType})),M.add(a),o.src=a}).catch(v)};return S(String(l.attrs.src||""),String(l.attrs.alt||""),String(l.attrs.title||"")),{dom:o,update:(d)=>{if(d.type!==l.type)return!1;return S(String(d.attrs.src||""),String(d.attrs.alt||""),String(d.attrs.title||"")),!0},destroy:()=>{if(g++,a)URL.revokeObjectURL(a),M.delete(a)}}}}}))}).use(st).use(dt).use(ut).use(at).use(ft((n)=>new mt({view:()=>({update:(u,l)=>{if(h||O.current||f.current!==m||e.current.context.readOnly||i?.editable()===!1||u.state.doc.eq(l.doc))return;try{let o=n.get(ct)(u.state.doc);if(o===w.current)return;if(w.current=o,e.current.context.onChange(i?.serialize(o)??o),s.current)clearTimeout(s.current);let g=e.current.host.autoSaveDelay;if(g!==void 0)s.current=setTimeout(()=>{if(s.current=null,!h&&!e.current.context.readOnly&&(i?.editable()??!0))try{e.current.context.onSave()}catch(a){v(a)}},g)}catch(o){v(o)}}})})));i?.configure(m),m.create().then(async()=>{if(h){m.destroy().catch(e.current.context.onError);return}if(e.current.document.text!==w.current)w.current=e.current.document.text,m.action(p(w.current)),w.current=m.action(C());if(w.current=m.action(C()),f.current=m,i?.applyExternal(m,e.current.document),await i?.ready(m),h)return;K((n)=>n+1),q(!0)}).catch(v);let H=(n)=>{if((n.metaKey||n.ctrlKey)&&n.key.toLowerCase()==="s"){if(n.preventDefault(),n.stopPropagation(),s.current)clearTimeout(s.current),s.current=null;if(!e.current.context.readOnly&&(i?.editable()??!0))try{e.current.context.onSave()}catch(u){v(u)}}},W=(n)=>{let u=n.target.closest("a");if(!u)return;n.preventDefault();let l=u.getAttribute("href");if(l)e.current.host.openLink?.(l).catch(v)};return c.addEventListener("keydown",H),c.addEventListener("click",W),()=>{if(h=!0,s.current)clearTimeout(s.current),s.current=null;if(f.current=null,i?.dispose(),F.disconnect(),x)clearTimeout(x);c.removeEventListener("keydown",H),c.removeEventListener("click",W);for(let n of M)URL.revokeObjectURL(n);if(m.status===rt.Created)m.destroy().catch(e.current.context.onError)}},[t.document.id,i]);let Q=A(()=>t.document),X=A((c)=>t.context.onError(c));L(()=>{let c=Q();if(!f.current||c.text===w.current)return;if(s.current)clearTimeout(s.current),s.current=null;O.current=!0;try{if(!i?.applyExternal(f.current,c))f.current.action(p(c.text));w.current=f.current.action(C())}catch(h){P(N(h)),X(h)}finally{O.current=!1}},[t.document.text,i]),L(()=>{f.current?.action((c)=>c.get(nt).setProps({editable:()=>!t.context.readOnly&&(i?.editable()??!0)}))},[t.context.readOnly,J,i]);let B=A((c)=>t.context.setToolbarActions?.(c));return L(()=>(B(b(z,{host:t.host,container:k.current,revision:V},void 0,!1,void 0,this)),()=>B(null)),[t.context.setToolbarActions,t.host,V]),b("div",{className:"alwith-preview-markdown alwith-markdown-view",children:[b(D,{error:G},void 0,!1,void 0,this),i?.render(),b("div",{className:"alwith-markdown-scroll",ref:k},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}export{ht as default};
@@ -1 +1 @@
1
- var e={mp3:"audio/mpeg",mp4:"video/mp4",m4a:"audio/mp4",m4v:"video/x-m4v",aac:"audio/aac",wav:"audio/wav",wave:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",ogv:"video/ogg",webm:"video/webm",mov:"video/quicktime",flac:"audio/flac",opus:"audio/opus",aiff:"audio/aiff",aif:"audio/aiff"};function d(o){let a=o.split(".").at(-1).toLowerCase(),i=e[a];if(!i)throw Error(`Unsupported media preview: ${o}`);return i}export{d as mediaMimeType};
1
+ import{i}from"../chunk-yhtn3t0e.js";export{i as mediaMimeType};
@@ -1,2 +1,2 @@
1
- import { type PreviewProps } from "./index.js";
1
+ import { type PreviewProps } from "./index";
2
2
  export default function Media({ document, context, host }: PreviewProps): import("react").JSX.Element;
@@ -1 +1,2 @@
1
- import{jsx as t,jsxs as n,Fragment as j}from"react/jsx-runtime";import x from"audiomotion-analyzer";import{useEffect as v,useRef as l,useState as N}from"react";import b from"react-player";import{previewLabel as g}from"./index.js";import{mediaMimeType as k}from"./media-types.js";import{ErrorMessage as A,useObjectUrl as M}from"./shared.js";function z({document:c,context:o,host:u}){let d=k(c.path),s=d.startsWith("audio/"),r=M(c.bytes,d),[y,m]=N(null),i=l(null),p=l(null),h=l(o);h.current=o,v(()=>{m(null)},[r]),v(()=>{if(!s||!r)return;let e=i.current,a=p.current;if(!e||!a)return;let w=null;try{w=new x(a,{source:e,height:140,mode:3,gradient:"classic",showBgColor:!1,showScaleX:!1,showScaleY:!1,showPeaks:!1,roundBars:!0,reflexRatio:0,lumiBars:!1,overlay:!0,smoothing:0.7})}catch(E){h.current.onError(E)}return()=>{e.pause(),w?.destroy(),e.removeAttribute("src"),e.load()}},[s,r]);let f=(e)=>{let a=e instanceof Error?e:Error(i.current?.error?.message||g(u,"mediaUnsupported"));m(a.message),o.onError(a)};return t("div",{className:`alwith-preview-media-desktop ${s?"alwith-preview-audio":"alwith-preview-video"}`,children:n("div",{className:"alwith-preview-media-content",children:[t(A,{error:y}),!r&&n("div",{className:"alwith-preview-status",role:"status",children:[t("span",{className:"alwith-preview-spinner"}),g(u,"loading")]}),r&&(s?n(j,{children:[t("div",{ref:p,className:"alwith-preview-audio-spectrum","aria-hidden":"true"}),t("audio",{ref:i,controls:!0,src:r,preload:"metadata",onError:()=>f(),children:t("track",{kind:"captions"})},r)]}):t(b,{src:r,controls:!0,width:"100%",height:"100%",preload:"metadata",playsInline:!0,style:{maxHeight:"100%"},onError:f},r))]})})}export{z as default};
1
+ import"../chunk-czgs93zj.js";import{j,M}from"../chunk-9mb4nnsc.js";import{i}from"../chunk-yhtn3t0e.js";import{C,D}from"../chunk-0m07f1rf.js";j(import.meta.url,["pm5mxznh","czgs93zj","9mb4nnsc","yhtn3t0e","0m07f1rf","rpk588j2","x6e3x53v","g5mn8gma","ft3hwgj5","pc0wr96w","ewq910t8","b5q2ys0a","6nvrc7p7","gq1eh0tx","dr1ebnb1","qt0cfrrv","qanrx7j1","nn5x2ear","68dtjjm4","b1xr49tw","sq7vxhx3","e5hxq2gn","s6jrc7pq","7zewhyx6","83qapya5","jdjcp0ak","bh9vgt8q"],[["./media.js",1,2,3,4],["../chunk-czgs93zj.js"],["../chunk-9mb4nnsc.js"],["../chunk-yhtn3t0e.js"],["../chunk-0m07f1rf.js",2],["./tiff.js",11,12,13,14,15,16,17,18,19,20,1,2,4],["./html.js",1,21,2,4],["./word.js",1,2,4],["./pdf.js",1,2,22,4],["./markdown.js",1,2,23,4,24],["./excel.js",25,26,1,2,4],["../chunk-b5q2ys0a.js"],["../chunk-6nvrc7p7.js"],["../chunk-gq1eh0tx.js"],["../chunk-dr1ebnb1.js"],["../chunk-qt0cfrrv.js"],["../chunk-qanrx7j1.js"],["../chunk-nn5x2ear.js"],["../chunk-68dtjjm4.js",15,16,17],["../chunk-b1xr49tw.js"],["../chunk-sq7vxhx3.js",11],["../chunk-e5hxq2gn.js",1],["../chunk-s6jrc7pq.js"],["../chunk-7zewhyx6.js",2],["../chunk-83qapya5.js",2,23,4],["../chunk-jdjcp0ak.js"],["../chunk-bh9vgt8q.js"]],0);
2
+ import g from"audiomotion-analyzer";import{useEffect as h,useRef as l,useState as k}from"react";import A from"react-player";import{jsxDEV as e,Fragment as N}from"react/jsx-dev-runtime";function P({document:u,context:s,host:c}){let d=i(u.path),a=d.startsWith("audio/"),r=C(u.bytes,d),[y,m]=k(null),n=l(null),p=l(null),w=l(s);w.current=s,h(()=>{m(null)},[r]),h(()=>{if(!a||!r)return;let o=n.current,t=p.current;if(!o||!t)return;let v=null;try{v=new g(t,{source:o,height:140,mode:3,gradient:"classic",showBgColor:!1,showScaleX:!1,showScaleY:!1,showPeaks:!1,roundBars:!0,reflexRatio:0,lumiBars:!1,overlay:!0,smoothing:0.7})}catch(E){w.current.onError(E)}return()=>{o.pause(),v?.destroy(),o.removeAttribute("src"),o.load()}},[a,r]);let f=(o)=>{let t=o instanceof Error?o:Error(n.current?.error?.message||M(c,"mediaUnsupported"));m(t.message),s.onError(t)};return e("div",{className:`alwith-preview-media-desktop ${a?"alwith-preview-audio":"alwith-preview-video"}`,children:e("div",{className:"alwith-preview-media-content",children:[e(D,{error:y},void 0,!1,void 0,this),!r&&e("div",{className:"alwith-preview-status",role:"status",children:[e("span",{className:"alwith-preview-spinner"},void 0,!1,void 0,this),M(c,"loading")]},void 0,!0,void 0,this),r&&(a?e(N,{children:[e("div",{ref:p,className:"alwith-preview-audio-spectrum","aria-hidden":"true"},void 0,!1,void 0,this),e("audio",{ref:n,controls:!0,src:r,preload:"metadata",onError:()=>f(),children:e("track",{kind:"captions"},void 0,!1,void 0,this)},r,!1,void 0,this)]},void 0,!0,void 0,this):e(A,{src:r,controls:!0,width:"100%",height:"100%",preload:"metadata",playsInline:!0,style:{maxHeight:"100%"},onError:f},r,!1,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}export{P as default};
@@ -1 +1 @@
1
- function o(l,n){if(n==="0")return 1;let t=n==="+"||n==="="?0.1:n==="-"||n==="_"?-0.1:null;return t===null?null:Math.min(2,Math.max(0.5,+(l+t).toFixed(2)))}export{o as nextPdfZoom};
1
+ import{I}from"../chunk-s6jrc7pq.js";export{I as nextPdfZoom};
@@ -1,2 +1,2 @@
1
- import { type PreviewProps } from "./index.js";
1
+ import { type PreviewProps } from "./index";
2
2
  export default function Pdf({ document: file, context, host }: PreviewProps): import("react").JSX.Element;
@@ -1 +1,2 @@
1
- import{jsx as v,jsxs as I}from"react/jsx-runtime";import{getDocument as q,GlobalWorkerOptions as O,RenderingCancelledException as U}from"pdfjs-dist";import{useEffect as M,useRef as y,useState as D}from"react";import{previewLabel as R}from"./index.js";import{nextPdfZoom as N}from"./pdf-controls.js";import{ErrorMessage as Y,errorText as Z}from"./shared.js";function G({document:z,context:C,host:p}){let E=y(null),[V,L]=D(null),[W,x]=D(!0),[k,b]=D(1),f=y(k);f.current=k;let m=y({context:C,host:p});m.current={context:C,host:p};let P=y(null);return M(()=>{let d=E.current;if(!d)throw Error("PDF container is missing");O.workerSrc=p.pdfWorkerSrc,L(null),x(!0),b(1),d.replaceChildren();let s=!1,l=null,t=null,o=new Map,u=new Set,h=new Set,w=new Map,g=new Map,T=q({data:new Uint8Array(z.bytes)}),A=(e)=>{if(!s&&!(e instanceof U))L(Z(e)),m.current.context.onError(e)},S=(e)=>{let r=g.get(e);if(!r)throw Error("PDF page size is missing");e.style.width=`${r.width*f.current}px`,e.style.height=`${r.height*f.current}px`,e.style.minWidth=`${Math.min(720,r.width*f.current)}px`},F=(e)=>{w.set(e,(w.get(e)??0)+1),o.get(e)?.cancel(),o.delete(e),u.delete(e);for(let r of e.querySelectorAll("canvas"))r.width=0,r.height=0,r.remove()},_=async(e)=>{if(!l||u.has(e)||e.querySelector("canvas"))return;let r=(w.get(e)??0)+1;w.set(e,r),u.add(e);let n=null;try{let a=await l.getPage(Number(e.dataset.page));if(s||!h.has(e)||w.get(e)!==r)return;let i=a.getViewport({scale:1});g.set(e,{width:i.width,height:i.height}),S(e);let c=a.getViewport({scale:2*Math.min(window.devicePixelRatio||1,2)});if(c.width*c.height>25000000)throw Error("PDF page exceeds the canvas preview limit");n=document.createElement("canvas"),n.width=Math.ceil(c.width),n.height=Math.ceil(c.height);let j=n.getContext("2d");if(!j)throw Error("PDF canvas context is unavailable");let K=a.render({canvas:n,canvasContext:j,viewport:c});if(o.set(e,K),await K.promise,!s&&h.has(e)&&w.get(e)===r)e.append(n)}finally{if(n&&!n.parentElement)n.width=0,n.height=0;if(w.get(e)===r)o.delete(e),u.delete(e)}};return T.promise.then(async(e)=>{if(l=e,s)return;let r=await l.getPage(1);if(s)return;let n=r.getViewport({scale:1});t=new IntersectionObserver((a)=>{for(let i of a){let c=i.target;if(i.isIntersecting)h.add(c),_(c).catch(A);else h.delete(c),F(c)}},{root:d,rootMargin:"200% 0px"});for(let a=1;a<=l.numPages;a++){let i=document.createElement("div");i.className="alwith-preview-pdf-page",i.dataset.page=String(a),i.setAttribute("aria-label",`${R(m.current.host,"page")} ${a}`),g.set(i,{width:n.width,height:n.height}),S(i),d.append(i),t.observe(i)}P.current=()=>{for(let a of g.keys())S(a)},x(!1)}).catch((e)=>{if(A(e),!s)x(!1)}),()=>{s=!0,P.current=null,t?.disconnect();for(let e of g.keys())F(e);d.replaceChildren(),T.destroy().catch(m.current.context.onError)}},[z.bytes,p.pdfWorkerSrc]),M(()=>{P.current?.()},[k]),M(()=>{let d=E.current;if(!d)throw Error("PDF container is missing");let s=(t)=>{if(!t.ctrlKey&&!t.metaKey)return;let o=t.target;if(o&&(["INPUT","TEXTAREA","SELECT"].includes(o.tagName)||o.isContentEditable))return;if(N(f.current,t.key)===null)return;t.preventDefault(),b((h)=>N(h,t.key))},l=(t)=>{if(!t.ctrlKey&&!t.metaKey)return;if(t.preventDefault(),t.deltaY!==0)b((o)=>N(o,t.deltaY<0?"+":"-"))};return window.addEventListener("keydown",s),d.addEventListener("wheel",l,{passive:!1}),()=>{window.removeEventListener("keydown",s),d.removeEventListener("wheel",l)}},[]),I("div",{className:"alwith-preview-pdf alwith-preview-pdf-desktop",children:[v(Y,{error:V}),W&&v("div",{className:"alwith-preview-pdf-loading",role:"status","aria-label":R(p,"loading"),children:v("span",{className:"alwith-preview-spinner"})}),v("div",{className:"alwith-preview-pdf-scroll",ref:E})]})}export{G as default};
1
+ import"../chunk-czgs93zj.js";import{j,M}from"../chunk-9mb4nnsc.js";import{I}from"../chunk-s6jrc7pq.js";import{D,N}from"../chunk-0m07f1rf.js";j(import.meta.url,["ft3hwgj5","czgs93zj","9mb4nnsc","s6jrc7pq","0m07f1rf","rpk588j2","x6e3x53v","g5mn8gma","pm5mxznh","pc0wr96w","ewq910t8","b5q2ys0a","6nvrc7p7","gq1eh0tx","dr1ebnb1","qt0cfrrv","qanrx7j1","nn5x2ear","68dtjjm4","b1xr49tw","sq7vxhx3","e5hxq2gn","yhtn3t0e","7zewhyx6","83qapya5","jdjcp0ak","bh9vgt8q"],[["./pdf.js",1,2,3,4],["../chunk-czgs93zj.js"],["../chunk-9mb4nnsc.js"],["../chunk-s6jrc7pq.js"],["../chunk-0m07f1rf.js",2],["./tiff.js",11,12,13,14,15,16,17,18,19,20,1,2,4],["./html.js",1,21,2,4],["./word.js",1,2,4],["./media.js",1,2,22,4],["./markdown.js",1,2,23,4,24],["./excel.js",25,26,1,2,4],["../chunk-b5q2ys0a.js"],["../chunk-6nvrc7p7.js"],["../chunk-gq1eh0tx.js"],["../chunk-dr1ebnb1.js"],["../chunk-qt0cfrrv.js"],["../chunk-qanrx7j1.js"],["../chunk-nn5x2ear.js"],["../chunk-68dtjjm4.js",15,16,17],["../chunk-b1xr49tw.js"],["../chunk-sq7vxhx3.js",11],["../chunk-e5hxq2gn.js",1],["../chunk-yhtn3t0e.js"],["../chunk-7zewhyx6.js",2],["../chunk-83qapya5.js",2,23,4],["../chunk-jdjcp0ak.js"],["../chunk-bh9vgt8q.js"]],0);
2
+ import{getDocument as U,GlobalWorkerOptions as Y,RenderingCancelledException as Z}from"pdfjs-dist";import{useEffect as x,useRef as E,useState as H}from"react";import{jsxDEV as g}from"react/jsx-dev-runtime";function _({document:S,context:C,host:h}){let y=E(null),[V,z]=H(null),[O,P]=H(!0),[T,b]=H(1),p=E(T);p.current=T;let v=E({context:C,host:h});v.current={context:C,host:h};let L=E(null);return x(()=>{let l=y.current;if(!l)throw Error("PDF container is missing");Y.workerSrc=h.pdfWorkerSrc,z(null),P(!0),b(1),l.replaceChildren();let o=!1,d=null,t=null,s=new Map,m=new Set,w=new Set,u=new Map,f=new Map,F=U({data:new Uint8Array(S.bytes)}),R=(e)=>{if(!o&&!(e instanceof Z))z(N(e)),v.current.context.onError(e)},k=(e)=>{let r=f.get(e);if(!r)throw Error("PDF page size is missing");e.style.width=`${r.width*p.current}px`,e.style.height=`${r.height*p.current}px`,e.style.minWidth=`${Math.min(720,r.width*p.current)}px`},A=(e)=>{u.set(e,(u.get(e)??0)+1),s.get(e)?.cancel(),s.delete(e),m.delete(e);for(let r of e.querySelectorAll("canvas"))r.width=0,r.height=0,r.remove()},q=async(e)=>{if(!d||m.has(e)||e.querySelector("canvas"))return;let r=(u.get(e)??0)+1;u.set(e,r),m.add(e);let n=null;try{let a=await d.getPage(Number(e.dataset.page));if(o||!w.has(e)||u.get(e)!==r)return;let i=a.getViewport({scale:1});f.set(e,{width:i.width,height:i.height}),k(e);let c=a.getViewport({scale:2*Math.min(window.devicePixelRatio||1,2)});if(c.width*c.height>25000000)throw Error("PDF page exceeds the canvas preview limit");n=document.createElement("canvas"),n.width=Math.ceil(c.width),n.height=Math.ceil(c.height);let K=n.getContext("2d");if(!K)throw Error("PDF canvas context is unavailable");let W=a.render({canvas:n,canvasContext:K,viewport:c});if(s.set(e,W),await W.promise,!o&&w.has(e)&&u.get(e)===r)e.append(n)}finally{if(n&&!n.parentElement)n.width=0,n.height=0;if(u.get(e)===r)s.delete(e),m.delete(e)}};return F.promise.then(async(e)=>{if(d=e,o)return;let r=await d.getPage(1);if(o)return;let n=r.getViewport({scale:1});t=new IntersectionObserver((a)=>{for(let i of a){let c=i.target;if(i.isIntersecting)w.add(c),q(c).catch(R);else w.delete(c),A(c)}},{root:l,rootMargin:"200% 0px"});for(let a=1;a<=d.numPages;a++){let i=document.createElement("div");i.className="alwith-preview-pdf-page",i.dataset.page=String(a),i.setAttribute("aria-label",`${M(v.current.host,"page")} ${a}`),f.set(i,{width:n.width,height:n.height}),k(i),l.append(i),t.observe(i)}L.current=()=>{for(let a of f.keys())k(a)},P(!1)}).catch((e)=>{if(R(e),!o)P(!1)}),()=>{o=!0,L.current=null,t?.disconnect();for(let e of f.keys())A(e);l.replaceChildren(),F.destroy().catch(v.current.context.onError)}},[S.bytes,h.pdfWorkerSrc]),x(()=>{L.current?.()},[T]),x(()=>{let l=y.current;if(!l)throw Error("PDF container is missing");let o=(t)=>{if(!t.ctrlKey&&!t.metaKey)return;let s=t.target;if(s&&(["INPUT","TEXTAREA","SELECT"].includes(s.tagName)||s.isContentEditable))return;if(I(p.current,t.key)===null)return;t.preventDefault(),b((w)=>I(w,t.key))},d=(t)=>{if(!t.ctrlKey&&!t.metaKey)return;if(t.preventDefault(),t.deltaY!==0)b((s)=>I(s,t.deltaY<0?"+":"-"))};return window.addEventListener("keydown",o),l.addEventListener("wheel",d,{passive:!1}),()=>{window.removeEventListener("keydown",o),l.removeEventListener("wheel",d)}},[]),g("div",{className:"alwith-preview-pdf alwith-preview-pdf-desktop",children:[g(D,{error:V},void 0,!1,void 0,this),O&&g("div",{className:"alwith-preview-pdf-loading",role:"status","aria-label":M(h,"loading"),children:g("span",{className:"alwith-preview-spinner"},void 0,!1,void 0,this)},void 0,!1,void 0,this),g("div",{className:"alwith-preview-pdf-scroll",ref:y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}export{_ as default};
@@ -1,4 +1,4 @@
1
- import { type PreviewProps } from "./index.js";
1
+ import { type PreviewProps } from "./index";
2
2
  export declare function useObjectUrl(bytes: Uint8Array, type: string): string | null;
3
3
  export declare function ErrorMessage({ error }: {
4
4
  error: string | null;
@@ -1 +1,2 @@
1
- import{jsx as o}from"react/jsx-runtime";import{useEffect as u,useState as a}from"react";import{previewLabel as i}from"./index.js";function p(e,t){let[r,l]=a(null);return u(()=>{let n=URL.createObjectURL(new Blob([new Uint8Array(e).buffer],{type:t}));return l(n),()=>URL.revokeObjectURL(n)},[e,t]),r}function x({error:e}){return e===null?null:o("div",{className:"alwith-preview-status",role:"alert",children:e})}function m({document:e,host:t,context:r}){if(!t.openExternal)return null;return o("button",{type:"button",onClick:()=>{t.openExternal(e.path).catch(r.onError)},children:i(t,"openExternal")})}function E(e){return e instanceof Error?e.message:String(e)}export{x as ErrorMessage,m as ExternalButton,E as errorText,p as useObjectUrl};
1
+ import{C,D,k,N}from"../chunk-0m07f1rf.js";import{j}from"../chunk-9mb4nnsc.js";import"../chunk-czgs93zj.js";j(import.meta.url,["a29k789h","0m07f1rf","9mb4nnsc","czgs93zj","rpk588j2","x6e3x53v","g5mn8gma","ft3hwgj5","pm5mxznh","pc0wr96w","ewq910t8","b5q2ys0a","6nvrc7p7","gq1eh0tx","dr1ebnb1","qt0cfrrv","qanrx7j1","nn5x2ear","68dtjjm4","b1xr49tw","sq7vxhx3","e5hxq2gn","s6jrc7pq","yhtn3t0e","7zewhyx6","83qapya5","jdjcp0ak","bh9vgt8q"],[["./shared.js",1,2,3],["../chunk-0m07f1rf.js",2],["../chunk-9mb4nnsc.js"],["../chunk-czgs93zj.js"],["./tiff.js",11,12,13,14,15,16,17,18,19,20,3,2,1],["./html.js",3,21,2,1],["./word.js",3,2,1],["./pdf.js",3,2,22,1],["./media.js",3,2,23,1],["./markdown.js",3,2,24,1,25],["./excel.js",26,27,3,2,1],["../chunk-b5q2ys0a.js"],["../chunk-6nvrc7p7.js"],["../chunk-gq1eh0tx.js"],["../chunk-dr1ebnb1.js"],["../chunk-qt0cfrrv.js"],["../chunk-qanrx7j1.js"],["../chunk-nn5x2ear.js"],["../chunk-68dtjjm4.js",15,16,17],["../chunk-b1xr49tw.js"],["../chunk-sq7vxhx3.js",11],["../chunk-e5hxq2gn.js",3],["../chunk-s6jrc7pq.js"],["../chunk-yhtn3t0e.js"],["../chunk-7zewhyx6.js",2],["../chunk-83qapya5.js",2,24,1],["../chunk-jdjcp0ak.js"],["../chunk-bh9vgt8q.js"]],0);
2
+ export{D as ErrorMessage,k as ExternalButton,N as errorText,C as useObjectUrl};
@@ -1,2 +1,2 @@
1
- import { type PreviewProps } from "./index.js";
1
+ import { type PreviewProps } from "./index";
2
2
  export default function Tiff({ document, context, host }: PreviewProps): import("react").JSX.Element;
@@ -1 +1,2 @@
1
- import{jsx as c,jsxs as A}from"react/jsx-runtime";import{useEffect as U,useEffectEvent as _,useMemo as j,useState as f}from"react";import*as i from"utif";import{ImagePreview as B}from"../index.js";import{previewLabel as C}from"./index.js";import{ErrorMessage as D,errorText as w}from"./shared.js";function L({document:s,context:m,host:p}){let[h,u]=f(0),[d,y]=f(null),[x,l]=f(null),t=j(()=>{try{return{pages:i.decode(new Uint8Array(s.bytes).buffer),error:null}}catch(e){return{pages:[],error:e}}},[s.bytes]);U(()=>{u(0)},[s.bytes]);let g=_((e)=>m.onError(e));return U(()=>{let e=!1;y(null),l(null);try{if(t.error!==null)throw t.error instanceof Error?t.error:Error(w(t.error));let r=t.pages[h];if(!r)throw Error("TIFF contains no image pages");let a={...r},{t256:b,t257:v}=a,E=Array.isArray(b)?Number(b[0]):0,F=Array.isArray(v)?Number(v[0]):0;if(!E||!F||E*F>25000000)throw Error("TIFF image dimensions exceed the preview limit");i.decodeImage(new Uint8Array(s.bytes).buffer,a);let N=i.toRGBA8(a),n=window.document.createElement("canvas");n.width=a.width,n.height=a.height;let I=n.getContext("2d");if(!I)throw Error("TIFF canvas context is unavailable");I.putImageData(new ImageData(new Uint8ClampedArray(N),a.width,a.height),0,0),n.toBlob((T)=>{if(n.width=0,n.height=0,!T){if(!e){let o=Error("Unable to encode TIFF preview");l(o.message),g(o)}return}T.arrayBuffer().then((o)=>{if(!e)y(new Uint8Array(o))}).catch((o)=>{if(!e)l(w(o)),g(o)})},"image/png")}catch(r){l(w(r)),g(r)}return()=>{e=!0}},[s.bytes,t,h]),A("div",{className:"alwith-preview-excel",children:[c(D,{error:x}),t.pages.length>1&&A("label",{className:"alwith-preview-sheets",children:[C(p,"page"),c("select",{value:h,onChange:(e)=>u(Number(e.target.value)),children:t.pages.map((e,r)=>c("option",{value:r,children:r+1},r))})]}),d&&c(B,{document:{...s,bytes:d},labels:p.imageLabels,onError:m.onError})]})}export{L as default};
1
+ import"../chunk-b5q2ys0a.js";import"../chunk-6nvrc7p7.js";import"../chunk-gq1eh0tx.js";import"../chunk-dr1ebnb1.js";import"../chunk-qt0cfrrv.js";import"../chunk-qanrx7j1.js";import"../chunk-nn5x2ear.js";import"../chunk-68dtjjm4.js";import"../chunk-b1xr49tw.js";import{A}from"../chunk-sq7vxhx3.js";import"../chunk-czgs93zj.js";import{j,M}from"../chunk-9mb4nnsc.js";import{D,N}from"../chunk-0m07f1rf.js";j(import.meta.url,["rpk588j2","b5q2ys0a","6nvrc7p7","gq1eh0tx","dr1ebnb1","qt0cfrrv","qanrx7j1","nn5x2ear","68dtjjm4","b1xr49tw","sq7vxhx3","czgs93zj","9mb4nnsc","0m07f1rf","x6e3x53v","g5mn8gma","ft3hwgj5","pm5mxznh","pc0wr96w","ewq910t8","e5hxq2gn","s6jrc7pq","yhtn3t0e","7zewhyx6","83qapya5","jdjcp0ak","bh9vgt8q"],[["./tiff.js",1,2,3,4,5,6,7,8,9,10,11,12,13],["../chunk-b5q2ys0a.js"],["../chunk-6nvrc7p7.js"],["../chunk-gq1eh0tx.js"],["../chunk-dr1ebnb1.js"],["../chunk-qt0cfrrv.js"],["../chunk-qanrx7j1.js"],["../chunk-nn5x2ear.js"],["../chunk-68dtjjm4.js",5,6,7],["../chunk-b1xr49tw.js"],["../chunk-sq7vxhx3.js",1],["../chunk-czgs93zj.js"],["../chunk-9mb4nnsc.js"],["../chunk-0m07f1rf.js",12],["./html.js",11,20,12,13],["./word.js",11,12,13],["./pdf.js",11,12,21,13],["./media.js",11,12,22,13],["./markdown.js",11,12,23,13,24],["./excel.js",25,26,11,12,13],["../chunk-e5hxq2gn.js",11],["../chunk-s6jrc7pq.js"],["../chunk-yhtn3t0e.js"],["../chunk-7zewhyx6.js",12],["../chunk-83qapya5.js",12,23,13],["../chunk-jdjcp0ak.js"],["../chunk-bh9vgt8q.js"]],0);
2
+ import{useEffect as T,useEffectEvent as B,useMemo as k,useState as h}from"react";import*as l from"utif";import{jsxDEV as i}from"react/jsx-dev-runtime";function C({document:n,context:f,host:p}){let[g,u]=h(0),[m,y]=h(null),[U,c]=h(null),t=k(()=>{try{return{pages:l.decode(new Uint8Array(n.bytes).buffer),error:null}}catch(e){return{pages:[],error:e}}},[n.bytes]);T(()=>{u(0)},[n.bytes]);let w=B((e)=>f.onError(e));return T(()=>{let e=!1;y(null),c(null);try{if(t.error!==null)throw t.error instanceof Error?t.error:Error(N(t.error));let r=t.pages[g];if(!r)throw Error("TIFF contains no image pages");let o={...r},{t256:d,t257:b}=o,v=Array.isArray(d)?Number(d[0]):0,E=Array.isArray(b)?Number(b[0]):0;if(!v||!E||v*E>25000000)throw Error("TIFF image dimensions exceed the preview limit");l.decodeImage(new Uint8Array(n.bytes).buffer,o);let P=l.toRGBA8(o),s=window.document.createElement("canvas");s.width=o.width,s.height=o.height;let F=s.getContext("2d");if(!F)throw Error("TIFF canvas context is unavailable");F.putImageData(new ImageData(new Uint8ClampedArray(P),o.width,o.height),0,0),s.toBlob((I)=>{if(s.width=0,s.height=0,!I){if(!e){let a=Error("Unable to encode TIFF preview");c(a.message),w(a)}return}I.arrayBuffer().then((a)=>{if(!e)y(new Uint8Array(a))}).catch((a)=>{if(!e)c(N(a)),w(a)})},"image/png")}catch(r){c(N(r)),w(r)}return()=>{e=!0}},[n.bytes,t,g]),i("div",{className:"alwith-preview-excel",children:[i(D,{error:U},void 0,!1,void 0,this),t.pages.length>1&&i("label",{className:"alwith-preview-sheets",children:[M(p,"page"),i("select",{value:g,onChange:(e)=>u(Number(e.target.value)),children:t.pages.map((e,r)=>i("option",{value:r,children:r+1},r,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m&&i(A,{document:{...n,bytes:m},labels:p.imageLabels,onError:f.onError},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}export{C as default};
@@ -1,2 +1,2 @@
1
- import { type PreviewProps } from "./index.js";
1
+ import { type PreviewProps } from "./index";
2
2
  export default function Word(props: PreviewProps): import("react").JSX.Element;
@@ -1 +1,2 @@
1
- import{jsx as o,jsxs as d,Fragment as h}from"react/jsx-runtime";import{renderAsync as y}from"docx-preview";import{useEffect as x,useEffectEvent as b,useState as u}from"react";import{previewLabel as v}from"./index.js";import{ErrorMessage as w,errorText as E,ExternalButton as g}from"./shared.js";function p(e){let[i,s]=u(null),[m,a]=u(null),c=/\.(doc|dot)$/i.test(e.document.path)||[208,207,17,224,161,177,26,225].every((t,r)=>e.document.bytes[r]===t),f=b((t)=>e.context.onError(t));return x(()=>{if(c)return;let t=!1,r=window.document.createElement("div"),l=window.document.createElement("div");return a(null),s(null),y(new Uint8Array(e.document.bytes).buffer,r,l,{ignoreFonts:!0,useBase64URL:!0,renderAltChunks:!1}).then(()=>{if(t)return;for(let n of r.querySelectorAll("script,iframe,object,embed"))n.remove();for(let n of r.querySelectorAll("[href]"))n.removeAttribute("href");s(`<!doctype html><html><head><meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; form-action 'none'; base-uri 'none'">${l.innerHTML}</head><body>${r.innerHTML}</body></html>`)}).catch((n)=>{if(!t)a(E(n)),f(n)}).finally(()=>{r.replaceChildren(),l.replaceChildren()}),()=>{t=!0}},[e.document.bytes,c]),o("div",{className:"alwith-preview-html alwith-preview-word",children:c?d("div",{className:"alwith-preview-status",children:[v(e.host,"legacyWord"),o(g,{...e})]}):d(h,{children:[o(w,{error:m}),i&&o("iframe",{title:e.document.path.split("/").at(-1),sandbox:"",referrerPolicy:"no-referrer",srcDoc:i})]})})}export{p as default};
1
+ import"../chunk-czgs93zj.js";import{j,M}from"../chunk-9mb4nnsc.js";import{D,k,N}from"../chunk-0m07f1rf.js";j(import.meta.url,["g5mn8gma","czgs93zj","9mb4nnsc","0m07f1rf","rpk588j2","x6e3x53v","ft3hwgj5","pm5mxznh","pc0wr96w","ewq910t8","b5q2ys0a","6nvrc7p7","gq1eh0tx","dr1ebnb1","qt0cfrrv","qanrx7j1","nn5x2ear","68dtjjm4","b1xr49tw","sq7vxhx3","e5hxq2gn","s6jrc7pq","yhtn3t0e","7zewhyx6","83qapya5","jdjcp0ak","bh9vgt8q"],[["./word.js",1,2,3],["../chunk-czgs93zj.js"],["../chunk-9mb4nnsc.js"],["../chunk-0m07f1rf.js",2],["./tiff.js",10,11,12,13,14,15,16,17,18,19,1,2,3],["./html.js",1,20,2,3],["./pdf.js",1,2,21,3],["./media.js",1,2,22,3],["./markdown.js",1,2,23,3,24],["./excel.js",25,26,1,2,3],["../chunk-b5q2ys0a.js"],["../chunk-6nvrc7p7.js"],["../chunk-gq1eh0tx.js"],["../chunk-dr1ebnb1.js"],["../chunk-qt0cfrrv.js"],["../chunk-qanrx7j1.js"],["../chunk-nn5x2ear.js"],["../chunk-68dtjjm4.js",14,15,16],["../chunk-b1xr49tw.js"],["../chunk-sq7vxhx3.js",10],["../chunk-e5hxq2gn.js",1],["../chunk-s6jrc7pq.js"],["../chunk-yhtn3t0e.js"],["../chunk-7zewhyx6.js",2],["../chunk-83qapya5.js",2,23,3],["../chunk-jdjcp0ak.js"],["../chunk-bh9vgt8q.js"]],0);
2
+ import{renderAsync as m}from"docx-preview";import{useEffect as y,useEffectEvent as h,useState as a}from"react";import{jsxDEV as o,Fragment as w}from"react/jsx-dev-runtime";function v(e){let[c,s]=a(null),[d,u]=a(null),l=/\.(doc|dot)$/i.test(e.document.path)||[208,207,17,224,161,177,26,225].every((t,r)=>e.document.bytes[r]===t),f=h((t)=>e.context.onError(t));return y(()=>{if(l)return;let t=!1,r=window.document.createElement("div"),i=window.document.createElement("div");return u(null),s(null),m(new Uint8Array(e.document.bytes).buffer,r,i,{ignoreFonts:!0,useBase64URL:!0,renderAltChunks:!1}).then(()=>{if(t)return;for(let n of r.querySelectorAll("script,iframe,object,embed"))n.remove();for(let n of r.querySelectorAll("[href]"))n.removeAttribute("href");s(`<!doctype html><html><head><meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; form-action 'none'; base-uri 'none'">${i.innerHTML}</head><body>${r.innerHTML}</body></html>`)}).catch((n)=>{if(!t)u(N(n)),f(n)}).finally(()=>{r.replaceChildren(),i.replaceChildren()}),()=>{t=!0}},[e.document.bytes,l]),o("div",{className:"alwith-preview-html alwith-preview-word",children:l?o("div",{className:"alwith-preview-status",children:[M(e.host,"legacyWord"),o(k,{...e},void 0,!1,void 0,this)]},void 0,!0,void 0,this):o(w,{children:[o(D,{error:d},void 0,!1,void 0,this),c&&o("iframe",{title:e.document.path.split("/").at(-1),sandbox:"",referrerPolicy:"no-referrer",srcDoc:c},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}export{v as default};