@nice2dev/ui-bi 1.1.6 → 1.1.9
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/CHANGELOG.md +101 -0
- package/README.md +13 -53
- package/dist/{NiceDocumentViewer-B-uEPZAf-CEkT03Kq.js → NiceDocumentViewer-BtpiyHdE-B0Wjc_z7.js} +110 -110
- package/dist/{NiceDocumentViewer-B-uEPZAf-zKq6VI8X.cjs → NiceDocumentViewer-BtpiyHdE-CpHKE6c1.cjs} +16 -16
- package/dist/{index-C5HkRuCY.js → index-BbAnSU3F.js} +55519 -40884
- package/dist/index-CiIML9tH.cjs +6676 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types.d.ts +0 -21
- package/dist/ui-bi.css +1 -1
- package/package.json +3 -3
- package/dist/NiceDashboardStudio.d.ts +0 -8
- package/dist/NiceDocumentViewer-B-uEPZAf-CmZ792mF.js +0 -674
- package/dist/NiceDocumentViewer-B-uEPZAf-Deg24KCP.cjs +0 -180
- package/dist/NiceReportBuilder.d.ts +0 -8
- package/dist/index-5FyuIZGq.cjs +0 -6671
- package/dist/index-BLSxTE3T.cjs +0 -6671
- package/dist/index-Ct0VIHvK.js +0 -94147
- package/dist/style.css +0 -1
- package/dist/viewAdapters.d.ts +0 -5
package/dist/{NiceDocumentViewer-B-uEPZAf-zKq6VI8X.cjs → NiceDocumentViewer-BtpiyHdE-CpHKE6c1.cjs}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("./index-BLSxTE3T.cjs"),o=require("react");function ve(r,i){var c;const t=((c=r.split(".").pop())==null?void 0:c.toLowerCase().split("?")[0])??"";return t==="pdf"?"pdf":["jpg","jpeg","png","gif","bmp","webp","svg","ico","tiff","tif"].includes(t)?"image":["mp4","webm","ogg","mov","avi","mkv"].includes(t)?"video":["mp3","wav","flac","aac","m4a","ogg"].includes(t)?"audio":["doc","docx","xls","xlsx","ppt","pptx","odt","ods","odp"].includes(t)?"office":t==="html"||t==="htm"?"html":["txt","log","md","json","xml","csv","yaml","yml"].includes(t)?"text":"unknown"}function he(r){if(r===0)return"0 B";const i=1024,t=["B","KB","MB","GB"],c=Math.floor(Math.log(r)/Math.log(i));return parseFloat((r/Math.pow(i,c)).toFixed(1))+" "+t[c]}function we(r){const i=Math.floor(r/3600),t=Math.floor(r%3600/60),c=Math.floor(r%60);return i>0?`${i}:${t.toString().padStart(2,"0")}:${c.toString().padStart(2,"0")}`:`${t}:${c.toString().padStart(2,"0")}`}function xe({src:r,page:i,zoom:t,rotation:c,onPageChange:u,onLoad:l,onError:p,workerUrl:m}){const f=o.useRef(null),k=o.useRef(null),[x,q]=o.useState(0),[A,K]=o.useState(!1);return o.useEffect(()=>{let g=!1;return(async()=>{try{let d;if(d=window.pdfjsLib,!d)try{d=await new Function("m","return import(m)")("pdfjs-dist")}catch{throw new Error('PDF.js library not found. Please install pdfjs-dist or include it via CDN: <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"><\/script>')}m?d.GlobalWorkerOptions.workerSrc=m:d.version&&(d.GlobalWorkerOptions.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${d.version}/pdf.worker.min.js`);const w=await d.getDocument(r).promise;if(g)return;k.current=w,q(w.numPages),l({name:r.split("/").pop()??"document.pdf",type:"pdf",mimeType:"application/pdf",pageCount:w.numPages})}catch(d){g||p(d instanceof Error?d:new Error("Failed to load PDF"))}})(),()=>{g=!0}},[r,m,l,p]),o.useEffect(()=>{const g=k.current,d=f.current;if(!g||!d||x===0)return;let w=!1;return(async()=>{if(!A){K(!0);try{const z=Math.max(1,Math.min(i,x)),L=await g.getPage(z);if(w)return;const b=L.getViewport({scale:t,rotation:c}),C=d.getContext("2d");if(!C)return;d.height=b.height,d.width=b.width,await L.render({canvasContext:C,viewport:b}).promise}catch(z){console.error("Error rendering PDF page:",z)}finally{w||K(!1)}}})(),()=>{w=!0}},[i,t,c,x,A]),e.jsx("div",{className:"nice-document-viewer__pdf",children:e.jsx("canvas",{ref:f,className:"nice-document-viewer__pdf-canvas"})})}function ge({src:r,zoom:i,rotation:t,onLoad:c,onError:u}){const[l,p]=o.useState(!1),m=o.useCallback(k=>{const x=k.currentTarget;p(!0),c({name:r.split("/").pop()??"image",type:"image",width:x.naturalWidth,height:x.naturalHeight})},[r,c]),f=o.useCallback(()=>{u(new Error("Failed to load image"))},[u]);return e.jsx("div",{className:"nice-document-viewer__image",children:e.jsx("img",{src:r,alt:"Document",onLoad:m,onError:f,style:{transform:`scale(${i}) rotate(${t}deg)`,opacity:l?1:0},draggable:!1})})}function be({src:r,type:i,onLoad:t,onError:c}){const u=o.useRef(null),l=o.useCallback(()=>{const m=u.current;if(!m)return;const f={name:r.split("/").pop()??(i==="video"?"video":"audio"),type:i,duration:m.duration};i==="video"&&"videoWidth"in m&&(f.width=m.videoWidth,f.height=m.videoHeight),t(f)},[r,i,t]),p=o.useCallback(()=>{c(new Error(`Failed to load ${i}`))},[i,c]);return i==="video"?e.jsx("div",{className:"nice-document-viewer__video",children:e.jsx("video",{ref:u,src:r,controls:!0,onLoadedMetadata:l,onError:p})}):e.jsx("div",{className:"nice-document-viewer__audio",children:e.jsx("audio",{ref:u,src:r,controls:!0,onLoadedMetadata:l,onError:p})})}function _e({src:r,viewerUrl:i,onLoad:t}){const[c,u]=o.useState(!1),l=`${i??"https://view.officeapps.live.com/op/embed.aspx?src="}${encodeURIComponent(r)}`,p=o.useCallback(()=>{u(!0),t({name:r.split("/").pop()??"document",type:"office"})},[r,t]);return e.jsx("div",{className:"nice-document-viewer__office",children:e.jsx("iframe",{src:l,onLoad:p,title:"Office Document",style:{opacity:c?1:0}})})}function je({src:r,onLoad:i,onError:t}){const[c,u]=o.useState(null);return o.useEffect(()=>{fetch(r).then(l=>{if(!l.ok)throw new Error("Failed to fetch text");return l.text()}).then(l=>{u(l),i({name:r.split("/").pop()??"text",type:"text",size:l.length})}).catch(l=>{t(l instanceof Error?l:new Error("Failed to load text"))})},[r,i,t]),c===null?e.jsx("div",{className:"nice-document-viewer__loading",children:"Loading..."}):e.jsx("div",{className:"nice-document-viewer__text",children:e.jsx("pre",{children:c})})}function ye({src:r,onLoad:i}){const t=o.useCallback(()=>{i({name:r.split("/").pop()??"page.html",type:"html"})},[r,i]);return e.jsx("div",{className:"nice-document-viewer__html",children:e.jsx("iframe",{src:r,onLoad:t,title:"HTML Document",sandbox:"allow-same-origin allow-scripts"})})}const ke=o.forwardRef(function(r,i){const{src:t,type:c,name:u,height:l=600,width:p="100%",zoom:m=1,minZoom:f=.25,maxZoom:k=4,page:x=1,showToolbar:q=!0,showPageNav:A=!0,showZoomControls:K=!0,showFullscreen:g=!0,showDownload:d=!0,showPrint:w=!0,showRotate:z=!0,enableKeyboard:L=!0,onLoad:b,onError:C,onPageChange:Z,onZoomChange:U,pdfWorkerUrl:ee,officeViewerUrl:te,loading:ne,errorContent:G,className:oe,"data-testid":re}=r,O=o.useRef(null),[n,ie]=o.useState(null),[_,ae]=o.useState(x),[E,ce]=o.useState(m),[J,se]=o.useState(0),[B,Y]=o.useState(!1),[I,le]=o.useState(null),[de,Q]=o.useState(!0),j=o.useMemo(()=>c??ve(t),[t,c]),N=o.useCallback(a=>{ie(a),Q(!1),b==null||b(a)},[b]),T=o.useCallback(a=>{le(a),Q(!1),C==null||C(a)},[C]),v=o.useCallback(a=>{const s=(n==null?void 0:n.pageCount)??1,R=Math.max(1,Math.min(a,s));ae(R),Z==null||Z(R)},[n==null?void 0:n.pageCount,Z]),P=o.useCallback(()=>v(_+1),[_,v]),S=o.useCallback(()=>v(_-1),[_,v]),y=o.useCallback(a=>{const s=Math.max(f,Math.min(a,k));ce(s),U==null||U(s)},[f,k,U]),M=o.useCallback(()=>y(E*1.25),[E,y]),D=o.useCallback(()=>y(E/1.25),[E,y]),F=o.useCallback(()=>y(1),[y]),W=o.useCallback(a=>{se(s=>(s+a)%360)},[]),H=o.useCallback(()=>{const a=document.createElement("a");a.href=t,a.download=u??(n==null?void 0:n.name)??"document",document.body.appendChild(a),a.click(),document.body.removeChild(a)},[t,u,n==null?void 0:n.name]),V=o.useCallback(()=>{const a=window.open(t,"_blank");a&&(a.onload=()=>a.print())},[t]),$=o.useCallback(()=>{var a,s,R;O.current&&(B?((a=document.exitFullscreen)==null||a.call(document),Y(!1)):((R=(s=O.current).requestFullscreen)==null||R.call(s),Y(!0)))},[B]);o.useEffect(()=>{if(!L)return;const a=s=>{switch(s.key){case"ArrowRight":case"PageDown":P();break;case"ArrowLeft":case"PageUp":S();break;case"Home":v(1);break;case"End":v((n==null?void 0:n.pageCount)??1);break;case"+":case"=":(s.ctrlKey||s.metaKey)&&(s.preventDefault(),M());break;case"-":(s.ctrlKey||s.metaKey)&&(s.preventDefault(),D());break;case"0":(s.ctrlKey||s.metaKey)&&(s.preventDefault(),F());break;case"f":(s.ctrlKey||s.metaKey)&&(s.preventDefault(),$());break}};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[L,P,S,v,n==null?void 0:n.pageCount,M,D,F,$]),o.useImperativeHandle(i,()=>({goToPage:v,nextPage:P,prevPage:S,setZoom:y,zoomIn:M,zoomOut:D,resetZoom:F,rotate:W,download:H,print:V,toggleFullscreen:$,getInfo:()=>n}),[v,P,S,y,M,D,F,W,H,V,$,n]);const ue=()=>{if(I)return(typeof G=="function"?G(I):G)??e.jsx("div",{className:"nice-document-viewer__error",children:e.jsxs("span",{children:[e.jsx(h.Ae,{name:"warning",size:14})," ",I.message]})});switch(j){case"pdf":return e.jsx(xe,{src:t,page:_,zoom:E,rotation:J,onPageChange:v,onLoad:N,onError:T,workerUrl:ee});case"image":return e.jsx(ge,{src:t,zoom:E,rotation:J,onLoad:N,onError:T});case"video":case"audio":return e.jsx(be,{src:t,type:j,onLoad:N,onError:T});case"office":return e.jsx(_e,{src:t,viewerUrl:te,onLoad:N});case"text":return e.jsx(je,{src:t,onLoad:N,onError:T});case"html":return e.jsx(ye,{src:t,onLoad:N});default:return e.jsxs("div",{className:"nice-document-viewer__unknown",children:[e.jsxs("span",{children:[e.jsx(h.Ae,{name:"file",size:14})," Unknown document type"]}),e.jsx("button",{type:"button",onClick:H,children:"Download"})]})}},me=A&&j==="pdf"&&((n==null?void 0:n.pageCount)??0)>1,pe=K&&(j==="pdf"||j==="image"),fe=z&&(j==="pdf"||j==="image");return e.jsxs("div",{ref:O,className:`nice-document-viewer ${B?"nice-document-viewer--fullscreen":""} ${oe??""}`,style:{height:l,width:p},"data-testid":re,"data-type":j,children:[q&&e.jsxs("div",{className:"nice-document-viewer__toolbar",children:[e.jsx("div",{className:"nice-document-viewer__toolbar-left",children:me&&e.jsxs("div",{className:"nice-document-viewer__pagination",children:[e.jsx("button",{type:"button",onClick:S,disabled:_<=1,"aria-label":"Previous page",children:e.jsx(h.Ae,{name:"chevron-left",size:16})}),e.jsxs("span",{children:[e.jsx("input",{type:"number",value:_,onChange:a=>v(parseInt(a.target.value,10)),min:1,max:(n==null?void 0:n.pageCount)??1}),"/ ",(n==null?void 0:n.pageCount)??1]}),e.jsx("button",{type:"button",onClick:P,disabled:_>=((n==null?void 0:n.pageCount)??1),"aria-label":"Next page",children:e.jsx(h.Ae,{name:"chevron-right",size:16})})]})}),e.jsxs("div",{className:"nice-document-viewer__toolbar-center",children:[pe&&e.jsxs("div",{className:"nice-document-viewer__zoom",children:[e.jsx("button",{type:"button",onClick:D,"aria-label":"Zoom out",children:"−"}),e.jsxs("span",{children:[Math.round(E*100),"%"]}),e.jsx("button",{type:"button",onClick:M,"aria-label":"Zoom in",children:"+"}),e.jsx("button",{type:"button",onClick:F,"aria-label":"Reset zoom",children:e.jsx(h.Ae,{name:"refresh",size:16})})]}),fe&&e.jsxs("div",{className:"nice-document-viewer__rotation",children:[e.jsx("button",{type:"button",onClick:()=>W(270),"aria-label":"Rotate left",children:e.jsx(h.Ae,{name:"refresh",size:16})}),e.jsx("button",{type:"button",onClick:()=>W(90),"aria-label":"Rotate right",children:e.jsx(h.Ae,{name:"refresh",size:16})})]})]}),e.jsxs("div",{className:"nice-document-viewer__toolbar-right",children:[d&&e.jsx("button",{type:"button",onClick:H,"aria-label":"Download",children:e.jsx(h.Ae,{name:"download",size:16})}),w&&e.jsx("button",{type:"button",onClick:V,"aria-label":"Print",children:e.jsx(h.Ae,{name:"printer",size:16})}),g&&e.jsx("button",{type:"button",onClick:$,"aria-label":"Fullscreen",children:e.jsx(h.Ae,{name:B?"collapse":"expand",size:16})})]})]}),e.jsxs("div",{className:"nice-document-viewer__content",children:[de&&!I&&(ne??e.jsx("div",{className:"nice-document-viewer__loading",children:"Loading..."})),ue()]}),n&&e.jsxs("div",{className:"nice-document-viewer__info",children:[e.jsx("span",{className:"nice-document-viewer__name",children:u??n.name}),n.size&&e.jsx("span",{className:"nice-document-viewer__size",children:he(n.size)}),n.width&&n.height&&e.jsxs("span",{className:"nice-document-viewer__dimensions",children:[n.width," × ",n.height]}),n.duration&&e.jsx("span",{className:"nice-document-viewer__duration",children:we(n.duration)})]})]})}),X="nice-document-viewer-styles";if(typeof document<"u"&&!document.getElementById(X)){const r=document.createElement("style");r.id=X,r.textContent=`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("./index-CiIML9tH.cjs"),r=require("react");function ve(o,i){var c;const t=((c=o.split(".").pop())==null?void 0:c.toLowerCase().split("?")[0])??"";return t==="pdf"?"pdf":["jpg","jpeg","png","gif","bmp","webp","svg","ico","tiff","tif"].includes(t)?"image":["mp4","webm","ogg","mov","avi","mkv"].includes(t)?"video":["mp3","wav","flac","aac","m4a","ogg"].includes(t)?"audio":["doc","docx","xls","xlsx","ppt","pptx","odt","ods","odp"].includes(t)?"office":t==="html"||t==="htm"?"html":["txt","log","md","json","xml","csv","yaml","yml"].includes(t)?"text":"unknown"}function he(o){if(o===0)return"0 B";const i=1024,t=["B","KB","MB","GB"],c=Math.floor(Math.log(o)/Math.log(i));return parseFloat((o/Math.pow(i,c)).toFixed(1))+" "+t[c]}function xe(o){const i=Math.floor(o/3600),t=Math.floor(o%3600/60),c=Math.floor(o%60);return i>0?`${i}:${t.toString().padStart(2,"0")}:${c.toString().padStart(2,"0")}`:`${t}:${c.toString().padStart(2,"0")}`}function we({src:o,page:i,zoom:t,rotation:c,onPageChange:u,onLoad:l,onError:p,workerUrl:m}){const f=r.useRef(null),k=r.useRef(null),[w,O]=r.useState(0),[K,Z]=r.useState(!1);return r.useEffect(()=>{let g=!1;return(async()=>{try{let d;if(d=window.pdfjsLib,!d)try{d=await new Function("m","return import(m)")("pdfjs-dist")}catch{throw new Error('PDF.js library not found. Please install pdfjs-dist or include it via CDN: <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"><\/script>')}m?d.GlobalWorkerOptions.workerSrc=m:d.version&&(d.GlobalWorkerOptions.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${d.version}/pdf.worker.min.js`);const x=await d.getDocument(o).promise;if(g)return;k.current=x,O(x.numPages),l({name:o.split("/").pop()??"document.pdf",type:"pdf",mimeType:"application/pdf",pageCount:x.numPages})}catch(d){g||p(d instanceof Error?d:new Error("Failed to load PDF"))}})(),()=>{g=!0}},[o,m,l,p]),r.useEffect(()=>{const g=k.current,d=f.current;if(!g||!d||w===0)return;let x=!1;return(async()=>{if(!K){Z(!0);try{const z=Math.max(1,Math.min(i,w)),L=await g.getPage(z);if(x)return;const b=L.getViewport({scale:t,rotation:c}),C=d.getContext("2d");if(!C)return;d.height=b.height,d.width=b.width,await L.render({canvasContext:C,viewport:b}).promise}catch(z){console.error("Error rendering PDF page:",z)}finally{x||Z(!1)}}})(),()=>{x=!0}},[i,t,c,w,K]),e.jsx("div",{className:"nice-document-viewer__pdf",children:e.jsx("canvas",{ref:f,className:"nice-document-viewer__pdf-canvas"})})}function ge({src:o,zoom:i,rotation:t,onLoad:c,onError:u}){const[l,p]=r.useState(!1),m=r.useCallback(k=>{const w=k.currentTarget;p(!0),c({name:o.split("/").pop()??"image",type:"image",width:w.naturalWidth,height:w.naturalHeight})},[o,c]),f=r.useCallback(()=>{u(new Error("Failed to load image"))},[u]);return e.jsx("div",{className:"nice-document-viewer__image",children:e.jsx("img",{src:o,alt:"Document",onLoad:m,onError:f,style:{transform:`scale(${i}) rotate(${t}deg)`,opacity:l?1:0},draggable:!1})})}function be({src:o,type:i,onLoad:t,onError:c}){const u=r.useRef(null),l=r.useCallback(()=>{const m=u.current;if(!m)return;const f={name:o.split("/").pop()??(i==="video"?"video":"audio"),type:i,duration:m.duration};i==="video"&&"videoWidth"in m&&(f.width=m.videoWidth,f.height=m.videoHeight),t(f)},[o,i,t]),p=r.useCallback(()=>{c(new Error(`Failed to load ${i}`))},[i,c]);return i==="video"?e.jsx("div",{className:"nice-document-viewer__video",children:e.jsx("video",{ref:u,src:o,controls:!0,onLoadedMetadata:l,onError:p})}):e.jsx("div",{className:"nice-document-viewer__audio",children:e.jsx("audio",{ref:u,src:o,controls:!0,onLoadedMetadata:l,onError:p})})}function _e({src:o,viewerUrl:i,onLoad:t}){const[c,u]=r.useState(!1),l=`${i??"https://view.officeapps.live.com/op/embed.aspx?src="}${encodeURIComponent(o)}`,p=r.useCallback(()=>{u(!0),t({name:o.split("/").pop()??"document",type:"office"})},[o,t]);return e.jsx("div",{className:"nice-document-viewer__office",children:e.jsx("iframe",{src:l,onLoad:p,title:"Office Document",style:{opacity:c?1:0}})})}function je({src:o,onLoad:i,onError:t}){const[c,u]=r.useState(null);return r.useEffect(()=>{fetch(o).then(l=>{if(!l.ok)throw new Error("Failed to fetch text");return l.text()}).then(l=>{u(l),i({name:o.split("/").pop()??"text",type:"text",size:l.length})}).catch(l=>{t(l instanceof Error?l:new Error("Failed to load text"))})},[o,i,t]),c===null?e.jsx("div",{className:"nice-document-viewer__loading",children:"Loading..."}):e.jsx("div",{className:"nice-document-viewer__text",children:e.jsx("pre",{children:c})})}function ye({src:o,onLoad:i}){const t=r.useCallback(()=>{i({name:o.split("/").pop()??"page.html",type:"html"})},[o,i]);return e.jsx("div",{className:"nice-document-viewer__html",children:e.jsx("iframe",{src:o,onLoad:t,title:"HTML Document",sandbox:"allow-same-origin allow-scripts"})})}const ke=r.forwardRef(function(o,i){const{src:t,type:c,name:u,height:l=600,width:p="100%",zoom:m=1,minZoom:f=.25,maxZoom:k=4,page:w=1,showToolbar:O=!0,showPageNav:K=!0,showZoomControls:Z=!0,showFullscreen:g=!0,showDownload:d=!0,showPrint:x=!0,showRotate:z=!0,enableKeyboard:L=!0,onLoad:b,onError:C,onPageChange:U,onZoomChange:B,pdfWorkerUrl:ee,officeViewerUrl:te,loading:ne,errorContent:A,className:re,"data-testid":oe}=o,G=r.useRef(null),[n,ie]=r.useState(null),[_,ae]=r.useState(w),[E,ce]=r.useState(m),[J,se]=r.useState(0),[I,Y]=r.useState(!1),[T,le]=r.useState(null),[de,Q]=r.useState(!0),j=r.useMemo(()=>c??ve(t),[t,c]),N=r.useCallback(a=>{ie(a),Q(!1),b==null||b(a)},[b]),W=r.useCallback(a=>{le(a),Q(!1),C==null||C(a)},[C]),v=r.useCallback(a=>{const s=(n==null?void 0:n.pageCount)??1,R=Math.max(1,Math.min(a,s));ae(R),U==null||U(R)},[n==null?void 0:n.pageCount,U]),S=r.useCallback(()=>v(_+1),[_,v]),P=r.useCallback(()=>v(_-1),[_,v]),y=r.useCallback(a=>{const s=Math.max(f,Math.min(a,k));ce(s),B==null||B(s)},[f,k,B]),M=r.useCallback(()=>y(E*1.25),[E,y]),D=r.useCallback(()=>y(E/1.25),[E,y]),F=r.useCallback(()=>y(1),[y]),H=r.useCallback(a=>{se(s=>(s+a)%360)},[]),q=r.useCallback(()=>{const a=document.createElement("a");a.href=t,a.download=u??(n==null?void 0:n.name)??"document",document.body.appendChild(a),a.click(),document.body.removeChild(a)},[t,u,n==null?void 0:n.name]),V=r.useCallback(()=>{const a=window.open(t,"_blank");a&&(a.onload=()=>a.print())},[t]),$=r.useCallback(()=>{var a,s,R;G.current&&(I?((a=document.exitFullscreen)==null||a.call(document),Y(!1)):((R=(s=G.current).requestFullscreen)==null||R.call(s),Y(!0)))},[I]);r.useEffect(()=>{if(!L)return;const a=s=>{switch(s.key){case"ArrowRight":case"PageDown":S();break;case"ArrowLeft":case"PageUp":P();break;case"Home":v(1);break;case"End":v((n==null?void 0:n.pageCount)??1);break;case"+":case"=":(s.ctrlKey||s.metaKey)&&(s.preventDefault(),M());break;case"-":(s.ctrlKey||s.metaKey)&&(s.preventDefault(),D());break;case"0":(s.ctrlKey||s.metaKey)&&(s.preventDefault(),F());break;case"f":(s.ctrlKey||s.metaKey)&&(s.preventDefault(),$());break}};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[L,S,P,v,n==null?void 0:n.pageCount,M,D,F,$]),r.useImperativeHandle(i,()=>({goToPage:v,nextPage:S,prevPage:P,setZoom:y,zoomIn:M,zoomOut:D,resetZoom:F,rotate:H,download:q,print:V,toggleFullscreen:$,getInfo:()=>n}),[v,S,P,y,M,D,F,H,q,V,$,n]);const ue=()=>{if(T)return(typeof A=="function"?A(T):A)??e.jsx("div",{className:"nice-document-viewer__error",children:e.jsxs("span",{children:[e.jsx(h.xe,{name:"warning",size:14})," ",T.message]})});switch(j){case"pdf":return e.jsx(we,{src:t,page:_,zoom:E,rotation:J,onPageChange:v,onLoad:N,onError:W,workerUrl:ee});case"image":return e.jsx(ge,{src:t,zoom:E,rotation:J,onLoad:N,onError:W});case"video":case"audio":return e.jsx(be,{src:t,type:j,onLoad:N,onError:W});case"office":return e.jsx(_e,{src:t,viewerUrl:te,onLoad:N});case"text":return e.jsx(je,{src:t,onLoad:N,onError:W});case"html":return e.jsx(ye,{src:t,onLoad:N});default:return e.jsxs("div",{className:"nice-document-viewer__unknown",children:[e.jsxs("span",{children:[e.jsx(h.xe,{name:"file",size:14})," Unknown document type"]}),e.jsx("button",{type:"button",onClick:q,children:"Download"})]})}},me=K&&j==="pdf"&&((n==null?void 0:n.pageCount)??0)>1,pe=Z&&(j==="pdf"||j==="image"),fe=z&&(j==="pdf"||j==="image");return e.jsxs("div",{ref:G,className:`nice-document-viewer ${I?"nice-document-viewer--fullscreen":""} ${re??""}`,style:{height:l,width:p},"data-testid":oe,"data-type":j,children:[O&&e.jsxs("div",{className:"nice-document-viewer__toolbar",children:[e.jsx("div",{className:"nice-document-viewer__toolbar-left",children:me&&e.jsxs("div",{className:"nice-document-viewer__pagination",children:[e.jsx("button",{type:"button",onClick:P,disabled:_<=1,"aria-label":"Previous page",children:e.jsx(h.xe,{name:"chevron-left",size:16})}),e.jsxs("span",{children:[e.jsx("input",{type:"number",value:_,onChange:a=>v(parseInt(a.target.value,10)),min:1,max:(n==null?void 0:n.pageCount)??1}),"/ ",(n==null?void 0:n.pageCount)??1]}),e.jsx("button",{type:"button",onClick:S,disabled:_>=((n==null?void 0:n.pageCount)??1),"aria-label":"Next page",children:e.jsx(h.xe,{name:"chevron-right",size:16})})]})}),e.jsxs("div",{className:"nice-document-viewer__toolbar-center",children:[pe&&e.jsxs("div",{className:"nice-document-viewer__zoom",children:[e.jsx("button",{type:"button",onClick:D,"aria-label":"Zoom out",children:"−"}),e.jsxs("span",{children:[Math.round(E*100),"%"]}),e.jsx("button",{type:"button",onClick:M,"aria-label":"Zoom in",children:"+"}),e.jsx("button",{type:"button",onClick:F,"aria-label":"Reset zoom",children:e.jsx(h.xe,{name:"refresh",size:16})})]}),fe&&e.jsxs("div",{className:"nice-document-viewer__rotation",children:[e.jsx("button",{type:"button",onClick:()=>H(270),"aria-label":"Rotate left",children:e.jsx(h.xe,{name:"refresh",size:16})}),e.jsx("button",{type:"button",onClick:()=>H(90),"aria-label":"Rotate right",children:e.jsx(h.xe,{name:"refresh",size:16})})]})]}),e.jsxs("div",{className:"nice-document-viewer__toolbar-right",children:[d&&e.jsx("button",{type:"button",onClick:q,"aria-label":"Download",children:e.jsx(h.xe,{name:"download",size:16})}),x&&e.jsx("button",{type:"button",onClick:V,"aria-label":"Print",children:e.jsx(h.xe,{name:"printer",size:16})}),g&&e.jsx("button",{type:"button",onClick:$,"aria-label":"Fullscreen",children:e.jsx(h.xe,{name:I?"collapse":"expand",size:16})})]})]}),e.jsxs("div",{className:"nice-document-viewer__content",children:[de&&!T&&(ne??e.jsx("div",{className:"nice-document-viewer__loading",children:"Loading..."})),ue()]}),n&&e.jsxs("div",{className:"nice-document-viewer__info",children:[e.jsx("span",{className:"nice-document-viewer__name",children:u??n.name}),n.size&&e.jsx("span",{className:"nice-document-viewer__size",children:he(n.size)}),n.width&&n.height&&e.jsxs("span",{className:"nice-document-viewer__dimensions",children:[n.width," × ",n.height]}),n.duration&&e.jsx("span",{className:"nice-document-viewer__duration",children:xe(n.duration)})]})]})}),X="nice-document-viewer-styles";if(typeof document<"u"&&!document.getElementById(X)){const o=document.createElement("style");o.id=X,o.textContent=`
|
|
2
2
|
.nice-document-viewer {
|
|
3
3
|
display: flex;
|
|
4
4
|
flex-direction: column;
|
|
5
|
-
border: 1px solid var(--border-color, #e5e7eb);
|
|
5
|
+
border: 1px solid var(--nice-border-color, #e5e7eb);
|
|
6
6
|
border-radius: var(--nice-radius-sm, 4px);
|
|
7
7
|
overflow: hidden;
|
|
8
|
-
background: var(--bg-primary, #ffffff);
|
|
8
|
+
background: var(--nice-bg-primary, #ffffff);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
.nice-document-viewer--fullscreen {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
align-items: center;
|
|
25
25
|
justify-content: space-between;
|
|
26
26
|
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
27
|
-
background: var(--bg-primary, #ffffff);
|
|
28
|
-
border-bottom: 1px solid var(--border-color, #e5e7eb);
|
|
27
|
+
background: var(--nice-bg-primary, #ffffff);
|
|
28
|
+
border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
|
|
29
29
|
flex-shrink: 0;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
|
|
40
40
|
.nice-document-viewer__toolbar button {
|
|
41
41
|
padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
|
|
42
|
-
border: 1px solid var(--border-color, #e5e7eb);
|
|
42
|
+
border: 1px solid var(--nice-border-color, #e5e7eb);
|
|
43
43
|
border-radius: var(--nice-radius-sm, 4px);
|
|
44
|
-
background: var(--bg-primary, #ffffff);
|
|
44
|
+
background: var(--nice-bg-primary, #ffffff);
|
|
45
45
|
cursor: pointer;
|
|
46
46
|
font-size: 14px;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
.nice-document-viewer__toolbar button:hover:not(:disabled) {
|
|
50
|
-
background: var(--hover-bg, color-mix(in srgb, var(--text-primary, #000) 4%, transparent));
|
|
50
|
+
background: var(--nice-hover-bg, color-mix(in srgb, var(--nice-text-primary, #000) 4%, transparent));
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
.nice-document-viewer__toolbar button:disabled {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
.nice-document-viewer__pagination input {
|
|
67
67
|
width: 50px;
|
|
68
68
|
padding: var(--nice-space-1, 4px);
|
|
69
|
-
border: 1px solid var(--border-color, #e5e7eb);
|
|
69
|
+
border: 1px solid var(--nice-border-color, #e5e7eb);
|
|
70
70
|
border-radius: var(--nice-radius-sm, 4px);
|
|
71
71
|
text-align: center;
|
|
72
72
|
}
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
justify-content: center;
|
|
96
96
|
gap: var(--nice-space-3, 12px);
|
|
97
97
|
padding: var(--nice-space-10, 40px);
|
|
98
|
-
color: var(--text-secondary, #475569);
|
|
98
|
+
color: var(--nice-text-secondary, #475569);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
.nice-document-viewer__error span {
|
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
height: 100%;
|
|
151
151
|
overflow: auto;
|
|
152
152
|
padding: var(--nice-space-4, 16px);
|
|
153
|
-
background: var(--bg-primary, #ffffff);
|
|
153
|
+
background: var(--nice-bg-primary, #ffffff);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
.nice-document-viewer__text pre {
|
|
@@ -166,15 +166,15 @@
|
|
|
166
166
|
align-items: center;
|
|
167
167
|
gap: var(--nice-space-4, 16px);
|
|
168
168
|
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
169
|
-
background: var(--bg-primary, #ffffff);
|
|
170
|
-
border-top: 1px solid var(--border-color, #e5e7eb);
|
|
169
|
+
background: var(--nice-bg-primary, #ffffff);
|
|
170
|
+
border-top: 1px solid var(--nice-border-color, #e5e7eb);
|
|
171
171
|
font-size: 12px;
|
|
172
|
-
color: var(--text-secondary, #475569);
|
|
172
|
+
color: var(--nice-text-secondary, #475569);
|
|
173
173
|
flex-shrink: 0;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
.nice-document-viewer__name {
|
|
177
177
|
font-weight: 500;
|
|
178
|
-
color: var(--text-primary, #0f172a);
|
|
178
|
+
color: var(--nice-text-primary, #0f172a);
|
|
179
179
|
}
|
|
180
|
-
`,document.head.appendChild(
|
|
180
|
+
`,document.head.appendChild(o)}exports.NiceDocumentViewer=ke;
|