@alwith/module-editor 0.0.0-stage → 0.1.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +94 -0
- package/README.md +47 -2
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/core.d.ts +56 -0
- package/dist/core.js +8 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +1 -0
- package/dist/monaco.d.ts +16 -0
- package/dist/monaco.js +1 -0
- package/dist/new-tab.d.ts +43 -0
- package/dist/new-tab.js +1 -0
- package/dist/preview-source-mode-toggle.d.ts +8 -0
- package/dist/preview-source-mode-toggle.js +1 -0
- package/dist/previews/excel-data.d.ts +20 -0
- package/dist/previews/excel-data.js +3 -0
- package/dist/previews/excel-navigation.d.ts +4 -0
- package/dist/previews/excel-navigation.js +1 -0
- package/dist/previews/excel.d.ts +3 -0
- package/dist/previews/excel.js +1 -0
- package/dist/previews/html-resources.d.ts +3 -0
- package/dist/previews/html-resources.js +2 -0
- package/dist/previews/html-session.d.ts +8 -0
- package/dist/previews/html-session.js +1 -0
- package/dist/previews/html.d.ts +3 -0
- package/dist/previews/html.js +1 -0
- package/dist/previews/index.d.ts +83 -0
- package/dist/previews/index.js +1 -0
- package/dist/previews/markdown-outline.d.ts +6 -0
- package/dist/previews/markdown-outline.js +1 -0
- package/dist/previews/markdown-readonly.d.ts +4 -0
- package/dist/previews/markdown-readonly.js +2 -0
- package/dist/previews/markdown.css +918 -0
- package/dist/previews/markdown.d.ts +5 -0
- package/dist/previews/markdown.js +1 -0
- package/dist/previews/media-types.d.ts +1 -0
- package/dist/previews/media-types.js +1 -0
- package/dist/previews/media.d.ts +2 -0
- package/dist/previews/media.js +1 -0
- package/dist/previews/pdf-controls.d.ts +1 -0
- package/dist/previews/pdf-controls.js +1 -0
- package/dist/previews/pdf.d.ts +2 -0
- package/dist/previews/pdf.js +1 -0
- package/dist/previews/shared.d.ts +7 -0
- package/dist/previews/shared.js +1 -0
- package/dist/previews/styles.css +142 -0
- package/dist/previews/tiff.d.ts +2 -0
- package/dist/previews/tiff.js +1 -0
- package/dist/previews/viewers.css +221 -0
- package/dist/previews/word.d.ts +2 -0
- package/dist/previews/word.js +1 -0
- package/dist/quick-start-assets.d.ts +4 -0
- package/dist/quick-start-assets.js +1 -0
- package/dist/quick-start-data.d.ts +11 -0
- package/dist/quick-start-data.js +1 -0
- package/dist/quick-start-icons.d.ts +9 -0
- package/dist/quick-start-icons.js +1 -0
- package/dist/shortcut-hint.d.ts +4 -0
- package/dist/shortcut-hint.js +0 -0
- package/dist/styles.css +726 -0
- package/dist/workspace-assets.d.ts +2 -0
- package/dist/workspace-assets.js +1 -0
- package/dist/workspace-tabs.d.ts +27 -0
- package/dist/workspace-tabs.js +1 -0
- package/dist/workspace.d.ts +31 -0
- package/dist/workspace.js +1 -0
- package/package.json +163 -4
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PreviewProps } from "./index.js";
|
|
2
|
+
import "katex/dist/katex.min.css";
|
|
3
|
+
import "@milkdown/prose/view/style/prosemirror.css";
|
|
4
|
+
import "@milkdown/prose/tables/style/tables.css";
|
|
5
|
+
export default function Markdown(props: PreviewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mediaMimeType(path: string): string;
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function nextPdfZoom(zoom: number, key: string): number | null;
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PreviewProps } from "./index.js";
|
|
2
|
+
export declare function useObjectUrl(bytes: Uint8Array, type: string): string | null;
|
|
3
|
+
export declare function ErrorMessage({ error }: {
|
|
4
|
+
error: string | null;
|
|
5
|
+
}): import("react").JSX.Element | null;
|
|
6
|
+
export declare function ExternalButton({ document, host, context }: PreviewProps): import("react").JSX.Element | null;
|
|
7
|
+
export declare function errorText(error: unknown): string;
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
@import "./markdown.css";
|
|
2
|
+
@import "./viewers.css";
|
|
3
|
+
|
|
4
|
+
.alwith-preview-status {
|
|
5
|
+
padding: 24px;
|
|
6
|
+
color: var(--muted-foreground);
|
|
7
|
+
}
|
|
8
|
+
.alwith-preview-document,
|
|
9
|
+
.alwith-preview-pdf-scroll {
|
|
10
|
+
height: 100%;
|
|
11
|
+
overflow: auto;
|
|
12
|
+
}
|
|
13
|
+
.alwith-preview-pdf,
|
|
14
|
+
.alwith-preview-html,
|
|
15
|
+
.alwith-preview-excel,
|
|
16
|
+
.alwith-preview-markdown {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
height: 100%;
|
|
20
|
+
min-height: 0;
|
|
21
|
+
}
|
|
22
|
+
.alwith-preview-pdf-scroll {
|
|
23
|
+
flex: 1;
|
|
24
|
+
padding: 16px;
|
|
25
|
+
background: var(--muted);
|
|
26
|
+
}
|
|
27
|
+
.alwith-preview-pdf-page {
|
|
28
|
+
display: flex;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
margin: 0 auto 16px;
|
|
31
|
+
}
|
|
32
|
+
.alwith-preview-html iframe,
|
|
33
|
+
.alwith-preview-word iframe {
|
|
34
|
+
flex: 1;
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
border: 0;
|
|
38
|
+
background: var(--background);
|
|
39
|
+
}
|
|
40
|
+
.alwith-preview-media {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
gap: 16px;
|
|
46
|
+
height: 100%;
|
|
47
|
+
padding: 16px;
|
|
48
|
+
}
|
|
49
|
+
.alwith-preview-media video {
|
|
50
|
+
max-width: 100%;
|
|
51
|
+
max-height: calc(100% - 60px);
|
|
52
|
+
}
|
|
53
|
+
.alwith-preview-media audio {
|
|
54
|
+
width: min(100%, 600px);
|
|
55
|
+
}
|
|
56
|
+
.alwith-preview-grid {
|
|
57
|
+
flex: 1;
|
|
58
|
+
overflow: auto;
|
|
59
|
+
min-height: 0;
|
|
60
|
+
font-size: 12px;
|
|
61
|
+
}
|
|
62
|
+
.alwith-preview-cell,
|
|
63
|
+
.alwith-preview-row-label,
|
|
64
|
+
.alwith-preview-column-label {
|
|
65
|
+
position: absolute;
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
padding: 4px 8px;
|
|
68
|
+
border-bottom: 1px solid var(--border);
|
|
69
|
+
border-right: 1px solid var(--border);
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
white-space: nowrap;
|
|
72
|
+
text-overflow: ellipsis;
|
|
73
|
+
}
|
|
74
|
+
.alwith-preview-row-label,
|
|
75
|
+
.alwith-preview-column-label {
|
|
76
|
+
background: var(--muted);
|
|
77
|
+
color: var(--muted-foreground);
|
|
78
|
+
text-align: center;
|
|
79
|
+
z-index: 1;
|
|
80
|
+
}
|
|
81
|
+
.alwith-preview-row-label {
|
|
82
|
+
width: 56px;
|
|
83
|
+
}
|
|
84
|
+
.alwith-preview-pdf-body {
|
|
85
|
+
display: flex;
|
|
86
|
+
flex: 1;
|
|
87
|
+
min-height: 0;
|
|
88
|
+
overflow: hidden;
|
|
89
|
+
}
|
|
90
|
+
.alwith-preview-pdf-thumbnails {
|
|
91
|
+
width: 148px;
|
|
92
|
+
flex-shrink: 0;
|
|
93
|
+
overflow: auto;
|
|
94
|
+
padding: 8px;
|
|
95
|
+
background: var(--muted);
|
|
96
|
+
border-right: 1px solid var(--border);
|
|
97
|
+
}
|
|
98
|
+
.alwith-preview-pdf-thumbnails[hidden] {
|
|
99
|
+
display: none;
|
|
100
|
+
}
|
|
101
|
+
.alwith-preview-pdf-thumbnail {
|
|
102
|
+
display: flex;
|
|
103
|
+
flex-direction: column;
|
|
104
|
+
align-items: center;
|
|
105
|
+
gap: 4px;
|
|
106
|
+
width: 100%;
|
|
107
|
+
margin-bottom: 8px;
|
|
108
|
+
padding: 6px;
|
|
109
|
+
border: 1px solid var(--border);
|
|
110
|
+
border-radius: var(--radius);
|
|
111
|
+
color: var(--muted-foreground);
|
|
112
|
+
background: var(--background);
|
|
113
|
+
cursor: pointer;
|
|
114
|
+
font-size: 12px;
|
|
115
|
+
}
|
|
116
|
+
.alwith-preview-pdf-toolbar {
|
|
117
|
+
display: flex;
|
|
118
|
+
flex-wrap: wrap;
|
|
119
|
+
align-items: center;
|
|
120
|
+
gap: 8px;
|
|
121
|
+
padding: 8px;
|
|
122
|
+
border-bottom: 1px solid var(--border);
|
|
123
|
+
}
|
|
124
|
+
.alwith-preview-pdf-toolbar button {
|
|
125
|
+
padding: 4px 8px;
|
|
126
|
+
border: 1px solid var(--border);
|
|
127
|
+
border-radius: var(--radius);
|
|
128
|
+
color: var(--foreground);
|
|
129
|
+
background: var(--background);
|
|
130
|
+
cursor: pointer;
|
|
131
|
+
}
|
|
132
|
+
.alwith-preview-pdf-toolbar input {
|
|
133
|
+
width: 64px;
|
|
134
|
+
padding: 4px;
|
|
135
|
+
border: 1px solid var(--border);
|
|
136
|
+
border-radius: var(--radius);
|
|
137
|
+
color: var(--foreground);
|
|
138
|
+
background: var(--background);
|
|
139
|
+
}
|
|
140
|
+
.alwith-preview-pdf-scroll {
|
|
141
|
+
min-width: 0;
|
|
142
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/* Desktop viewer layout, scoped to the portable preview surface. */
|
|
2
|
+
.alwith-preview-pdf-desktop {
|
|
3
|
+
position: relative;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
}
|
|
6
|
+
.alwith-preview-pdf-desktop .alwith-preview-pdf-scroll {
|
|
7
|
+
position: relative;
|
|
8
|
+
min-height: 0;
|
|
9
|
+
padding: 16px 12px;
|
|
10
|
+
background: white;
|
|
11
|
+
}
|
|
12
|
+
.alwith-preview-pdf-desktop .alwith-preview-pdf-page {
|
|
13
|
+
display: block;
|
|
14
|
+
margin: 8px auto;
|
|
15
|
+
background: white;
|
|
16
|
+
}
|
|
17
|
+
.alwith-preview-pdf-desktop .alwith-preview-pdf-page canvas {
|
|
18
|
+
display: block;
|
|
19
|
+
width: 100%;
|
|
20
|
+
height: 100%;
|
|
21
|
+
}
|
|
22
|
+
.alwith-preview-pdf-loading {
|
|
23
|
+
position: absolute;
|
|
24
|
+
inset: 0;
|
|
25
|
+
z-index: 10;
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
background: color-mix(in srgb, var(--background) 80%, transparent);
|
|
30
|
+
}
|
|
31
|
+
.alwith-preview-spinner {
|
|
32
|
+
display: inline-block;
|
|
33
|
+
width: 24px;
|
|
34
|
+
height: 24px;
|
|
35
|
+
border: 2px solid var(--muted-foreground);
|
|
36
|
+
border-right-color: transparent;
|
|
37
|
+
border-radius: 50%;
|
|
38
|
+
animation: alwith-preview-spin 1s linear infinite;
|
|
39
|
+
}
|
|
40
|
+
@keyframes alwith-preview-spin {
|
|
41
|
+
to {
|
|
42
|
+
transform: rotate(360deg);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
.alwith-preview-media-desktop {
|
|
46
|
+
height: 100%;
|
|
47
|
+
width: 100%;
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
box-sizing: border-box;
|
|
52
|
+
}
|
|
53
|
+
.alwith-preview-audio {
|
|
54
|
+
padding: 32px;
|
|
55
|
+
}
|
|
56
|
+
.alwith-preview-audio .alwith-preview-media-content {
|
|
57
|
+
display: flex;
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
align-items: center;
|
|
60
|
+
gap: 16px;
|
|
61
|
+
width: 100%;
|
|
62
|
+
max-width: 576px;
|
|
63
|
+
}
|
|
64
|
+
.alwith-preview-audio-spectrum {
|
|
65
|
+
height: 140px;
|
|
66
|
+
width: 100%;
|
|
67
|
+
overflow: hidden;
|
|
68
|
+
border-radius: var(--radius);
|
|
69
|
+
}
|
|
70
|
+
.alwith-preview-audio audio {
|
|
71
|
+
width: 100%;
|
|
72
|
+
}
|
|
73
|
+
.alwith-preview-video {
|
|
74
|
+
padding: 12px;
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
}
|
|
77
|
+
.alwith-preview-video .alwith-preview-media-content {
|
|
78
|
+
height: 100%;
|
|
79
|
+
width: 100%;
|
|
80
|
+
max-width: 100%;
|
|
81
|
+
}
|
|
82
|
+
.alwith-preview-excel .x-spreadsheet-container {
|
|
83
|
+
flex: 1;
|
|
84
|
+
min-height: 0;
|
|
85
|
+
min-width: 0;
|
|
86
|
+
width: 100%;
|
|
87
|
+
overflow: hidden;
|
|
88
|
+
}
|
|
89
|
+
.excel-preview-wrapper {
|
|
90
|
+
overflow: hidden;
|
|
91
|
+
}
|
|
92
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar {
|
|
93
|
+
position: relative;
|
|
94
|
+
padding: 0 56px 0 0;
|
|
95
|
+
overflow: visible;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu {
|
|
99
|
+
display: flex;
|
|
100
|
+
flex-wrap: nowrap;
|
|
101
|
+
min-width: 0;
|
|
102
|
+
width: 100%;
|
|
103
|
+
position: relative;
|
|
104
|
+
overflow-x: auto;
|
|
105
|
+
overflow-y: hidden;
|
|
106
|
+
scrollbar-width: none;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu::-webkit-scrollbar {
|
|
110
|
+
display: none;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu > li {
|
|
114
|
+
float: none;
|
|
115
|
+
flex: 0 0 auto;
|
|
116
|
+
width: 200px;
|
|
117
|
+
min-width: 200px;
|
|
118
|
+
max-width: 200px;
|
|
119
|
+
box-sizing: border-box;
|
|
120
|
+
overflow: hidden;
|
|
121
|
+
text-align: center;
|
|
122
|
+
text-overflow: ellipsis;
|
|
123
|
+
white-space: nowrap;
|
|
124
|
+
display: block;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu > li > span {
|
|
128
|
+
display: block;
|
|
129
|
+
overflow: hidden;
|
|
130
|
+
text-overflow: ellipsis;
|
|
131
|
+
white-space: nowrap;
|
|
132
|
+
max-width: 100%;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu > li > * {
|
|
136
|
+
max-width: 100%;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu > li:first-child {
|
|
140
|
+
position: sticky;
|
|
141
|
+
left: 0;
|
|
142
|
+
bottom: 0;
|
|
143
|
+
z-index: 3;
|
|
144
|
+
display: none;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu > li:first-child > span {
|
|
148
|
+
width: 35px;
|
|
149
|
+
display: block;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu > li:first-child > .x-spreadsheet-icon {
|
|
153
|
+
display: none;
|
|
154
|
+
pointer-events: none;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .x-spreadsheet-menu > li:first-child .x-spreadsheet-dropdown-content {
|
|
158
|
+
width: max-content;
|
|
159
|
+
min-width: 260px;
|
|
160
|
+
max-width: min(70vw, 640px);
|
|
161
|
+
max-height: min(60vh, 520px);
|
|
162
|
+
overflow: hidden auto;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.excel-preview-wrapper
|
|
166
|
+
.x-spreadsheet-bottombar
|
|
167
|
+
.x-spreadsheet-menu
|
|
168
|
+
> li:first-child
|
|
169
|
+
.x-spreadsheet-dropdown-content
|
|
170
|
+
.x-spreadsheet-item {
|
|
171
|
+
white-space: nowrap;
|
|
172
|
+
min-width: 100%;
|
|
173
|
+
padding-right: 16px;
|
|
174
|
+
box-sizing: border-box;
|
|
175
|
+
display: block;
|
|
176
|
+
overflow: hidden;
|
|
177
|
+
text-overflow: ellipsis;
|
|
178
|
+
width: 100%;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar.excel-bottom-nav-enabled {
|
|
182
|
+
padding-right: 80px;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .excel-sheet-nav-button {
|
|
186
|
+
position: absolute;
|
|
187
|
+
top: 50%;
|
|
188
|
+
transform: translateY(-50%);
|
|
189
|
+
width: 26px;
|
|
190
|
+
height: 26px;
|
|
191
|
+
border: 1px solid var(--border);
|
|
192
|
+
border-radius: 4px;
|
|
193
|
+
background: var(--background);
|
|
194
|
+
color: var(--foreground);
|
|
195
|
+
line-height: 1;
|
|
196
|
+
font-size: 20px;
|
|
197
|
+
font-weight: 600;
|
|
198
|
+
display: inline-flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
justify-content: center;
|
|
201
|
+
padding: 0;
|
|
202
|
+
z-index: 4;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .excel-sheet-nav-button:disabled {
|
|
206
|
+
opacity: 0.4;
|
|
207
|
+
cursor: not-allowed;
|
|
208
|
+
pointer-events: none;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .excel-sheet-nav-button-left {
|
|
212
|
+
right: 32px;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .excel-sheet-nav-button-right {
|
|
216
|
+
right: 8px;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.excel-preview-wrapper .x-spreadsheet-bottombar .excel-sheet-nav-button[hidden] {
|
|
220
|
+
display: none;
|
|
221
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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};
|