@nice2dev/ui-math 1.0.30 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NiceDocumentViewer-B-uEPZAf-B3Mc4woS.js +674 -0
- package/dist/NiceDocumentViewer-B-uEPZAf-Cqu7ZY0M.cjs +180 -0
- package/dist/NiceDocumentViewer-B-uEPZAf-D7D_oQs2.js +674 -0
- package/dist/NiceDocumentViewer-B-uEPZAf-DUPkuyM2.cjs +180 -0
- package/dist/index-B-GN7Tl3.cjs +6674 -0
- package/dist/index-CdkQ95oF.cjs +6674 -0
- package/dist/index-D1OnaU9z.js +97205 -0
- package/dist/index-DAeW1pW6.js +97217 -0
- package/dist/index.cjs +1 -31
- package/dist/index.mjs +28 -5596
- package/package.json +13 -13
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("./index-CdkQ95oF.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=`
|
|
2
|
+
.nice-document-viewer {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
border: 1px solid var(--border-color, #e5e7eb);
|
|
6
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
background: var(--bg-primary, #ffffff);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.nice-document-viewer--fullscreen {
|
|
12
|
+
position: fixed;
|
|
13
|
+
top: 0;
|
|
14
|
+
left: 0;
|
|
15
|
+
right: 0;
|
|
16
|
+
bottom: 0;
|
|
17
|
+
z-index: 9999;
|
|
18
|
+
border: none;
|
|
19
|
+
border-radius: 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.nice-document-viewer__toolbar {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: space-between;
|
|
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);
|
|
29
|
+
flex-shrink: 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.nice-document-viewer__toolbar-left,
|
|
33
|
+
.nice-document-viewer__toolbar-center,
|
|
34
|
+
.nice-document-viewer__toolbar-right {
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
gap: var(--nice-space-2, 8px);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.nice-document-viewer__toolbar button {
|
|
41
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
|
|
42
|
+
border: 1px solid var(--border-color, #e5e7eb);
|
|
43
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
44
|
+
background: var(--bg-primary, #ffffff);
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
font-size: 14px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.nice-document-viewer__toolbar button:hover:not(:disabled) {
|
|
50
|
+
background: var(--hover-bg, color-mix(in srgb, var(--text-primary, #000) 4%, transparent));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.nice-document-viewer__toolbar button:disabled {
|
|
54
|
+
opacity: 0.4;
|
|
55
|
+
cursor: not-allowed;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.nice-document-viewer__pagination,
|
|
59
|
+
.nice-document-viewer__zoom,
|
|
60
|
+
.nice-document-viewer__rotation {
|
|
61
|
+
display: flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
gap: var(--nice-space-1-5, 6px);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.nice-document-viewer__pagination input {
|
|
67
|
+
width: 50px;
|
|
68
|
+
padding: var(--nice-space-1, 4px);
|
|
69
|
+
border: 1px solid var(--border-color, #e5e7eb);
|
|
70
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
71
|
+
text-align: center;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.nice-document-viewer__zoom span {
|
|
75
|
+
min-width: 50px;
|
|
76
|
+
text-align: center;
|
|
77
|
+
font-size: 13px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.nice-document-viewer__content {
|
|
81
|
+
flex: 1;
|
|
82
|
+
overflow: auto;
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
position: relative;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.nice-document-viewer__loading,
|
|
90
|
+
.nice-document-viewer__error,
|
|
91
|
+
.nice-document-viewer__unknown {
|
|
92
|
+
display: flex;
|
|
93
|
+
flex-direction: column;
|
|
94
|
+
align-items: center;
|
|
95
|
+
justify-content: center;
|
|
96
|
+
gap: var(--nice-space-3, 12px);
|
|
97
|
+
padding: var(--nice-space-10, 40px);
|
|
98
|
+
color: var(--text-secondary, #475569);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.nice-document-viewer__error span {
|
|
102
|
+
color: var(--nice-error, #d32f2f);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.nice-document-viewer__pdf,
|
|
106
|
+
.nice-document-viewer__image {
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: center;
|
|
109
|
+
justify-content: center;
|
|
110
|
+
min-height: 100%;
|
|
111
|
+
min-width: 100%;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.nice-document-viewer__pdf-canvas {
|
|
115
|
+
max-width: 100%;
|
|
116
|
+
height: auto;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.nice-document-viewer__image img {
|
|
120
|
+
max-width: 100%;
|
|
121
|
+
max-height: 100%;
|
|
122
|
+
object-fit: contain;
|
|
123
|
+
transition: transform 0.2s;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.nice-document-viewer__video,
|
|
127
|
+
.nice-document-viewer__audio {
|
|
128
|
+
display: flex;
|
|
129
|
+
align-items: center;
|
|
130
|
+
justify-content: center;
|
|
131
|
+
width: 100%;
|
|
132
|
+
height: 100%;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.nice-document-viewer__video video,
|
|
136
|
+
.nice-document-viewer__audio audio {
|
|
137
|
+
max-width: 100%;
|
|
138
|
+
max-height: 100%;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.nice-document-viewer__office iframe,
|
|
142
|
+
.nice-document-viewer__html iframe {
|
|
143
|
+
width: 100%;
|
|
144
|
+
height: 100%;
|
|
145
|
+
border: none;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.nice-document-viewer__text {
|
|
149
|
+
width: 100%;
|
|
150
|
+
height: 100%;
|
|
151
|
+
overflow: auto;
|
|
152
|
+
padding: var(--nice-space-4, 16px);
|
|
153
|
+
background: var(--bg-primary, #ffffff);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.nice-document-viewer__text pre {
|
|
157
|
+
margin: 0;
|
|
158
|
+
font-family: 'Fira Code', monospace;
|
|
159
|
+
font-size: 13px;
|
|
160
|
+
white-space: pre-wrap;
|
|
161
|
+
word-wrap: break-word;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.nice-document-viewer__info {
|
|
165
|
+
display: flex;
|
|
166
|
+
align-items: center;
|
|
167
|
+
gap: var(--nice-space-4, 16px);
|
|
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);
|
|
171
|
+
font-size: 12px;
|
|
172
|
+
color: var(--text-secondary, #475569);
|
|
173
|
+
flex-shrink: 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.nice-document-viewer__name {
|
|
177
|
+
font-weight: 500;
|
|
178
|
+
color: var(--text-primary, #0f172a);
|
|
179
|
+
}
|
|
180
|
+
`,document.head.appendChild(r)}exports.NiceDocumentViewer=ke;
|