import{y as e,cL as t,aZ as n}from"./index-D_yusBPL.js";import{a as r,g as a,o as s}from"./vendor-CSmrTISS.js";const i=/[\\/:*?"<>|]/g,o=(e,t=2)=>String(e).padStart(t,"0"),u=(e,t)=>(e||"").trim().replace(i,"_")||t;function c(e,n=new Date){const r=u(e.deviceid,"device"),a=u(e.devname,r),s=u(e.ip,"unknown"),i=(e=>`${e.getFullYear()}-${o(e.getMonth()+1)}-${o(e.getDate())}_${o(e.getHours())}-${o(e.getMinutes())}-${o(e.getSeconds())}.${o(e.getMilliseconds(),3)}${t(e)}.png`)(n);return`snapshots/${a}-${s}/${i}`}async function l(t){const n=c(t.device,t.now),r=(t.blob.type||"").trim()||"image/png";try{return await e.writeFile(n,t.blob,"files",r),{ok:!0,path:`files/${n}`}}catch(a){return{ok:!1,error:(a instanceof Error?a.message:String(a))||"request failed"}}}const d={stepPx:[5,1e3],coalesceMs:[0,200],amp:[0,5],durBaseMs:[0,800],releaseDelayMs:[0,500],brakeReversePx:[2,20]},f=Object.freeze({enabled:!1,natural:!0,brakeEnabled:!1,stepPx:48,coalesceMs:60,amp:.18,durBaseMs:50,releaseDelayMs:120,brakeReversePx:5});function h(e,t){const[n,r]=d[e];return((e,t,n)=>Math.max(t,Math.min(n,e)))(t,n,r)}function b(e,t){return n(e,{fallback:t,allowNumber:!0})}function m(e){return b(e,!0)}function g(e,t,n=f[e]){const r="number"==typeof t?t:Number.parseFloat(String(t??""));return Number.isFinite(r)?h(e,r):n}function M(e){return{enabled:b(e?.enabled,f.enabled),natural:b(e?.natural,f.natural),brakeEnabled:b(e?.brakeEnabled,f.brakeEnabled),stepPx:g("stepPx",e?.stepPx),coalesceMs:Math.round(g("coalesceMs",e?.coalesceMs)),amp:g("amp",e?.amp),durBaseMs:Math.round(g("durBaseMs",e?.durBaseMs)),releaseDelayMs:Math.round(g("releaseDelayMs",e?.releaseDelayMs)),brakeReversePx:Math.round(g("brakeReversePx",e?.brakeReversePx))}}function p(e,t,n,r=16){return Number.isFinite(e)?1===t?e*r:2===t?e*Math.max(n,r):e:0}function v(e){return e.enabled&&!e.pointerActive&&Number.isFinite(e.deltaY)&&Math.abs(e.deltaY)>.01}function w(e,t){const n=requestAnimationFrame,r=cancelAnimationFrame;let a,s;const i=()=>{if(!a)return;const t=a;a=void 0;const{mergeKey:n,...r}=t;e(r)},o=()=>{void 0!==s&&(r(s),s=void 0),i()};return{hasPending:()=>void 0!==a,schedule:e=>{a?(a.mergeKey??"")===(e.mergeKey??"")?a={...e,deltaY:a.deltaY+e.deltaY}:(o(),a=e):a=e,void 0===s&&(s=n(()=>{s=void 0,i()}))},flush:o,clear:()=>{a=void 0,void 0!==s&&(r(s),s=void 0)}}}function x(){const e=new Map;return{size:()=>e.size,get:t=>e.get(t),entries:()=>Array.from(e.entries()),acquire:(t,n)=>{const r=e.get(t);if(r)return r;const a=(()=>{const t=new Set;for(const n of e.values())t.add(n.finger);for(let e=28;e>=1;e-=1)if(!t.has(e))return e;return null})();if(null===a)return null;const s={finger:a,data:n};return e.set(t,s),s},update:(t,n)=>{const r=e.get(t);if(r)return r.data=n,r},release:t=>{const n=e.get(t);if(n)return e.delete(t),n},clear:()=>{const t=Array.from(e.entries());return e.clear(),t}}}const y=(e,t=0)=>{const n="number"==typeof e?e:Number(e);return Number.isFinite(n)?n:t},k=(e,t=0)=>{const n=y(e,t);return n>0?n:t};function $(e){const t=k(e.containerWidth,0),n=k(e.containerHeight,0),r=k(e.contentWidth,0),a=k(e.contentHeight,0);if(!(t&&n&&r&&a))return null;const s=Math.abs(Math.trunc(e.rotateQuarter??0))%4,i=s%2==0?r:a,o=s%2==0?a:r;if(!i||!o)return null;const u=Math.min(t/i,n/o);if(!Number.isFinite(u)||u<=0)return null;const c=i*u,l=o*u;return{baseWidth:i,baseHeight:o,scale:u,drawnWidth:c,drawnHeight:l,offsetX:(t-c)/2,offsetY:(n-l)/2}}function E(e=()=>!0){const t=()=>function(e){const t=e.visualViewport,n=k(t?.width,k(e.innerWidth,0)),r=k(t?.height,k(e.innerHeight,0));return{left:y(t?.offsetLeft,0),top:y(t?.offsetTop,0),width:Math.max(0,n),height:Math.max(0,r)}}(window),[n,i]=r(t()),o=()=>{const e=t();i(t=>function(e,t,n=.5){return!e||Math.abs(e.left-t.left)>n||Math.abs(e.top-t.top)>n||Math.abs(e.width-t.width)>n||Math.abs(e.height-t.height)>n}(t,e)?e:t)};return o(),a(()=>{if(!e())return void o();o();const t=window.visualViewport;window.addEventListener("resize",o),t?.addEventListener("resize",o),t?.addEventListener("scroll",o),s(()=>{window.removeEventListener("resize",o),t?.removeEventListener("resize",o),t?.removeEventListener("scroll",o)})}),n}export{f as R,g as a,$ as b,x as c,p as d,v as e,w as f,m as g,M as n,b as p,l as s,E as u};
