Files
sm-bm-plugin/public/assets/realtime-pg3MdzgH.js

2 lines
9.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{U as R,L,Q as j}from"./index-DBE6HPTS.js";function m(e){const n=e<0,t=Math.abs(Math.round(e)),r=Math.floor(t/60),o=t%60;return(n?"−":"")+r+":"+(o<10?"0":"")+o}function z(e){return e.map(n=>Number.isFinite(n)&&n>0?n:0)}function w(e){return Number.isFinite(e)&&e>0?e:0}function H(e){const n=z(e.budgets),t=n.reduce((p,f)=>p+f,0),r=e.targetSeconds>0?e.targetSeconds:t,o=n.length===0?0:Math.max(0,Math.min(n.length-1,Math.trunc(e.index)||0)),i=w(e.elapsed),a=w(e.slideElapsed),s=n[o]??0,l=s-a;let d="",u=!1;if(!e.idle){let p=Math.min(a,s);for(let b=0;b<o;b++)p+=n[b]??0;const f=Math.round(p-i);u=f<0,d=f>=0?"zapas "+m(f):"opóźnienie "+m(-f)}return{slide:s?m(l):"—",total:m(r-i),pace:d,slideOver:s>0&&l<0,totalOver:i>r,late:u,idle:e.idle,paused:e.paused,hidden:e.hidden,elapsed:Math.floor(i),slideElapsed:Math.floor(a)}}function ue(e){const n=z(e.budgets),t=n.map(()=>0);let r=0,o=0,i=0,a=!1;function s(c){return n.length===0?0:Math.max(0,Math.min(n.length-1,c))}function l(){return o===0&&r===0}function d(){return H({budgets:n,targetSeconds:e.targetSeconds,index:i,slideElapsed:t[i]??0,elapsed:r,idle:l(),paused:o===0&&r>0,hidden:a})}function u(){if(!o)return;const c=e.now(),E=(c-o)/1e3;o=c,n.length>0&&(t[i]+=E),r+=E}function p(c){i=s(c),o===0&&r===0&&(o=e.now())}function f(c){i=s(c)}function b(){!r&&!o||(u(),o=o?0:e.now())}function C(){for(let c=0;c<t.length;c++)t[c]=0;r=0,o=0}return{go:p,seek:f,tick:u,pause:b,reset:C,toggleHidden(){a=!a},view:d}}const A="remote.action",_="remote.state",de=300,fe=1e4,O=45e3,pe=15e3,D=25e3,be=1e4,he=1e3,v=["next","prev","first","last","goto","speak","notes","sources","special","back","clock-pause","clock","clock-reset","toolbar","sync"],I=/^[A-Za-z0-9_-]{8,64}$/,U=9999,y=9999,T=86400,x=new Set(v),V=new Set(["say","notes","srcs"]),B={next:"ArrowRight",prev:"ArrowLeft",first:"Home",last:"End",speak:"p",notes:"n",sources:"z",special:"s",back:"Escape","clock-pause":"t",clock:"c","clock-reset":"r",toolbar:"h"};function me(e){const n=B[e];return!n||n.toLowerCase()==="f"?null:n}function g(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function h(e,n,t){return typeof e=="number"&&Number.isInteger(e)&&e>=n&&e<=t}function G(e){if(!g(e))return null;const n=e.action,t=e.tab;if(typeof n!="string"||!x.has(n)||typeof t!="string"||t!==""&&!I.test(t))return null;const r=n;return r==="goto"?h(e.number,1,U)?{action:r,number:e.number,tab:t}:null:e.number!==void 0?null:{action:r,tab:t}}function $(e){if(!g(e))return null;const{elapsed:n,slide_elapsed:t,paused:r,hidden:o,idle:i}=e;return!h(n,0,T)||!h(t,0,T)||typeof r!="boolean"||typeof o!="boolean"||typeof i!="boolean"?null:{elapsed:n,slide_elapsed:t,paused:r,hidden:o,idle:i}}function F(e){if(!g(e))return null;const{tab:n,claim:t,bye:r,number:o,total:i,special:a,has_special:s,panel:l,toolbar_hidden:d}=e;if(typeof n!="string"||!I.test(n)||typeof t!="boolean"||typeof r!="boolean"||!h(o,0,y)||!h(i,0,y)||o>i||typeof a!="boolean"||typeof s!="boolean"||typeof d!="boolean"||l!==null&&(typeof l!="string"||!V.has(l)))return null;const u=$(e.clock);return u?{tab:n,claim:t,bye:r,number:o,total:i,special:a,has_special:s,panel:l,toolbar_hidden:d,clock:u}:null}function ge(e){if(!g(e))return null;if(e.event===A){const n=G(e.payload);return n?{event:A,payload:n}:null}if(e.event===_){const n=F(e.payload);return n?{event:_,payload:n}:null}return null}function ye(){const e=globalThis.crypto;if(e&&typeof e.randomUUID=="function")return e.randomUUID();const n=new Uint8Array(16);if(e&&typeof e.getRandomValues=="function")e.getRandomValues(n);else for(let t=0;t<n.length;t++)n[t]=Math.floor(Math.random()*256);return Array.from(n,t=>t.toString(16).padStart(2,"0")).join("")}function k(e){return!Number.isFinite(e)||e<=0?0:Math.min(T,Math.floor(e))}function S(e){return!Number.isFinite(e)||e<=0?0:Math.min(y,Math.floor(e))}function Te(e,n,t,r={}){const o=S(e.total),i=Math.min(S(e.number),o);return{tab:t,claim:!!r.claim,bye:!!r.bye,number:i,total:o,special:e.special,has_special:e.hasSpecial,panel:e.panel,toolbar_hidden:e.toolbarHidden,clock:n?{elapsed:k(n.elapsed),slide_elapsed:k(n.slideElapsed),paused:n.paused,hidden:n.hidden,idle:n.idle}:{elapsed:0,slide_elapsed:0,paused:!1,hidden:!1,idle:!0}}}function Ee(e){let n=null;return{observe(t){if(t.bye){t.tab===n&&(n=null);return}t.claim&&(n=t.tab)},activeTab:()=>n,isActive:()=>n===e,shouldApply(t){return n===e&&(t.tab===""||t.tab===e)}}}function we(){let e=null,n=0,t=null;return{observe(r,o){return(r.claim&&!r.bye||t===null)&&(t=r.tab),r.tab!==t?!1:(e=r,n=o,r.bye&&(t=null),!0)},current:()=>e,receivedAt:()=>n,actionTab:()=>t??"",live(r){return e!==null&&!e.bye&&r-n<D}}}function Ae(e,n){return e>0&&n-e<O}const K={now:()=>Date.now(),setTimeout:(e,n)=>globalThis.setTimeout(e,n),clearTimeout:e=>globalThis.clearTimeout(e)};function _e(e,n,t=K){let r=Number.NEGATIVE_INFINITY,o=null;function i(){r=t.now(),e()}function a(){o!==null&&t.clearTimeout(o),o=null}return{call(){if(o!==null)return;const s=r+n-t.now();if(s<=0){i();return}o=t.setTimeout(()=>{o=null,i()},s)},flush(){a(),i()},cancel:a}}const q=/<h([1-3])\b[^>]*>([\s\S]*?)<\/h\1\s*>/gi,Y=/<br\s*\/?>/gi,Z=/<[^>]*>/g,W=/&(#x[0-9a-f]+|#[0-9]+|amp|lt|gt|quot|apos|nbsp);/gi,M={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "};function P(e){return e.replace(W,(n,t)=>{const r=t.toLowerCase();if(r in M)return M[r];const o=r.startsWith("#x")?parseInt(r.slice(2),16):parseInt(r.slice(1),10);return!Number.isFinite(o)||o<=0||o>1114111?n:o===160?" ":String.fromCodePoint(o)})}function X(e){return P(e.replace(Y," ").replace(Z,"")).replace(/\s+/g," ").trim()}function N(e,n){const t=e.findIndex(r=>r.number===n);return t<0?0:t}function ke(e){const n=e.body_html??"";for(const r of n.matchAll(q)){const o=X(r[2]??"");if(o)return o}const t=(e.section_label??"").trim();return t||`Slajd ${e.number}`}const Q={say:"Na ekranie: Powiedz",notes:"Na ekranie: Notatki",srcs:"Na ekranie: Źródła"};function Se(e){const n=[];return e.special&&n.push("Specjalny"),e.panel&&n.push(Q[e.panel]),e.toolbar_hidden&&n.push("Pasek ukryty"),e.clock.hidden&&n.push("Zegar ukryty"),n}const J={connecting:"Łączenie…",waiting:"Czekam na komputer",live:"Połączono",reconnecting:"Ponowne łączenie…",unavailable:"Pilot niedostępny"};function Me(e){return J[e]}function Ne(e,n,t,r,o,i){const{clock:a}=e,l=!a.paused&&!a.idle?Math.max(0,(i-o)/1e3):0;return{budgets:n,targetSeconds:t,index:r,slideElapsed:a.slide_elapsed+l,elapsed:a.elapsed+l,idle:a.idle,paused:a.paused,hidden:a.hidden}}function ze(e,n){const t=n&&e!==null,r=e?.panel??null,o=!!e?.special,i=(a,s,l,d,u=null)=>({action:a,label:s,kbd:l,enabled:t&&d,pressed:u});return[i("prev","Wstecz","",!0),i("next","Dalej","",!0),i("speak","Powiedz","P",!0,r==="say"),i("notes","Notatki","N",!0,r==="notes"),i("sources","Źródła","Z",!0,r==="srcs"),i("special","Specjalny","S",!!e?.has_special||o,o),i("back","Powrót","Esc",o),i("toolbar","Pasek","H",!0,e?!e.toolbar_hidden:!1),i("clock-pause",e?.clock.paused?"Wznów":"Pauza","T",!e?.clock.idle),i("clock",e?.clock.hidden?"Pokaż zegar":"Ukryj zegar","C",!0),i("clock-reset","Zeruj","R",!0),i("first","Początek","Home",!0),i("last","Koniec","End",!0)]}function Ie(e){return e===0?"Nie wysłano: brak połączenia z internetem. Naciśnij ponownie.":e===429?"Za dużo naciśnięć naraz. Odczekaj chwilę i naciśnij ponownie.":e===503?"Pilot jest teraz niedostępny. Steruj klawiaturą na komputerze.":"Nie wysłano polecenia. Naciśnij ponownie."}const ee=/<img\b((?:[^>"']|"[^"]*"|'[^']*')*)>/gi,ne=/([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;function te(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function oe(e){const n=new Map;for(const t of e.matchAll(ne)){const r=(t[1]??"").toLowerCase();!r||n.has(r)||n.set(r,t[2]??t[3]??t[4]??"")}return n}function Pe(e){return e?e.replace(ee,(n,t)=>{const r=oe(t);if(!r.has("data-deck-image"))return n;const o=P(r.get("alt")??"").replace(/\s+/g," ").trim();return`<em class="drawer-image">${o?`[obraz: ${te(o)}]`:"[obraz]"}</em>`}):""}function Ce(e,n,t,r){if(e.slides.length===0)return null;if(t&&n){const o=e.slides[N(e.slides,n.number)]??null;return o&&n.special&&o.special?o.special:o}return e.slides[N(e.slides,r)]??null}const re="/ws",ie="/api/realtime/token",se=new Set([401,403,404,503]);function ae(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}${re}`}function le(e){const n=String(e);return n==="connected"||n==="connecting"?n:"disconnected"}async function Re(e,n){const{Centrifuge:t,UnauthorizedError:r}=await R(async()=>{const{Centrifuge:s,UnauthorizedError:l}=await import("./index-B53bcf0x.js");return{Centrifuge:s,UnauthorizedError:l}},[]),o=new t(ae(),{minReconnectDelay:500,maxReconnectDelay:1e4,getToken:async()=>{try{const s=await L.request(ie);if(!s||typeof s.token!="string"||s.token==="")throw new Error("realtime: empty token");return s.token}catch(s){throw s instanceof j&&se.has(s.status)?(n.onUnavailable?.(),new r("realtime unavailable")):s}}});o.on("state",s=>n.onConnection?.(le(s.newState)));const i=o.newSubscription(e);i.on("publication",s=>n.onPublication(s.data)),i.on("subscribed",()=>n.onSubscribed?.()),i.on("unsubscribed",s=>{s.code>=400&&n.onDenied?.(s.code)}),i.subscribe(),o.connect();let a=!1;return{close(){a||(a=!0,i.removeAllListeners(),i.unsubscribe(),o.removeSubscription(i),o.disconnect(),o.removeAllListeners())},resubscribe(){a||i.subscribe()}}}export{he as C,be as D,fe as H,_ as R,de as S,_e as a,ue as b,Ee as c,ge as d,Te as e,Pe as f,ke as g,Ce as h,ze as i,Me as j,pe as k,we as l,Ie as m,ye as n,Re as o,Ae as p,H as q,me as r,N as s,Se as t,Ne as u};