Files
bambuddy/static/assets/PdfPreviewModal-ChNGaUl4.js
T
maziggy f471fe7b27 Add Gotify as a notification provider (#2743)
Posts to the server's /message endpoint with the app token in the
X-Gotify-Key header. Each event's priority level is sent to Gotify as
0, 2, 5, 8 or 10, set in the same per-event priority section ntfy uses.
Events without a level go out at 5. The snapshot goes out as a
bigImageUrl, and the outcome confirmation opens its dialog on tap.

-----

List notification providers alphabetically

The Provider Type list in the Add Notification Provider dialog is now
sorted by the name shown on screen, in the current UI language, so the
order holds in every locale.
2026-10-05 12:24:02 +02:00

2 lines
7.2 KiB
JavaScript

const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-rlMIkeOl.js","assets/index-CdoB5JwO.js","assets/chunk-aKtaBQYM.js","assets/index-Bb4TsUSQ.css"])))=>i.map(i=>d[i]);
import{i as e}from"./chunk-aKtaBQYM.js";import{_ as t,a as n,c as r,f as i,g as a,h as o,i as s,m as c,n as l,o as u,r as d,s as ee,t as te,u as ne,v as re,y as f}from"./index-CdoB5JwO.js";var p=e(f(),1),m=a(),h=.4,g=4,_=1.25,v=30,ie=Math.log(_)/v,ae=150,y=16*1024*1024,b=`/assets/pdfjs/`,oe=e=>Math.min(g,Math.max(h,e));function x(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);n.fillStyle=`#ffffff`,n.fillRect(0,0,256,256);let r=256/Math.max(e.width,e.height),i=e.width*r,a=e.height*r;return n.drawImage(e,(256-i)/2,(256-a)/2,i,a),new Promise(e=>t.toBlob(e,`image/png`))}function S(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function C({libraryFileId:e,filename:a,fileSize:f,onClose:h,onSnapshot:g}){let{t:C}=re(),w=te(),{panelRef:T,isFullscreen:E,toggleFullscreen:D}=w,O=(0,p.useRef)(null),k=(0,p.useRef)(null),A=(0,p.useRef)(null),j=(0,p.useRef)(!1),M=(0,p.useRef)(g);(0,p.useEffect)(()=>{M.current=g});let[N,P]=(0,p.useState)(null),[F,I]=(0,p.useState)(1),[L,R]=(0,p.useState)(1),[z,se]=(0,p.useState)(1),[B,ce]=(0,p.useState)(0),[V,H]=(0,p.useState)(null),[U,W]=(0,p.useState)(!0),G=(0,p.useRef)(L),K=(0,p.useRef)(null),q=(0,p.useRef)(null),J=(0,p.useRef)(new Map),Y=(0,p.useRef)(null),X=(0,p.useCallback)((e,t,n)=>{let r=O.current,i=k.current;if(r&&i){let e=r.getBoundingClientRect(),a=i.getBoundingClientRect(),o=t==null?e.width/2:t-e.left,s=n==null?e.height/2:n-e.top;q.current=a.width>0&&a.height>0?{fx:(o+e.left-a.left)/a.width,fy:(s+e.top-a.top)/a.height,px:o,py:s}:null}R(t=>oe(t*e))},[]);(0,p.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),X(_)):e.key===`-`?(e.preventDefault(),X(1/_)):e.key===`0`&&(e.preventDefault(),q.current=null,R(1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X]),(0,p.useEffect)(()=>{let e=O.current;if(!e)return;let t=t=>{if(!k.current||!K.current||!(t.ctrlKey||t.metaKey)&&!(e.scrollHeight<=e.clientHeight&&e.scrollWidth<=e.clientWidth))return;t.preventDefault();let n=Math.max(-30,Math.min(v,S(t)));X(Math.exp(-n*ie),t.clientX,t.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X]);let le=e=>{e.pointerType===`touch`&&(J.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),Y.current=null)},ue=e=>{if(e.pointerType!==`touch`)return;let t=J.current,n=t.get(e.pointerId);if(!n)return;if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){let t=O.current;t&&(t.scrollLeft-=e.clientX-n.x,t.scrollTop-=e.clientY-n.y);return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=Y.current;Y.current=a,o!=null&&o>0&&a>0&&X(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},Z=e=>{e.pointerType===`touch`&&(J.current.delete(e.pointerId),Y.current=null)};(0,p.useLayoutEffect)(()=>{G.current=L;let e=k.current,t=O.current,n=K.current;if(!e||!t||!n)return;e.style.width=`${n.width*L}px`,e.style.height=`${n.height*L}px`;let r=q.current;q.current=null,r&&(t.scrollLeft=e.offsetLeft+r.fx*e.offsetWidth-r.px,t.scrollTop=e.offsetTop+r.fy*e.offsetHeight-r.py)},[L]),(0,p.useEffect)(()=>{if(L===z)return;let e=window.setTimeout(()=>se(L),ae);return()=>window.clearTimeout(e)},[L,z]),(0,p.useEffect)(()=>{let e=T.current;if(!e)return;let t=new ResizeObserver(()=>ce(e=>e+1));return t.observe(e),()=>t.disconnect()},[T]),(0,p.useEffect)(()=>{let r=!1,i=null;if(P(null),H(null),I(1),W(!0),f>52428800){H(C(`fileManager.preview.tooLarge`,{size:s(f)})),W(!1);return}let a={},o=u();return o&&(a.Authorization=`Bearer ${o}`),(async()=>{let o=await fetch(n.getLibraryFileDownloadUrl(e),{headers:a});if(!o.ok)throw Error(`HTTP ${o.status}`);let s=await o.arrayBuffer(),c=await t(()=>import(`./pdf-rlMIkeOl.js`),__vite__mapDeps([0,1,2,3]));if(c.GlobalWorkerOptions.workerSrc||(c.GlobalWorkerOptions.workerSrc=(await t(async()=>{let{default:e}=await import(`./pdf.worker.min-DpOxPwGP.js`);return{default:e}},[])).default),i=c.getDocument({data:new Uint8Array(s),cMapUrl:`${b}cmaps/`,iccUrl:`${b}iccs/`,standardFontDataUrl:`${b}standard_fonts/`,wasmUrl:`${b}wasm/`}),r){i.destroy();return}let l=await i.promise;r||P(l)})().catch(e=>{console.error(`[pdf-preview] load failed`,e),r||(H(C(`fileManager.preview.error`)),W(!1))}),()=>{r=!0,A.current?.cancel(),A.current=null,i?.destroy()}},[e,f,C]),(0,p.useEffect)(()=>{if(!N)return;let e=!1;return W(!0),(async()=>{let t=await N.getPage(F),n=k.current,r=O.current;if(!n||!r||e)return;let i=t.getViewport({scale:1}),a=Math.max((r.clientWidth-32)/i.width,.1),o=Math.min(window.devicePixelRatio||1,2),s=a*z*o,c=i.width*s*(i.height*s),l=c>y?s*Math.sqrt(y/c):s,u=t.getViewport({scale:l});n.width=u.width,n.height=u.height,K.current={width:i.width*a,height:i.height*a},n.style.width=`${K.current.width*G.current}px`,n.style.height=`${K.current.height*G.current}px`,A.current?.cancel();let d=t.render({canvas:n,viewport:u});if(A.current=d,await d.promise,!e&&(W(!1),F===1&&M.current&&!j.current)){j.current=!0;let t=await x(n);t&&!e&&M.current?.(t)}})().catch(t=>{!e&&t?.name!==`RenderingCancelledException`&&(console.error(`[pdf-preview] render failed`,t),H(C(`fileManager.preview.error`)),W(!1))}),()=>{e=!0}},[N,F,z,B,C]);let Q=N?.numPages??0,$=d;return(0,m.jsx)(l,{title:a,fullscreen:w,onClose:h,icon:(0,m.jsx)(i,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:(0,m.jsxs)(m.Fragment,{children:[N&&Q>1&&(0,m.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,m.jsx)(`button`,{onClick:()=>I(e=>Math.max(1,e-1)),disabled:F<=1,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":C(`fileManager.preview.prevPage`),children:(0,m.jsx)(c,{className:`w-4 h-4`})}),(0,m.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:C(`fileManager.preview.page`,{current:F,total:Q})}),(0,m.jsx)(`button`,{onClick:()=>I(e=>Math.min(Q,e+1)),disabled:F>=Q,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":C(`fileManager.preview.nextPage`),children:(0,m.jsx)(o,{className:`w-4 h-4`})})]}),N&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`button`,{onClick:()=>X(1/_),className:$,"aria-label":C(`fileManager.preview.zoomOut`),children:(0,m.jsx)(ee,{className:`w-4 h-4`})}),(0,m.jsx)(`button`,{onClick:()=>X(_),className:$,"aria-label":C(`fileManager.preview.zoomIn`),children:(0,m.jsx)(r,{className:`w-4 h-4`})})]})]}),children:(0,m.jsxs)(`div`,{ref:O,"data-testid":`pdf-preview-page`,className:`relative flex-1 min-h-0 overflow-auto bg-bambu-dark p-4 touch-none ${E?``:`rounded-b-lg`}`,onDoubleClick:D,onPointerDown:le,onPointerMove:ue,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:[V?(0,m.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,m.jsx)(`p`,{className:`text-bambu-gray text-center`,children:V})}):(0,m.jsx)(`div`,{className:`flex justify-center min-w-fit`,children:(0,m.jsx)(`canvas`,{ref:k,className:`shadow-lg`})}),!V&&U&&(0,m.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,m.jsx)(ne,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})}export{C as PdfPreviewModal};