@matchomag/cs2-replay 0.0.0-stage → 0.3.0
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/FORMAT.md +350 -0
- package/README.md +453 -2
- package/bin/demo-replay-darwin-amd64 +0 -0
- package/bin/demo-replay-darwin-arm64 +0 -0
- package/bin/demo-replay-linux-amd64 +0 -0
- package/bin/demo-replay-linux-arm64 +0 -0
- package/bin/demo-replay-windows-amd64.exe +0 -0
- package/bin/demo-replay.js +22 -0
- package/dist/2d/index.js +1 -0
- package/dist/3d/index.js +11 -0
- package/dist/chunks/actors-EZRYEB4I.js +177 -0
- package/dist/chunks/chunk-5BFKVD63.js +1 -0
- package/dist/chunks/chunk-D5ST2XVO.js +106 -0
- package/dist/chunks/chunk-DQPOBPMK.js +1 -0
- package/dist/chunks/chunk-FBSLUYGT.js +1 -0
- package/dist/chunks/chunk-Q37CWKZX.js +12 -0
- package/dist/chunks/chunk-VSIECNZM.js +1 -0
- package/dist/chunks/chunk-YJG3LSSB.js +1 -0
- package/dist/chunks/chunk-YO73RW3Y.js +1 -0
- package/dist/chunks/look-2WBUGHMJ.js +669 -0
- package/dist/index.js +1 -0
- package/dist/maps/index.js +1 -0
- package/dist/parse/index.js +1 -0
- package/dist/parse/wasm/replay.wasm +0 -0
- package/dist/parse/worker.js +1 -0
- package/dist/types/2d/index.d.ts +17 -0
- package/dist/types/2d/radar.d.ts +35 -0
- package/dist/types/3d/actors.d.ts +90 -0
- package/dist/types/3d/characters/anim.d.ts +93 -0
- package/dist/types/3d/characters/ao.d.ts +3 -0
- package/dist/types/3d/characters/body.d.ts +37 -0
- package/dist/types/3d/characters/builder.d.ts +82 -0
- package/dist/types/3d/characters/index.d.ts +74 -0
- package/dist/types/3d/characters/rig.d.ts +73 -0
- package/dist/types/3d/characters/textures.d.ts +4 -0
- package/dist/types/3d/characters/viewmodel.d.ts +51 -0
- package/dist/types/3d/characters/weapons.d.ts +25 -0
- package/dist/types/3d/follow.d.ts +43 -0
- package/dist/types/3d/fx/batch.d.ts +87 -0
- package/dist/types/3d/fx/context.d.ts +34 -0
- package/dist/types/3d/fx/explosion.d.ts +14 -0
- package/dist/types/3d/fx/fire.d.ts +11 -0
- package/dist/types/3d/fx/index.d.ts +84 -0
- package/dist/types/3d/fx/lights.d.ts +25 -0
- package/dist/types/3d/fx/meshes.d.ts +18 -0
- package/dist/types/3d/fx/misc.d.ts +15 -0
- package/dist/types/3d/fx/random.d.ts +21 -0
- package/dist/types/3d/fx/smoke.d.ts +10 -0
- package/dist/types/3d/fx/textures.d.ts +29 -0
- package/dist/types/3d/fx/types.d.ts +117 -0
- package/dist/types/3d/greybox.d.ts +22 -0
- package/dist/types/3d/index.d.ts +127 -0
- package/dist/types/3d/look.d.ts +49 -0
- package/dist/types/3d/markers.d.ts +23 -0
- package/dist/types/3d/smoke/volume.d.ts +95 -0
- package/dist/types/3d/smoke/voxels.d.ts +87 -0
- package/dist/types/3d/world/index.d.ts +179 -0
- package/dist/types/3d/world/look.d.ts +16 -0
- package/dist/types/3d/world/material.d.ts +128 -0
- package/dist/types/3d/world/post.d.ts +75 -0
- package/dist/types/3d/world/probes.d.ts +39 -0
- package/dist/types/3d/world/release.d.ts +28 -0
- package/dist/types/3d/world/stage.d.ts +84 -0
- package/dist/types/core/format.d.ts +163 -0
- package/dist/types/core/live.d.ts +115 -0
- package/dist/types/core/model.d.ts +164 -0
- package/dist/types/core/playback.d.ts +82 -0
- package/dist/types/core/theme.d.ts +46 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/maps/index.d.ts +258 -0
- package/dist/types/parse/index.d.ts +108 -0
- package/dist/types/ui/shell.d.ts +131 -0
- package/dist/types/ui/styles.d.ts +1 -0
- package/package.json +68 -4
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import{c as w,d as k,e as A,f as z}from"./chunk-5BFKVD63.js";import{a as R,b as S,c as H,h as C}from"./chunk-FBSLUYGT.js";import{a as E,d as x,e as $}from"./chunk-VSIECNZM.js";var B=`
|
|
2
|
+
.cs2r {
|
|
3
|
+
container-type: inline-size;
|
|
4
|
+
position: relative; display: flex; flex-direction: column;
|
|
5
|
+
width: 100%; height: 100%; min-height: 240px; overflow: hidden;
|
|
6
|
+
background: var(--replay-bg); color: var(--replay-text);
|
|
7
|
+
font: 12px/1.35 var(--replay-font);
|
|
8
|
+
-webkit-tap-highlight-color: transparent;
|
|
9
|
+
}
|
|
10
|
+
.cs2r:focus { outline: none; }
|
|
11
|
+
.cs2r:focus-visible { outline: 2px solid var(--replay-accent); outline-offset: -2px; }
|
|
12
|
+
.cs2r *, .cs2r *::before, .cs2r *::after { box-sizing: border-box; }
|
|
13
|
+
.cs2r-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
|
|
14
|
+
.cs2r--sides .cs2r-main { grid-template-columns: 190px minmax(0, 1fr) 190px; }
|
|
15
|
+
.cs2r-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
|
|
16
|
+
.cs2r-stage > canvas, .cs2r-stage > .cs2r-layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
|
|
17
|
+
.cs2r-stage > canvas { touch-action: none; }
|
|
18
|
+
|
|
19
|
+
.cs2r-panel { background: var(--replay-panel); border: 1px solid var(--replay-border); border-radius: 4px; }
|
|
20
|
+
.cs2r-score { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); padding: 4px 12px; text-align: center; pointer-events: none; white-space: nowrap; z-index: 2; }
|
|
21
|
+
.cs2r-score:empty, .cs2r-feed:empty { display: none; }
|
|
22
|
+
.cs2r-score .cs2r-teams { font-weight: 700; font-size: 14px; display: flex; gap: 8px; align-items: baseline; justify-content: center; }
|
|
23
|
+
.cs2r-score .cs2r-num { font: 700 15px var(--replay-mono); min-width: 1.4em; text-align: center; }
|
|
24
|
+
.cs2r-score .cs2r-clock { display: block; font: 11px var(--replay-mono); color: var(--replay-muted); margin-top: 1px; }
|
|
25
|
+
.cs2r-score .cs2r-clock.cs2r-bomb-time { color: var(--replay-bomb); }
|
|
26
|
+
.cs2r-feed { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; pointer-events: none; z-index: 2; max-width: calc(100% - 16px); }
|
|
27
|
+
.cs2r-feed > div { padding: 2px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
|
|
28
|
+
.cs2r-feed .cs2r-weapon { color: var(--replay-muted); margin: 0 4px; }
|
|
29
|
+
.cs2r-overlay-roster { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); padding: 6px 8px; min-width: 200px; z-index: 2; }
|
|
30
|
+
.cs2r-side { min-width: 0; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
|
|
31
|
+
.cs2r-team { font-weight: 700; margin: 2px 0; display: flex; justify-content: space-between; gap: 6px; }
|
|
32
|
+
.cs2r-team span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
33
|
+
.cs2r-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 6px; padding: 3px 4px; border-radius: 3px; cursor: pointer; background: transparent; border: 0; color: inherit; font: inherit; text-align: left; width: 100%; }
|
|
34
|
+
.cs2r-row:hover, .cs2r-row:focus-visible { background: color-mix(in srgb, var(--replay-text) 10%, transparent); outline: none; }
|
|
35
|
+
.cs2r-row.cs2r-dead { opacity: 0.42; }
|
|
36
|
+
.cs2r-row .cs2r-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
37
|
+
.cs2r-row .cs2r-hp { font-family: var(--replay-mono); text-align: right; }
|
|
38
|
+
.cs2r-row .cs2r-bar { grid-column: 1 / 3; height: 3px; margin: 2px 0 1px; background: color-mix(in srgb, var(--replay-text) 14%, transparent); border-radius: 2px; overflow: hidden; }
|
|
39
|
+
.cs2r-row .cs2r-bar i { display: block; height: 100%; }
|
|
40
|
+
.cs2r-row .cs2r-gear { grid-column: 1 / 3; font-size: 10px; color: var(--replay-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
41
|
+
.cs2r-badge { display: inline-block; font-size: 9px; font-weight: 700; padding: 0 3px; border-radius: 2px; margin-right: 4px; vertical-align: 1px; }
|
|
42
|
+
.cs2r-badge-c4 { background: var(--replay-bomb); color: #fff; }
|
|
43
|
+
.cs2r-badge-kit { background: var(--replay-ct); color: #000; }
|
|
44
|
+
|
|
45
|
+
.cs2r-bar-controls { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-top: 1px solid var(--replay-border); background: var(--replay-panel); user-select: none; }
|
|
46
|
+
.cs2r-btn, .cs2r-select { height: 28px; min-width: 30px; padding: 0 8px; border-radius: 4px; border: 1px solid var(--replay-border); background: transparent; color: inherit; font: 12px var(--replay-font); cursor: pointer; }
|
|
47
|
+
.cs2r-btn:hover, .cs2r-select:hover { background: color-mix(in srgb, var(--replay-text) 10%, transparent); }
|
|
48
|
+
.cs2r-btn:focus-visible, .cs2r-select:focus-visible { outline: 2px solid var(--replay-accent); outline-offset: 1px; }
|
|
49
|
+
.cs2r-select option { background: var(--replay-bg); color: var(--replay-text); }
|
|
50
|
+
.cs2r-btn svg { width: 14px; height: 14px; display: block; margin: auto; fill: currentColor; }
|
|
51
|
+
.cs2r-seg { display: flex; }
|
|
52
|
+
.cs2r-seg .cs2r-btn { position: relative; border-radius: 0; margin-left: -1px; }
|
|
53
|
+
.cs2r-seg .cs2r-btn:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
|
|
54
|
+
.cs2r-seg .cs2r-btn:last-child { border-radius: 0 4px 4px 0; }
|
|
55
|
+
.cs2r-seg .cs2r-btn[aria-pressed="true"] { z-index: 1; border-color: var(--replay-accent); background: color-mix(in srgb, var(--replay-accent) 24%, transparent); }
|
|
56
|
+
.cs2r-seg .cs2r-btn:focus-visible { z-index: 2; }
|
|
57
|
+
.cs2r-overlay-roster .cs2r-seg { margin-bottom: 6px; }
|
|
58
|
+
.cs2r-overlay-roster .cs2r-seg .cs2r-btn { flex: 1; height: 24px; }
|
|
59
|
+
.cs2r-overlay-roster--bare { top: 8px; transform: none; min-width: 0; padding: 4px; }
|
|
60
|
+
.cs2r-overlay-roster--bare .cs2r-seg { margin: 0; }
|
|
61
|
+
.cs2r-time { font: 12px var(--replay-mono); min-width: 128px; white-space: nowrap; color: var(--replay-muted); }
|
|
62
|
+
.cs2r-timeline { flex: 1; min-width: 80px; height: 34px; cursor: pointer; display: block; touch-action: none; }
|
|
63
|
+
.cs2r-live { position: absolute; top: 8px; left: 8px; z-index: 3; display: flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; font: 700 11px var(--replay-font); letter-spacing: 0.04em; color: var(--replay-muted); cursor: pointer; }
|
|
64
|
+
.cs2r-live:disabled { cursor: default; }
|
|
65
|
+
.cs2r-live:not(:disabled):hover { color: var(--replay-text); }
|
|
66
|
+
.cs2r-live:focus-visible { outline: 2px solid var(--replay-accent); outline-offset: 1px; }
|
|
67
|
+
.cs2r-live i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: 0.7; }
|
|
68
|
+
.cs2r-live span { font: 11px var(--replay-mono); letter-spacing: 0; }
|
|
69
|
+
.cs2r-live--on { color: var(--replay-text); }
|
|
70
|
+
.cs2r-live--on i { background: #e5383b; opacity: 1; animation: cs2r-pulse 2s ease-in-out infinite; }
|
|
71
|
+
@keyframes cs2r-pulse { 50% { opacity: 0.45; } }
|
|
72
|
+
@media (prefers-reduced-motion: reduce) { .cs2r-live--on i { animation: none; } }
|
|
73
|
+
/* The 3D roster's bare view switch sits where the badge is: below it then. */
|
|
74
|
+
.cs2r-live ~ .cs2r-overlay-roster--bare { top: 40px; }
|
|
75
|
+
.cs2r-waiting { pointer-events: none; }
|
|
76
|
+
.cs2r-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--replay-muted); z-index: 3; }
|
|
77
|
+
|
|
78
|
+
.cs2r-plabel { color: #fff; font: 11px var(--replay-font); text-shadow: 0 0 3px #000, 0 0 2px #000; text-align: center; white-space: nowrap; pointer-events: none; }
|
|
79
|
+
.cs2r-plabel .cs2r-plabel-hp { display: block; width: 46px; height: 3px; margin: 2px auto 0; background: #0008; }
|
|
80
|
+
.cs2r-plabel .cs2r-plabel-hp i { display: block; height: 100%; }
|
|
81
|
+
.cs2r-categories { position: absolute; top: 8px; right: 8px; padding: 6px 8px; line-height: 1.7; user-select: none; z-index: 2; }
|
|
82
|
+
.cs2r-categories label { display: block; cursor: pointer; }
|
|
83
|
+
.cs2r-categories .cs2r-swatch { display: inline-block; width: 10px; height: 10px; margin: 0 5px 0 3px; border: 1px solid #fff6; vertical-align: -1px; }
|
|
84
|
+
.cs2r-help { position: absolute; left: 8px; bottom: 8px; padding: 6px 8px; white-space: pre; pointer-events: none; color: var(--replay-muted); z-index: 2; font-size: 11px; }
|
|
85
|
+
|
|
86
|
+
@container (max-width: 720px) {
|
|
87
|
+
.cs2r--sides .cs2r-main { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
|
|
88
|
+
.cs2r--sides .cs2r-stage { grid-column: 1 / 3; grid-row: 1; }
|
|
89
|
+
.cs2r--sides .cs2r-side--t { grid-column: 1; grid-row: 2; max-height: 40cqh; }
|
|
90
|
+
.cs2r--sides .cs2r-side--ct { grid-column: 2; grid-row: 2; max-height: 40cqh; }
|
|
91
|
+
/* No room for the roster over the stage: only its controls stay, in the bottom right corner. */
|
|
92
|
+
.cs2r-overlay-roster:not(.cs2r-overlay-roster--controls), .cs2r-roster-list { display: none; }
|
|
93
|
+
.cs2r-overlay-roster { top: auto; bottom: 8px; left: auto; right: 8px; transform: none; min-width: 0; padding: 4px; }
|
|
94
|
+
.cs2r-overlay-roster .cs2r-seg { margin: 0; }
|
|
95
|
+
.cs2r-time { min-width: 0; }
|
|
96
|
+
.cs2r-time .cs2r-time-total { display: none; }
|
|
97
|
+
}
|
|
98
|
+
@container (max-width: 480px) {
|
|
99
|
+
/* The scoreboard takes the top: the badge goes to the bottom left. */
|
|
100
|
+
.cs2r-live { top: auto; bottom: 8px; }
|
|
101
|
+
.cs2r-bar-controls { flex-wrap: wrap; }
|
|
102
|
+
.cs2r-timeline { flex-basis: 100%; order: 10; }
|
|
103
|
+
.cs2r-feed { display: none; }
|
|
104
|
+
.cs2r-row .cs2r-gear { display: none; }
|
|
105
|
+
}
|
|
106
|
+
`,I="cs2r-styles";function K(f=document){if(f.getElementById(I))return;let l=f.createElement("style");l.id=I,l.textContent=B,f.head.appendChild(l)}var g={play:'<svg viewBox="0 0 16 16"><path d="M4 2.5v11l9-5.5z"/></svg>',pause:'<svg viewBox="0 0 16 16"><path d="M3.5 2.5h3v11h-3zM9.5 2.5h3v11h-3z"/></svg>',prev:'<svg viewBox="0 0 16 16"><path d="M3 2.5h2v11H3zM14 2.5v11L6 8z"/></svg>',next:'<svg viewBox="0 0 16 16"><path d="M11 2.5h2v11h-2zM2 2.5v11L10 8z"/></svg>'},y=f=>String(f).replace(/[&<>"']/g,l=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[l]),u=(f,l,e)=>{let t=document.createElement(f);return l&&(t.className=l),e&&(t.innerHTML=e),t},T=class extends R{constructor(e,t,r,c){super();this.host=e;this.replay=t;this.options=r;K(e.ownerDocument),this.themeInput=r.theme??{},this.themeValue=w(e,this.themeInput),this.live=C.of(t);let s=c.rosterLayout==="sides"&&r.hud?.roster!==!1&&(!!t?.rounds.length||!!this.live),o=u("div",`cs2r${s?" cs2r--sides":""}`);o.tabIndex=0,o.setAttribute("role","application"),o.setAttribute("aria-label",t?`Replay of ${t.map}`:"Map viewer"),k(o,this.themeValue),this.element=o;let n=u("div","cs2r-main");if(this.stage=u("div","cs2r-stage"),o.append(n),this.model=t?$(t,r):null,this.playback=this.model?new H(this.model,r.speeds??S):null,this.renderer=c.createRenderer({root:o,stage:this.stage,model:this.model,invalidate:()=>this.invalidate(),theme:()=>this.themeValue,emit:(i,p)=>this.emit(i,p),snapshot:()=>this.model&&this.playback?this.model.snapshot(this.playback.t):null}),this.stage.prepend(this.renderer.element),this.model&&this.playback){this.hud=new L(this,o,n,this.stage,this.model,this.playback,r,c.rosterLayout,this.renderer.rosterControls);let i=this.playback;i.speed=r.speed??1,i.on("change",()=>this.invalidate()),i.on("play",()=>(this.invalidate(),this.emit("play",void 0))),i.on("pause",()=>(this.invalidate(),this.emit("pause",void 0))),i.on("speed",()=>this.invalidate()),i.on("round",a=>this.emit("round",{index:a,round:this.model.replay.rounds[a]??null})),i.on("live",a=>(this.invalidate(),this.emit("live",{following:a,ended:this.live?.ended??!0})));let p=this.live;if(p&&!p.ended){i.live=!0,i.liveDelay=p.fragmentSeconds+1;let a=p.on("update",()=>{this.model.refresh(),i.grew(),this.renderer.replayChanged?.(),this.hud?.grew(),this.invalidate()}),v=p.on("end",()=>{i.live=!1,this.hud?.grew(),this.invalidate(),this.emit("live",{following:!1,ended:!0})});this.cleanups.push(a,v)}if(p&&!p.ended&&r.round==null)r.autoplay!==!1?i.goLive():i.seek(i.liveTarget());else{let a=r.round!=null?this.model.replay.rounds.findIndex(v=>v.num===r.round):0;i.gotoRound(Math.max(0,a)),r.autoplay&&i.play()}}else n.append(this.stage);e.append(o),this.listenKeys(o),this.watchSize(),this.watchTheme(),this.watchVisibility(),this.last=performance.now(),this.raf=requestAnimationFrame(this.loop)}host;replay;options;element;model;playback;renderer;stage;themeValue;themeInput;dirty=!0;raf=0;last=0;lastRaf=0;vsync=1e3/60;changedAt=-1/0;visible=!0;lastFrame=-1;cleanups=[];hud=null;live;loop=e=>{this.raf=requestAnimationFrame(this.loop);let t=e-this.lastRaf;this.lastRaf=e,t>0&&t<100&&(this.vsync+=(t-this.vsync)*.1);let r=this.renderer,c=this.options.maxFps??r.maxFps??0,s=e-this.last;if(c>0&&s>=0&&s+this.vsync/2<1e3/c)return;let o=Math.min((e-this.last)/1e3,.1);if(this.last=e,!this.visible)return;let n=this.playback?.tick(o)??!1;(n||this.dirty)&&(this.changedAt=e);let i=e-this.changedAt<(r.settle??0)*1e3;if(!n&&!this.dirty&&!r.continuous&&!i)return;this.dirty=!1;let p=this.model&&this.playback?this.model.snapshot(this.playback.t):null;this.renderer.render({snapshot:p,theme:this.themeValue,dt:o}),p&&(this.hud?.update(p),p.frame!==this.lastFrame&&(this.lastFrame=p.frame,this.emit("frame",p.frame)))};invalidate(){this.dirty=!0}listenKeys(e){let t=this.options.keyboard??"focus",r=s=>{if(s.defaultPrevented||s.metaKey||s.ctrlKey||s.altKey)return;let o=s.target;if(o?.closest("input, textarea, select, [contenteditable=''], [contenteditable='true']")||t==="global"&&o?.closest(".cs2r")&&o.closest(".cs2r")!==e||this.renderer.handleKey?.(s))return;let n=this.playback;if(n){switch(s.code){case"Space":if(o?.closest("button"))return;n.toggle();break;case"KeyP":case"KeyK":n.toggle();break;case"ArrowLeft":n.skip(s.shiftKey?-1:-5);break;case"ArrowRight":n.skip(s.shiftKey?1:5);break;case"Comma":n.pause(),n.seek(Math.ceil(n.t)-1);break;case"Period":n.pause(),n.seek(Math.floor(n.t)+1);break;case"BracketLeft":n.previousRound();break;case"BracketRight":n.nextRound();break;case"Minus":n.stepSpeed(-1);break;case"Equal":n.stepSpeed(1);break;case"KeyL":if(!n.live)return;n.goLive();break;default:return}s.preventDefault()}};if(t===!1)return;let c=t==="global"?window:e;c.addEventListener("keydown",r),this.cleanups.push(()=>c.removeEventListener("keydown",r))}watchSize(){let e=new ResizeObserver(()=>{let{width:t,height:r}=this.stage.getBoundingClientRect();t>0&&r>0&&this.renderer.resize(t,r),this.hud?.resize(),this.invalidate()});e.observe(this.stage),this.cleanups.push(()=>e.disconnect())}watchTheme(){let e=()=>this.setTheme(),t=new MutationObserver(e),r=this.host.ownerDocument;t.observe(r.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme"]}),t.observe(r.body,{attributes:!0,attributeFilter:["class","style","data-theme"]});let c=matchMedia("(prefers-color-scheme: dark)");c.addEventListener("change",e),this.cleanups.push(()=>(t.disconnect(),c.removeEventListener("change",e)))}watchVisibility(){if(typeof IntersectionObserver>"u")return;let e=new IntersectionObserver(([t])=>{this.visible=t.isIntersecting,this.visible&&this.invalidate()});e.observe(this.element),this.cleanups.push(()=>e.disconnect())}get theme(){return this.themeValue}get playing(){return this.playback?.playing??!1}get frame(){return this.playback?.t??0}get round(){let e=this.model?.roundAt(this.frame)??-1;return e>=0?this.model.replay.rounds[e]:null}get speed(){return this.playback?.speed??1}set speed(e){this.playback&&(this.playback.speed=e)}play(){this.playback?.play()}pause(){this.playback?.pause()}toggle(){this.playback?.toggle()}seek(e){this.playback?.seek(e)}gotoRound(e){let t=this.replay?.rounds.findIndex(r=>r.num===e)??-1;t>=0&&this.playback?.gotoRound(t)}get following(){return this.playback?.following??!1}goLive(){this.playback?.goLive()}setTheme(e){e&&(this.themeInput={...this.themeInput,...e});let t=w(this.host,this.themeInput);JSON.stringify(t)!==JSON.stringify(this.themeValue)&&(this.themeValue=t,k(this.element,t),this.hud?.themeChanged(),this.invalidate())}pickPlayer(e){this.emit("player",{index:e}),this.model&&this.playback&&this.renderer.focusPlayer&&this.renderer.focusPlayer(e,this.model.snapshot(this.playback.t))}destroy(){cancelAnimationFrame(this.raf),this.cleanups.forEach(e=>e()),this.renderer.destroy(),this.playback?.dispose(),this.clearListeners(),this.element.remove()}},L=class{constructor(l,e,t,r,c,s,o,n,i){this.viewer=l;this.model=c;this.pb=s;let p=o.hud??{},a=c.replay,v=l.live;if(!a.rounds.length&&!v){t.append(r),r.append(u("div","cs2r-empty",'<span class="cs2r-panel" style="padding:8px 12px">This demo has no live rounds to replay.</span>'));return}if(v){let h=u("button","cs2r-panel cs2r-live");h.type="button",h.addEventListener("click",()=>this.pb.goLive()),this.liveBadge=h,r.append(h),a.rounds.length||(this.waiting=u("div","cs2r-empty cs2r-waiting",'<span class="cs2r-panel" style="padding:8px 12px">Waiting for the match to start\u2026</span>'),r.append(this.waiting))}if(p.scoreboard!==!1&&r.append(this.score=u("div","cs2r-panel cs2r-score")),p.killFeed!==!1&&r.append(this.feed=u("div","cs2r-feed")),p.roster!==!1&&n==="sides")this.rosterT=u("div","cs2r-side cs2r-side--t"),this.rosterCT=u("div","cs2r-side cs2r-side--ct"),t.append(this.rosterT,r,this.rosterCT);else{t.append(r);let h=p.roster!==!1;if(h||i){let m=u("div","cs2r-panel cs2r-overlay-roster");i&&(m.append(i),m.classList.add("cs2r-overlay-roster--controls")),h?m.append(this.rosterT=u("div","cs2r-roster-list")):m.classList.add("cs2r-overlay-roster--bare"),r.append(m)}}let d=h=>{let m=h.target.closest(".cs2r-row");m&&this.viewer.pickPlayer(Number(m.dataset.p))};this.rosterT?.addEventListener("click",d),this.rosterCT?.addEventListener("click",d),p.controls!==!1&&this.buildControls(e)}viewer;model;pb;score;feed;rosterT;rosterCT;playBtn;speedSel;timeEl;timeline;liveBadge;waiting;hoverX=-1;keys={score:"",feed:"",roster:"",time:"",playing:!1,speed:0,live:""};buildControls(l){let e=this.pb,t=u("div","cs2r-bar-controls"),r=(a,v,d)=>{let h=u("button","cs2r-btn",v);return h.type="button",h.title=a,h.setAttribute("aria-label",a),h.addEventListener("click",d),h},c=r("Previous round ([)",g.prev,()=>e.previousRound());this.playBtn=r("Play (K)",g.play,()=>e.toggle());let s=r("Next round (])",g.next,()=>e.nextRound()),o=u("select","cs2r-select");o.title="Speed (- / =)",o.setAttribute("aria-label","Playback speed"),o.innerHTML=e.speeds.map(a=>`<option value="${a}">${a}\xD7</option>`).join(""),o.addEventListener("change",()=>e.speed=Number(o.value)),this.speedSel=o,this.timeEl=u("span","cs2r-time"),this.timeEl.setAttribute("aria-live","off");let n=u("canvas","cs2r-timeline");n.setAttribute("role","slider"),n.setAttribute("aria-label","Timeline"),this.timeline=n,t.append(c,this.playBtn,s,o,this.timeEl,n),l.append(t);let i=a=>a/n.clientWidth*Math.max(0,this.model.frames-1),p=!1;n.addEventListener("pointerdown",a=>{p=!0,n.setPointerCapture(a.pointerId),e.seek(i(a.offsetX))}),n.addEventListener("pointermove",a=>{this.hoverX=a.offsetX,p&&e.seek(i(a.offsetX)),this.viewer.invalidate()}),n.addEventListener("pointerup",()=>p=!1),n.addEventListener("pointercancel",()=>p=!1),n.addEventListener("pointerleave",()=>{this.hoverX=-1,this.viewer.invalidate()})}resize(){this.keys.score=this.keys.feed=this.keys.roster=""}grew(){this.waiting&&this.model.replay.rounds.length&&(this.waiting.remove(),this.waiting=void 0),this.keys.roster=this.keys.live=""}themeChanged(){this.resize()}update(l){let e=this.viewer.theme,t=this.pb;if(this.liveBadge){let r=!t.live,c=r||t.following?0:Math.max(0,this.model.seconds(l.frame,this.model.frames-1)-t.liveDelay),s=r?"ended":t.following?"live":`behind${Math.round(c)}`;if(s!==this.keys.live){this.keys.live=s;let o=this.liveBadge;o.classList.toggle("cs2r-live--on",s==="live"),o.disabled=r||s==="live",o.innerHTML=r?"Broadcast over":`<i></i>LIVE${s==="live"?"":` <span>\u2212${x(c)}</span>`}`;let n=r?"The broadcast is over":s==="live"?"Playing live":`${x(c)} behind live: go to live (L)`;o.title=n,o.setAttribute("aria-label",n)}}if(this.score&&l.round){let r=`${l.roundIndex}|${l.score.t}|${l.score.ct}|${l.clock.text}`;r!==this.keys.score&&(this.keys.score=r,this.score.innerHTML=`<span class="cs2r-teams"><span style="color:var(--replay-t)">${y(l.score.teamT)}</span><span class="cs2r-num">${l.score.t}</span>:<span class="cs2r-num">${l.score.ct}</span><span style="color:var(--replay-ct)">${y(l.score.teamCT)}</span></span><span class="cs2r-clock${l.clock.phase==="bomb"?" cs2r-bomb-time":""}">Round ${l.round.num} \xB7 ${y(l.clock.text)}</span>`)}else this.score&&this.keys.score!=="warmup"&&this.model.replay.rounds.length&&(this.keys.score="warmup",this.score.innerHTML='<span class="cs2r-clock">Warmup</span>');if(this.feed){let r=l.kills.map(c=>`${c.f},${c.victim}`).join(";");if(r!==this.keys.feed){this.keys.feed=r;let c=(s,o)=>s==null?"":`<span style="color:var(--replay-${o==="CT"?"ct":"t"})">${y(s)}</span>`;this.feed.innerHTML=l.kills.map(s=>{let o=`${s.hs?" \u2299":""}${s.wb?" \u21F6":""}${s.smoke?" \u2601":""}${s.noscope?" \u2300":""}${s.flash?" \u2736":""}`;return`<div class="cs2r-panel">${s.killer>=0&&s.killer!==s.victim?c(s.killerName,s.killerSide):""}<span class="cs2r-weapon">${y(s.weapon||"world")}${o}</span>${c(s.victimName,s.victimSide)}</div>`}).join("")}}if(this.rosterT){let r=l.players.filter(s=>s.present),c=r.map(s=>`${s.index}${s.side}${s.hp}${s.alive}${s.weapon}${s.armor}${s.hasBomb}${s.hasKit}`).join("|")+l.roundIndex;if(c!==this.keys.roster){this.keys.roster=c;let s=o=>{let n=r.filter(a=>a.side===o),i=n.filter(a=>a.alive).length,p=o==="T"?l.score.teamT:l.score.teamCT;return`<div class="cs2r-team" style="color:var(--replay-${o==="CT"?"ct":"t"})"><span>${y(p)}</span><span>${i}/${n.length}</span></div>`+n.map(a=>`<button type="button" class="cs2r-row${a.alive?"":" cs2r-dead"}" data-p="${a.index}" title="${y(a.name)}"><span class="cs2r-name">${a.hasBomb?'<b class="cs2r-badge cs2r-badge-c4">C4</b>':""}${a.hasKit?'<b class="cs2r-badge cs2r-badge-kit">KIT</b>':""}${y(a.name)}</span><span class="cs2r-hp">${a.alive?a.hp:"\u2715"}</span><span class="cs2r-bar"><i style="width:${a.hp}%;background:${z(e,a.hp)}"></i></span><span class="cs2r-gear">${a.alive?y(a.weapon)+(a.armor?` \xB7 ${a.armor} armor`:""):"dead"}</span></button>`).join("")};this.rosterCT?(this.rosterT.innerHTML=s("T"),this.rosterCT.innerHTML=s("CT")):this.rosterT.innerHTML=s("T")+s("CT")}}if(this.playBtn&&this.keys.playing!==t.playing){this.keys.playing=t.playing,this.playBtn.innerHTML=t.playing?g.pause:g.play;let r=t.playing?"Pause (K)":"Play (K)";this.playBtn.title=r,this.playBtn.setAttribute("aria-label",r)}if(this.speedSel&&this.keys.speed!==t.speed&&(this.keys.speed=t.speed,this.speedSel.value=String(t.speed)),this.timeEl){let r=x(this.model.seconds(0,l.frame)),c=`${l.round?.num}|${l.clock.text}|${r}`;c!==this.keys.time&&(this.keys.time=c,this.timeEl.innerHTML=`R${l.round?.num??"\u2013"} ${y(l.clock.text)} <span class="cs2r-time-total">\xB7 ${r}</span>`)}this.timeline&&this.drawTimeline(l,e)}drawTimeline(l,e){let t=this.timeline,r=this.model.frames,c=this.model.replay,s=devicePixelRatio||1,o=t.clientWidth,n=t.clientHeight;if(!o||!n)return;(t.width!==Math.round(o*s)||t.height!==Math.round(n*s))&&(t.width=Math.round(o*s),t.height=Math.round(n*s)),t.setAttribute("aria-valuemin","0"),t.setAttribute("aria-valuemax",String(Math.max(0,r-1))),t.setAttribute("aria-valuenow",String(l.frame)),t.setAttribute("aria-valuetext",l.round?`Round ${l.round.num}, ${l.clock.text}`:"");let i=t.getContext("2d");i.setTransform(s,0,0,s,0,0),i.clearRect(0,0,o,n);let p=d=>r>1?d/(r-1)*o:0,a=12,v=n-a;i.font=`10px ${e.font}`,c.rounds.forEach((d,h)=>{let m=p(d.start),b=p(Math.min(E(d),r-1));i.fillStyle=h%2?e.trackAlt:e.track,i.fillRect(m,a,b-m,v),d.live>=0&&(i.globalAlpha=.07,i.fillStyle=e.text,i.fillRect(m,a,p(d.live)-m,v),i.globalAlpha=1),d.winner&&(i.fillStyle=A(e,d.winner),i.fillRect(m,n-4,b-m,4)),i.fillStyle=e.muted,b-m>14&&i.fillText(String(d.num),m+2,10)}),i.fillStyle=e.text,i.globalAlpha=.8;for(let d of c.kills)i.fillRect(p(d.f),a+6,1,v-14);i.globalAlpha=1,i.fillStyle=e.bomb;for(let d of this.model.plants)i.beginPath(),i.arc(p(d.f),a+4,2.5,0,7),i.fill();if(i.fillStyle=e.accent,i.fillRect(p(l.t)-1,0,2,n),this.hoverX>=0){let d=Math.round(this.hoverX/o*(r-1)),h=this.model.roundAt(d),m=h>=0?`R${c.rounds[h].num} ${this.model.clock(d).text}`:"";i.globalAlpha=.6,i.fillStyle=e.text,i.fillRect(this.hoverX,a,1,v),i.globalAlpha=1;let b=i.measureText(m).width,M=Math.min(o-b-6,this.hoverX+4);i.fillStyle=e.panel,i.fillRect(M-2,a+v/2-8,b+4,13),i.fillStyle=e.text,i.fillText(m,M,a+v/2+2)}}};function D(f,l,e,t){return new T(f,l,e,t)}export{y as a,D as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=["first","third","free"];function y(i){return i.filter(n=>n.present).sort((n,t)=>n.side===t.side?n.index-t.index:n.side==="T"?-1:1)}function k(i,n,t){let e=y(i),r=e.length,o=e.findIndex(s=>s.index===n),a=o>=0?o:t>0?-1:r;for(let s=1;s<=r;s++){let l=e[((a+t*s)%r+r)%r];if(l.alive)return l.index}return null}function g(i,n){if(n!==null&&i[n]?.present)return n;let t=y(i);return(t.find(e=>e.alive)??t[0])?.index??null}function P(i,n){let t=(i-n)%(2*Math.PI);return t>Math.PI?t-2*Math.PI:t<=-Math.PI?t+2*Math.PI:t}var f=/grenade|flash|molotov|incendiary|decoy|smoke|snowball/i,m=/knife|bayonet|karambit|dagger|blade|bowie|falchion|stiletto|talon|ursus|navaja|kukri|huntsman|butterfly|c4|bomb/i,u=.5;function b(i){return i<0||i>u?0:i<.015?i/.015:Math.exp(-(i-.015)/.085)*(1-i/u)}var p=class{constructor(n){this.replay=n;this.sync()}replay;byPlayer=[];grenade=[];knife=[];shots=0;sync(){let n=this.replay,t=n.shots;for(t&&t.tick.length<this.shots&&(this.byPlayer=[],this.shots=0);this.byPlayer.length<n.players.length;)this.byPlayer.push([]);for(let e=this.grenade.length;e<n.weapons.length;e++)this.grenade.push(f.test(n.weapons[e])),this.knife.push(m.test(n.weapons[e]));if(t)for(let e=this.shots;e<t.tick.length;e++)this.byPlayer[t.p[e]]?.push(e);this.shots=t?.tick.length??0}pitch(n,t){let e=this.replay.shots,r=this.byPlayer[n];if(!e||!r?.length)return 0;let o=this.tickAt(t);for(let a=this.lastAt(r,o),s=0;a>=0&&s<6;a--,s++){let l=r[a],h=(o-e.tick[l])/this.replay.tickRate;if(h>2)break;if(this.grenade[e.w[l]])continue;let c=Math.min(1,Math.max(0,h-1));return-e.pitch[l]*(1-c*c*(3-2*c))}return 0}recoil(n,t){let e=this.replay.shots,r=this.byPlayer[n];if(!e||!r?.length)return 0;let o=this.tickAt(t),a=0;for(let s=this.lastAt(r,o),l=0;s>=0&&l<12;s--,l++){let h=r[s],c=(o-e.tick[h])/this.replay.tickRate;if(c>u)break;!this.grenade[e.w[h]]&&!this.knife[e.w[h]]&&(a+=b(c))}return Math.min(2,a)}lastAt(n,t){let e=this.replay.shots.tick,r=0,o=n.length-1,a=-1;for(;r<=o;){let s=r+o>>1;e[n[s]]<=t?(a=s,r=s+1):o=s-1}return a}tickAt(n){let t=this.replay.ticks;if(!t.length)return 0;let e=Math.max(0,Math.min(t.length-1,Math.floor(n))),r=Math.min(t.length-1,e+1);return t[e]+(t[r]-t[e])*Math.max(0,Math.min(1,n-e))}};export{d as a,k as b,g as c,P as d,p as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as u}from"./chunk-YJG3LSSB.js";var m=class{listeners=new Map;on(s,e){let t=this.listeners.get(s);return t||this.listeners.set(s,t=new Set),t.add(e),()=>t.delete(e)}emit(s,e){this.listeners.get(s)?.forEach(t=>t(e))}clearListeners(){this.listeners.clear()}},x=[.25,.5,1,2,4,8,16],b=class extends m{constructor(e,t=x,r=()=>performance.now()){super();this.model=e;this.speeds=t;this.now=r;this.edge={frames:e.frames,at:r()}}model;speeds;now;_t=0;_playing=!1;_speed=1;_round=-1;_live=!1;_following=!1;liveDelay=4;edge={frames:0,at:0};get live(){return this._live}set live(e){e!==this._live&&(this._live=e,e||this.setFollowing(!1))}get following(){return this._following}setFollowing(e){e!==this._following&&(this._following=e,this.emit("live",e))}grew(){this.model.frames!==this.edge.frames&&(this.edge={frames:this.model.frames,at:this.now()})}liveTarget(){let e=this.model.hz,t=Math.max(0,this.model.frames-1),r=Math.min(this.liveDelay,(this.now()-this.edge.at)/1e3);return Math.max(0,Math.min(t,this.edge.frames-1-this.liveDelay*e+r*e))}goLive(){this._live&&(this.speed=1,this.move(this.liveTarget()),this.setFollowing(!0),this._playing||(this._playing=!0,this.emit("play",void 0)))}get t(){return this._t}get playing(){return this._playing}get speed(){return this._speed}set speed(e){e===this._speed||!(e>0)||(this._speed=e,this.emit("speed",e),e!==1&&this.setFollowing(!1))}stepSpeed(e){let t=this.speeds.findIndex(a=>a>=this._speed),r=t<0?this.speeds.length-1:t;this.speed=this.speeds[Math.max(0,Math.min(this.speeds.length-1,r+e))]}get roundIndex(){return Math.max(0,this.model.roundAt(this._t))}play(){this._playing||!this._live&&this._t>=this.model.frames-1||(this._playing=!0,this.emit("play",void 0))}pause(){this.setFollowing(!1),this._playing&&(this._playing=!1,this.emit("pause",void 0))}toggle(){this._playing?this.pause():this.play()}seek(e){this.setFollowing(!1),this.move(e)}move(e){let t=Math.max(0,Math.min(Math.max(0,this.model.frames-1),e));if(t===this._t)return;this._t=t,this.emit("change",t);let r=this.model.roundAt(t);r!==this._round&&(this._round=r,this.emit("round",r))}skip(e){this.seek(this._t+e*this.model.hz)}roundStart(e){let t=this.model.replay.rounds;if(!t.length)return 0;let r=t[Math.max(0,Math.min(t.length-1,e))];return r.live>=0?Math.max(r.start,r.live-3*this.model.hz):r.start}gotoRound(e){this.seek(this.roundStart(e))}previousRound(){let e=this.roundIndex;this.gotoRound(this._t-this.roundStart(e)>2*this.model.hz?e:e-1)}nextRound(){this.gotoRound(this.roundIndex+1)}tick(e){if(!this._playing)return!1;let t=this.model.frames-1,r=this.model.hz,a=this._t;if(this._following){let o=this.liveTarget(),h=o-this._t;Math.abs(h)>3*r?this.move(o):this.move(Math.min(t,this._t+e*r*(1+Math.max(-.1,Math.min(.1,h/(4*r))))))}else this.move(this._t+e*r*this._speed),this._live&&this._t>=this.liveTarget()&&this._speed<=1&&this.setFollowing(!0);return this._t>=t&&!this._live&&this.pause(),this._t!==a}dispose(){this.clearListeners()}};var g=1,A=n=>n.length>=4&&n[0]===67&&n[1]===83&&n[2]===82&&n[3]===85;function E(n){let s=n instanceof Uint8Array?n:new Uint8Array(n);if(!A(s))throw new u("Not a live update.");let e=new DataView(s.buffer,s.byteOffset,s.byteLength),t=e.getUint32(4,!0);if(t>g)throw new u(`Live update version ${t} is newer than this viewer supports (${g}).`);let r=e.getUint32(8,!0);if(12+r>s.byteLength)throw new u("Live update is truncated.");let a=JSON.parse(new TextDecoder().decode(s.subarray(12,12+r))),o=a.frames??0,h=(a.players??[]).length,i=a.offsets??{};if(o>0&&i.bomb+o*12>s.byteLength)throw new u("Live update is truncated.");let l=(p,c,y)=>new p(s.slice(c,c+y*p.BYTES_PER_ELEMENT).buffer);return{...a,players:a.players??[],weapons:a.weapons??[""],ticks:o?l(Int32Array,i.ticks,o):new Int32Array(0),pos:o?l(Float32Array,i.pos,o*h*4):new Float32Array(0),state:o?l(Uint8Array,i.state,o*h*4):new Uint8Array(0),bombPos:o?l(Float32Array,i.bomb,o*3):new Float32Array(0)}}function L(n=""){return{version:1,map:n,server:"",protocol:0,tickRate:64,hz:16,frames:0,players:[],weapons:[""],rounds:[],kills:[],grenades:[],bomb:[],shots:{tick:[],p:[],w:[],yaw:[],pitch:[]},hurts:{tick:[],victim:[],attacker:[],dmg:[],hit:[]},ticks:new Int32Array(0),pos:new Float32Array(0),state:new Uint8Array(0),bombPos:new Float32Array(0)}}var w=Symbol.for("@matchomag/cs2-replay/live"),_=class extends m{replay;revision=0;ended=!1;endReason=null;endOnFinal=!0;fragmentSeconds=3;error=null;cap=0;ticksBuf=new Int32Array(0);posBuf=new Float32Array(0);stateBuf=new Uint8Array(0);bombBuf=new Float32Array(0);stride=0;constructor(s=L()){super(),this.replay=s,Object.defineProperty(s,w,{value:this,configurable:!0})}static of(s){return s?.[w]??null}apply(s){if(this.ended)return;let e=s instanceof Uint8Array||s instanceof ArrayBuffer?E(s):s,t=this.replay;if(e.start!==t.frames)throw new u(`Live update starts at frame ${e.start}, but the replay has ${t.frames}.`);Object.assign(t,{map:e.map||t.map,server:e.server||t.server,protocol:e.protocol||t.protocol,tickRate:e.tickRate||t.tickRate,hz:e.hz||t.hz});let r=Math.max(e.players.length,t.players.length);R(t.players,e.players.length>=t.players.length?e.players:[...e.players,...t.players.slice(e.players.length)]),R(t.weapons,e.weapons),this.grow(t.frames+e.frames,r);let a=t.frames,o=e.frames,h=e.players.length;if(this.ticksBuf.set(e.ticks,a),this.bombBuf.set(e.bombPos,a*3),h===r)this.posBuf.set(e.pos,a*r*4),this.stateBuf.set(e.state,a*r*4);else for(let i=0;i<o;i++)this.posBuf.set(e.pos.subarray(i*h*4,(i+1)*h*4),(a+i)*r*4),this.stateBuf.set(e.state.subarray(i*h*4,(i+1)*h*4),(a+i)*r*4);if(t.frames=a+o,t.ticks=this.ticksBuf.subarray(0,t.frames),t.pos=this.posBuf.subarray(0,t.frames*r*4),t.state=this.stateBuf.subarray(0,t.frames*r*4),t.bombPos=this.bombBuf.subarray(0,t.frames*3),e.rounds&&d(t.rounds,e.rounds),e.kills&&d(t.kills,e.kills),e.bomb&&d(t.bomb,e.bomb),e.shots){let i=t.shots??={tick:[],p:[],w:[],yaw:[],pitch:[]};for(let l of["tick","p","w","yaw","pitch"])d(i[l],{from:e.shots.from,items:e.shots[l]})}if(e.hurts){let i=t.hurts??={tick:[],victim:[],attacker:[],dmg:[],hit:[]};for(let l of["tick","victim","attacker","dmg","hit"])d(i[l],{from:e.hurts.from,items:e.hurts[l]})}for(let i of e.grenades??[]){let{i:l,pathFrom:p,path:c,voxels:y,...v}=i,f=t.grenades[l]??={...v,path:[]};Object.assign(f,v),f.path.length=Math.min(f.path.length,p*3);for(let k of c)f.path.push(k);y&&(f.voxels=y)}for(let i=0;i<t.grenades.length;i++)t.grenades[i]??={type:"",thrower:-1,start:0,path:[]};this.revision++,this.emit("update",{frames:t.frames,revision:this.revision}),e.final&&this.endOnFinal&&this.end("over")}end(s,e){this.ended||(this.ended=!0,this.endReason=s,this.error=e??null,this.emit("end",{reason:s,...e?{error:e}:{}}))}grow(s,e){let t=this.replay;if(s<=this.cap&&e===this.stride)return;let r=Math.max(s,this.cap<s?Math.ceil(Math.max(256,this.cap*1.5,s)):this.cap),a=new Int32Array(r),o=new Float32Array(r*3);a.set(this.ticksBuf.subarray(0,t.frames)),o.set(this.bombBuf.subarray(0,t.frames*3));let h=new Float32Array(r*e*4),i=new Uint8Array(r*e*4),l=this.stride;if(l===e)h.set(this.posBuf.subarray(0,t.frames*e*4)),i.set(this.stateBuf.subarray(0,t.frames*e*4));else if(l>0)for(let p=0;p<t.frames;p++)h.set(this.posBuf.subarray(p*l*4,(p+1)*l*4),p*e*4),i.set(this.stateBuf.subarray(p*l*4,(p+1)*l*4),p*e*4);Object.assign(this,{cap:r,ticksBuf:a,bombBuf:o,posBuf:h,stateBuf:i,stride:e})}};function R(n,s){if(n!==s){n.length=0;for(let e of s)n.push(e)}}function d(n,s){n.length=Math.min(n.length,s.from);for(let e of s.items)n.push(e)}export{m as a,x as b,b as c,g as d,A as e,E as f,L as g,_ as h};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{b as tt}from"./chunk-VSIECNZM.js";import*as S from"three";var u=32,z=20*.0254,j=6,V=7.6,ct=2,nt=30,ut=12,H=n=>{let t=0;for(let e=0;e<10;e++)t|=(n>>3*e&1)<<e;return t},T=(n,t,e)=>(e*u+t)*u+n;function lt(n){if(n.length<6||n[1]!==3)return null;let t=new DataView(n.buffer,n.byteOffset,n.byteLength),e=n[2],a=3;if(a+e*8+2>n.length)return null;let r=[];for(let i=0;i<e;i++,a+=8)n[a+3]>0&&n[a]<u&&n[a+1]<u&&n[a+2]<u&&r.push([n[a],n[a+1],n[a+2]]);let o=t.getUint16(a,!0);if(a+=2,a+o*10>n.length)return null;let c=new Uint8Array(u*u*u).fill(2);for(let i=0;i<o;i++,a+=10){let f=t.getUint16(a,!0),p=H(f)*4,M=H(f>>1)*4,g=H(f>>2)*4,y=t.getUint32(a+2,!0),b=t.getUint32(a+6,!0);for(let m=0;m<64;m++){let s=m<32?y>>>m&1:b>>>m-32&1,l=p+H(m),h=M+H(m>>1),d=g+H(m>>2);l<u&&h<u&&d<u&&(c[T(l,h,d)]=s)}}return{seeds:r,solid:c}}var K=class{k=[];v=[];get size(){return this.k.length}push(t,e){let a=this.k,r=this.v,o=a.length;for(a.push(t),r.push(e);o>0;){let c=o-1>>1;if(a[c]<=t)break;a[o]=a[c],r[o]=r[c],o=c}a[o]=t,r[o]=e}pop(){let t=this.k,e=this.v,a=[t[0],e[0]],r=t.pop(),o=e.pop(),c=t.length;if(c){let i=0;for(;;){let f=2*i+1;if(f>=c||(f+1<c&&t[f+1]<t[f]&&f++,t[f]>=r))break;t[i]=t[f],e[i]=e[f],i=f}t[i]=r,e[i]=o}return a}},rt=[];for(let n=-1;n<=1;n++)for(let t=-1;t<=1;t++)for(let e=-1;e<=1;e++)(e||t||n)&&rt.push([e,t,n,Math.hypot(e,t,n)]);function O(n,t,e,a){let r=new Float32Array(u*u*u).fill(1/0),o=new K;for(let c of t)!n(c)||r[c]===0||(r[c]=0,o.push(0,c));for(;o.size;){let[c,i]=o.pop();if(c>r[i])continue;let f=i%u,p=(i/u|0)%u,M=i/(u*u)|0;for(let[g,y,b,m]of rt){let s=f+g,l=p+y,h=M+b;if(s<0||l<0||h<0||s>=u||l>=u||h>=u)continue;let d=T(s,l,h);if(!n(d)||(g&&y||g&&b||y&&b)&&(g&&!n(T(f+g,p,M))||y&&!n(T(f,p+y,M))||b&&!n(T(f,p,M+b))))continue;let x=c+(b>0?m*a:m);x<r[d]&&x<=e&&(r[d]=x,o.push(x,d))}}return r}function yt(n,t){let e=n.solid,a=s=>e[s]===0,r=n.seeds.map(([s,l,h])=>T(s,l,h)),o=O(a,r,V,ct),c=s=>o[s]<=V,i=-1,f=1/0;for(let s=0;s<o.length;s++){if(!c(s))continue;let l=s%u,h=(s/u|0)%u,d=s/(u*u)|0,x=(l-15.5)**2+(h-15.5)**2+(d-16)**2*2;x<f&&(f=x,i=s)}let p=i>=0?O(c,[i],40,1):new Float32Array(o.length).fill(1/0),M=new Uint8Array(u*u*u*2),g=[u,u,u],y=[0,0,0],b=0;for(let s=0;s<u;s++)for(let l=0;l<u;l++)for(let h=0;h<u;h++){let d=T(h,l,s),x=((s*u+h)*u+l)*2,E=o[d];if(!(E<=V)){M[x]=255,M[x+1]=255;continue}M[x]=Math.min(254,Math.round(E*nt)),M[x+1]=Math.min(254,Math.round(Math.min(p[d],21)*ut)),E<=j&&b++;let A=[l,h,s];for(let R=0;R<3;R++)g[R]=Math.min(g[R],A[R]),y[R]=Math.max(y[R],A[R]+1)}let m=u/2*z;return{min:t.clone().subScalar(m),data:M,cells:b,lo:g,hi:y}}var mt=6,et=n=>Math.min(255,Math.round(Math.sqrt(Math.max(0,n)/mt)*255));function ft(n){if(n===255)return 0;let t=n/nt,e=j-1.2,a=j+.1,r=Math.min(1,Math.max(0,(t-e)/(a-e)));return 1-r*r*(3-2*r)}function Mt(n,t){let e=u,a=new Float32Array(e*e*e);for(let b=0;b<a.length;b++)a[b]=ft(n.data[b*2]);let r=(b,m,s)=>b<0||m<0||s<0||b>=e||m>=e||s>=e?0:a[(s*e+m)*e+b],o=(b,m,s)=>{let l=Math.floor(b),h=Math.floor(m),d=Math.floor(s),x=b-l,E=m-h,A=s-d,R=r(l,h,d)*(1-x)+r(l+1,h,d)*x,k=r(l,h+1,d)*(1-x)+r(l+1,h+1,d)*x,L=r(l,h,d+1)*(1-x)+r(l+1,h,d+1)*x,I=r(l,h+1,d+1)*(1-x)+r(l+1,h+1,d+1)*x;return(R*(1-E)+k*E)*(1-A)+(L*(1-E)+I*E)*A},c=new S.Vector3(t.x,t.z,t.y).normalize(),i=Math.SQRT1_2,f=[[0,0,1,.4],[i,0,i,.15],[-i,0,i,.15],[0,i,i,.15],[0,-i,i,.15]],p=.5,M=18,g=(b,m,s,l,h,d)=>{let x=0;for(let E=1;E<=M;E++)x+=o(b+l*E*p,m+h*E*p,s+d*E*p);return x*p*z},y=new Uint8Array(e*e*e*2);for(let b=Math.max(0,n.lo[2]-1);b<Math.min(e,n.hi[2]+1);b++)for(let m=Math.max(0,n.lo[1]-1);m<Math.min(e,n.hi[1]+1);m++)for(let s=Math.max(0,n.lo[0]-1);s<Math.min(e,n.hi[0]+1);s++){let l=(b*e+m)*e+s;if(n.data[l*2]===255)continue;y[l*2]=et(g(s,m,b,c.x,c.y,c.z));let h=0;for(let[d,x,E,A]of f)h+=g(s,m,b,d,x,E)*A;y[l*2+1]=et(h)}return y}function Et(n){let e=O(r=>n[r]===0,[T(16,16,16),T(15,15,16),T(16,15,16),T(15,16,16)],7,1),a=[];for(let r=16;r<=21;r++)for(let o=11;o<=20;o++)for(let c=11;c<=20;c++){if((c+o+r)%2)continue;((c-15.5)/4.6)**2+((o-15.5)/4.6)**2+((r-16)/6)**2<=1&&e[T(c,o,r)]<=7&&a.push([c,o,r])}return{seeds:a,solid:n}}function gt(n){return n.grenades.some(t=>tt(t.type)==="smoke"&&t.effectAt&&t.effectPos&&!(t.voxels&<(ht(t.voxels.data))?.seeds.length))}function bt(n){let t=n.material;return!t.transparent&&!(t.alphaTest>0)}function Rt(n,t){let e=new Uint8Array(u*u*u),a=u/2*z,r=t.clone().subScalar(a),o=t.clone().addScalar(a),c=new S.Box3(r,o),i=new S.Vector3,f=new S.Vector3,p=new S.Vector3,M=z*.45;return n.updateMatrixWorld(),n.traverse(g=>{let y=g;if(!y.isMesh||!y.visible||!bt(y))return;let b=y.geometry,m=b.attributes.position,s=b.index;if(!m?.array||s&&!s.array||(b.boundingBox??b.computeBoundingBox(),!b.boundingBox.clone().applyMatrix4(y.matrixWorld).intersectsBox(c)))return;let h=s?s.count:m.count,d=y.matrixWorld,x=d.equals(new S.Matrix4),E=m.array,A=s?.array;for(let R=0;R<h;R+=3){let k=A?A[R]:R,L=A?A[R+1]:R+1,I=A?A[R+2]:R+2,N=E[k*3],q=E[L*3],G=E[I*3];if(x){if(Math.max(N,q,G)<r.x||Math.min(N,q,G)>o.x)continue;let v=E[k*3+2],P=E[L*3+2],w=E[I*3+2];if(Math.max(v,P,w)<r.z||Math.min(v,P,w)>o.z)continue}if(i.fromBufferAttribute(m,k),f.fromBufferAttribute(m,L),p.fromBufferAttribute(m,I),x||(i.applyMatrix4(d),f.applyMatrix4(d),p.applyMatrix4(d)),Math.max(i.y,f.y,p.y)<r.y||Math.min(i.y,f.y,p.y)>o.y)continue;let X=f.x-i.x,Q=f.y-i.y,$=f.z-i.z,J=p.x-i.x,Y=p.y-i.y,Z=p.z-i.z,ot=Math.max(Math.hypot(X,Q,$),Math.hypot(J,Y,Z)),B=Math.min(400,Math.max(1,Math.ceil(ot/M)));for(let v=0;v<=B;v++)for(let P=0;P<=B-v;P++){let w=v/B,D=P/B,it=i.x+X*w+J*D,at=i.y+Q*w+Y*D,st=i.z+$*w+Z*D,C=Math.floor((st-r.z)/z),_=Math.floor((it-r.x)/z),F=Math.floor((at-r.y)/z);C<0||_<0||F<0||C>=u||_>=u||F>=u||(e[T(C,_,F)]=1)}}}),e}function ht(n){let t=atob(n),e=new Uint8Array(t.length);for(let a=0;a<t.length;a++)e[a]=t.charCodeAt(a);return e}import*as U from"three";var pt=7,W=class{constructor(t,e,a){this.data=t;this.step=e;this.bounds=a;this.nx=Math.round((a[2]-a[0])/e)+2;for(let r=0;r<t.length;r+=pt){let o=this.key(Math.round((t[r]-a[0])/e),Math.round((t[r+2]-a[1])/e)),c=this.cells.get(o);c||this.cells.set(o,c=[]),c.push(r)}}data;step;bounds;cells=new Map;nx;key(t,e){return e*this.nx+t}floorIn(t,e,a){let r=this.cells.get(this.key(t,e));if(!r)return-1;let o=-1,c=1/0;for(let i of r){let f=a-this.data[i+1],p=f>=-.6?Math.abs(f):10-f;f<3&&p<c&&(c=p,o=i)}return o}sample(t,e){let a=(t.x-this.bounds[0])/this.step,r=(t.z-this.bounds[1])/this.step,o=Math.floor(a),c=Math.floor(r),i=a-o,f=r-c,p=0,M=0,g=0,y=0,b=0;for(let m=0;m<2;m++)for(let s=0;s<2;s++){let l=this.floorIn(o+s,c+m,t.y);if(l<0)continue;let h=(s?i:1-i)*(m?f:1-f)+1e-4;M+=this.data[l+3]*h,g+=this.data[l+4]*h,y+=this.data[l+5]*h,b+=this.data[l+6]*h,p+=h}if(p===0)for(let m=-2;m<=2&&p===0;m++)for(let s=-2;s<=2;s++){let l=this.floorIn(o+s,c+m,t.y);if(!(l<0)){M=this.data[l+3],g=this.data[l+4],y=this.data[l+5],b=this.data[l+6],p=1;break}}return p===0?!1:(e.ambient.setRGB(M/p,g/p,y/p),e.sun=b/p,!0)}};function Tt(n,t,e){return new W(new Float32Array(n),t,e)}var dt=U.ShaderChunk.lights_fragment_begin.replace("getDirectionalLightInfo( directionalLight, directLight );",`getDirectionalLightInfo( directionalLight, directLight );
|
|
2
|
+
directLight.color *= cs2ProbeSun;`);function St(n){let t={ambient:new U.Color(.25,.25,.25),sun:1,spec:1},e={cs2ProbeAmbient:{value:t.ambient},cs2ProbeSun:{value:1},cs2ProbeSpec:{value:1}};Object.defineProperty(t,"sun",{get:()=>e.cs2ProbeSun.value,set:o=>e.cs2ProbeSun.value=o}),Object.defineProperty(t,"spec",{get:()=>e.cs2ProbeSpec.value,set:o=>e.cs2ProbeSpec.value=o});let a=new Map,r=o=>{if(!o.isMeshStandardMaterial)return o;let i=a.get(o);if(i)return i;i=o.clone();let f=o.onBeforeCompile,p=o.customProgramCacheKey();return i.onBeforeCompile=(M,g)=>{f.call(i,M,g),Object.assign(M.uniforms,e),M.fragmentShader=M.fragmentShader.replace("#include <common>",`#include <common>
|
|
3
|
+
uniform vec3 cs2ProbeAmbient;
|
|
4
|
+
uniform float cs2ProbeSun;
|
|
5
|
+
uniform float cs2ProbeSpec;`).replace("#include <lights_fragment_begin>",dt).replace("#include <lights_fragment_maps>",`{
|
|
6
|
+
// Probe ambient: floor irradiance, a little stronger on up-facing normals.
|
|
7
|
+
vec3 cs2Wn = inverseTransformDirection( normal, viewMatrix );
|
|
8
|
+
irradiance = cs2ProbeAmbient * PI * ( 0.7 + 0.3 * cs2Wn.y );
|
|
9
|
+
}
|
|
10
|
+
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
11
|
+
radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ) * cs2ProbeSpec;
|
|
12
|
+
#endif`)},i.customProgramCacheKey=()=>`${p}|cs2probe`,a.set(o,i),i};return n.traverse(o=>{let c=o;c.isMesh&&(c.material=Array.isArray(c.material)?c.material.map(r):r(c.material))}),t}export{u as a,z as b,j as c,nt as d,ut as e,lt as f,yt as g,mt as h,Mt as i,Et as j,gt as k,bt as l,Rt as m,ht as n,Tt as o,St as p};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as x}from"./chunk-YJG3LSSB.js";var I=h=>h.end<0?1/0:h.end,Y={"Smoke Grenade":"smoke",Flashbang:"flash","HE Grenade":"he",Molotov:"fire","Incendiary Grenade":"fire","Decoy Grenade":"decoy"},D=h=>Y[h]??"other",O=120,L=1.5,_=.5,Z={smoke:20,fire:7,decoy:15},ee=(h,T,n)=>h+(((T-h)%360+540)%360-180)*n;function $(h){let T=Math.max(0,h);return`${Math.floor(T/60)}:${String(Math.floor(T%60)).padStart(2,"0")}`}function te(h,T={}){let n=h,H=T.roundTime??115,U=T.bombTime??40,q=T.killFeedSeconds??6,b=0,p=0,S=n.hz,z=new Int16Array(0),C=new Int32Array(0),E=[],G=new Int32Array(0);function N(){let a=b===n.players.length?Math.min(p,n.frames):0;b=n.players.length,p=n.frames,S=n.hz,z=new Int16Array(p).fill(-1),n.rounds.forEach((e,r)=>z.fill(r,e.start,n.rounds[r+1]?.start??p));let t=new Int32Array(p*b);a>0&&t.set(C.subarray(0,a*b));for(let e=a;e<p;e++)for(let r=0;r<b;r++){let o=e*b+r;t[o]=n.state[o*4+1]&x.Alive?e:e?t[o-b]:-1}C=t,E=n.bomb.filter(e=>e.event==="plant"),G=new Int32Array(n.grenades.length),n.grenades.forEach((e,r)=>{let o=e.effectAt??0;if(!o)return;let l=e.effectEnd||o+Math.round((Z[D(e.type)]??0)*S);G[r]=Math.min(l,Math.max(o,n.rounds.find(s=>s.start>o)?.start??l))})}N();let P=a=>Math.max(0,Math.min(p-1,a)),K=a=>p?z[P(Math.floor(a))]:-1,R=(a,t)=>n.state[(P(a)*b+t)*4+1]&x.CT?"CT":"T",w=(a,t)=>p?(n.ticks[P(t)]-n.ticks[P(a)])/n.tickRate:0;function F(a,t){return E.find(e=>e.f>=a.live&&e.f<=t&&e.f<=I(a)+1)}function j(a){let t=K(a);if(t<0)return{phase:"",text:"",remaining:0};let e=n.rounds[t];if(e.live<0||a<e.live)return{phase:"freeze",text:"freeze",remaining:0};if(a>I(e))return{phase:"over",text:"round over",remaining:0};let r=F(e,a);if(r){let l=Math.max(0,U-w(r.f,a));return{phase:"bomb",text:`C4 ${$(l)}`,remaining:l}}let o=Math.max(0,H-w(e.live,a));return{phase:"live",text:$(o),remaining:o}}let B=(a,t)=>{let e=(a*b+t)*4;return{x:n.pos[e],y:n.pos[e+1],z:n.pos[e+2]}};function J(a,t,e,r){let o=[];for(let l=0;l<b;l++){let s=(a*b+l)*4,m=(t*b+l)*4,i=n.state[s+1],f=(i&x.Alive)!==0,y=n.pos[s],u=n.pos[s+1],k=n.pos[s+2],v=n.pos[s+3];if(f&&n.state[m+1]&x.Alive){let g=n.pos[m]-y,M=n.pos[m+1]-u,c=n.pos[m+2]-k;g*g+M*M+c*c<O*O&&(y+=g*e,u+=M*e,k+=c*e),v=ee(v,n.pos[m+3],e)}let A=null,d=C[a*b+l];!f&&r&&d>=r.start&&(A={...B(d,l),side:R(d,l),frame:d+1}),o.push({index:l,name:n.players[l].name,steamId:n.players[l].steamId,side:i&x.CT?"CT":"T",present:n.pos[s]!==0||n.pos[s+1]!==0,alive:f,x:y,y:u,z:k,yaw:v,hp:n.state[s],armor:n.state[s+3],weapon:n.weapons[n.state[s+2]]??"",ducking:(i&x.Duck)!==0,blind:(i&x.Blind)!==0,hasBomb:(i&x.Bomb)!==0,defusing:(i&x.Defusing)!==0,scoped:(i&x.Scoped)!==0,hasKit:(i&x.Kit)!==0,death:A})}return o}function Q(a,t,e){let r=t.path.length/3,o=t.effectAt??0,l=o>0?Math.min(o,t.start+r-1):t.start+r-1,s=D(t.type),m=s==="flash"||s==="he",i=G[a]||o,f=r>0&&e>=t.start&&e<=l,y=o>0&&e>=o&&e<=(m?o+_*S:i),u=r>0&&e>=t.start&&e<=l+L*S;if(!f&&!y&&!u)return null;let k=Math.max(0,Math.min(r-1,e-t.start)),v=null;if(f){let d=Math.floor(k),g=Math.min(r-1,d+1),M=k-d,c=t.path;v={x:c[d*3]+(c[g*3]-c[d*3])*M,y:c[d*3+1]+(c[g*3+1]-c[d*3+1])*M,z:c[d*3+2]+(c[g*3+2]-c[d*3+2])*M}}let A=null;if(y&&t.effectPos){let d=(e-o)/S,[g,M,c]=t.effectPos;A={kind:s,x:g,y:M,z:c,age:d,remaining:Math.max(0,(i-e)/S),burst:m?Math.min(1,d/_):0}}return{index:a,kind:s,thrower:t.thrower,throwerSide:t.thrower>=0?R(t.start,t.thrower):null,projectile:v,trail:u?{path:t.path,count:Math.min(Math.floor(k)+1,l-t.start+1),fade:e>l?1-(e-l)/(L*S):1}:null,effect:A}}function V(a,t,e,r){let o=n.bombPos[a*3],l=n.bombPos[a*3+1],s=n.bombPos[a*3+2],m=r.findIndex(u=>u.hasBomb),i={x:o,y:l,z:s,carrier:m,site:null,sincePlant:0};if(m>=0)return{...i,state:"carried",x:r[m].x,y:r[m].y,z:r[m].z};if(o===0&&l===0||!e||t.phase==="freeze"||t.phase==="")return{...i,state:"hidden"};let f=F(e,a);if(!f)return{...i,state:"dropped"};let y=n.bomb.find(u=>u.event!=="plant"&&u.f>=f.f&&u.f<=a&&u.f<=I(e)+1);return{...i,site:f.site??null,state:y?y.event==="defuse"?"defused":"exploded":"planted",sincePlant:w(f.f,a)}}function W(a,t){let e=[];for(let r of n.kills){if(r.f>a)break;if(r.f<=a-q*S)continue;let o=Math.max(0,r.f-1),l=r.killer<0||r.killer===r.victim;e.push({...r,age:(t-r.f)/S,killerName:r.killer>=0?n.players[r.killer]?.name??null:null,victimName:n.players[r.victim]?.name??"",killerSide:r.killer>=0?R(o,r.killer):null,victimSide:R(o,r.victim),killerPos:l?null:B(o,r.killer),victimPos:B(o,r.victim)})}return e}function X(a){if(!p)return{t:0,frame:0,roundIndex:-1,round:null,clock:{phase:"",text:"",remaining:0},score:{t:0,ct:0,teamT:"T",teamCT:"CT"},players:[],grenades:[],kills:[],bomb:{state:"hidden",x:0,y:0,z:0,carrier:-1,site:null,sincePlant:0}};let t=Math.max(0,Math.min(p-1,a)),e=Math.floor(t),r=Math.min(p-1,e+1),o=t-e,l=K(e),s=l>=0?n.rounds[l]:null,m=j(e),i=J(e,r,o,s),f=[];for(let u=0;u<n.grenades.length;u++){let k=n.grenades[u];if(k.start>t)continue;let v=Q(u,k,t);v&&f.push(v)}let y=s!==null&&e>I(s);return{t,frame:e,roundIndex:l,round:s,clock:m,score:{t:(s?.scoreT??0)+(y&&s?.winner==="T"?1:0),ct:(s?.scoreCT??0)+(y&&s?.winner==="CT"?1:0),teamT:s?.teamT||"T",teamCT:s?.teamCT||"CT"},players:i,grenades:f,bomb:V(e,m,s,i),kills:W(e,t)}}return{replay:h,get frames(){return p},get hz(){return S},get roundOf(){return z},get plants(){return E},get effectEnds(){return G},roundAt:K,sideAt:R,seconds:w,clock:j,snapshot:X,refresh:N}}export{I as a,D as b,ee as c,$ as d,te as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var T={Alive:1,CT:2,Duck:4,Blind:8,Bomb:16,Defusing:32,Scoped:64,Kit:128},w=1,o=class extends Error{name="ReplayFormatError"},m=(e,r)=>e.length>=r.length&&r.every((n,i)=>e[i]===n),x=e=>m(e,[67,83,82,80]),A=e=>m(e,[80,66,68,69,77,83,50,0]),g=e=>m(e,[31,139]);function U(e){let r=e instanceof Uint8Array?e:new Uint8Array(e);if(!x(r))throw A(r)?new o("This is a CS2 demo, not a replay: parse it with parseDemo() or openReplay() from @matchomag/cs2-replay/parse."):new o("Not a replay file.");r.byteOffset%4!==0&&(r=r.slice());let{buffer:n,byteOffset:i}=r,u=new DataView(n,i,r.byteLength),y=u.getUint32(4,!0);if(y>w)throw new o(`Replay format version ${y} is newer than this viewer supports (${w}).`);let b=u.getUint32(8,!0);if(12+b>r.byteLength)throw new o("Replay file is truncated.");let t=JSON.parse(new TextDecoder().decode(r.subarray(12,12+b))),a=t.frames??0,f=t.players??[],c=f.length,s=t.offsets??{},d=(s.bomb??0)+a*3*4;if(a>0&&d>r.byteLength)throw new o("Replay file is truncated.");let p=(l,h,R)=>new l(n,i+h,R);return{version:y,map:t.map??"",server:t.server??"",protocol:t.protocol??0,tickRate:t.tickRate||64,hz:t.hz||16,frames:a,players:f,weapons:t.weapons??[""],rounds:t.rounds??[],kills:t.kills??[],grenades:(t.grenades??[]).map(l=>({...l,path:l.path??[]})),bomb:t.bomb??[],...t.shots?{shots:t.shots}:{},...t.hurts?{hurts:t.hurts}:{},ticks:a?p(Int32Array,s.ticks,a):new Int32Array(0),pos:a?p(Float32Array,s.pos,a*c*4):new Float32Array(0),state:a?p(Uint8Array,s.state,a*c*4):new Uint8Array(0),bombPos:a?p(Float32Array,s.bomb,a*3):new Float32Array(0)}}async function v(e){let r=new Blob([e]).stream().pipeThrough(new DecompressionStream("gzip"));return new Uint8Array(await new Response(r).arrayBuffer())}async function k(e,r){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Blob)return new Uint8Array(await e.arrayBuffer());let n=e instanceof Response?e:await fetch(e,r);if(!n.ok)throw new Error(`Couldn't load the replay: HTTP ${n.status}`);return new Uint8Array(await n.arrayBuffer())}async function B(e,r){let n=await k(e,r);return g(n)&&(n=await v(n)),U(n)}export{T as a,w as b,o as c,x as d,A as e,g as f,U as g,v as h,k as i,B as j};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var y=["low","medium","high"];async function k(t){let e=await fetch(t,{cache:"no-cache"});if(!e.ok)throw new Error(`${e.status} ${t}`);let a=await e.json(),n=e.url||t;for(let s of Object.values(a.maps))for(let c of Object.values(s.builds))c.manifest&&(c.manifest=new URL(c.manifest,n).href),c.greybox&&(c.greybox.file=new URL(c.greybox.file,n).href);return a}function S(t,e,a,n={}){let s=n.date===void 0?void 0:P(n.date),c=Object.hasOwn(t.maps,e)?t.maps[e]:void 0;if(!c)return null;let r=a==="game"?i=>!!i.manifest:i=>!!i.greybox,o=Object.entries(c.builds).filter(([,i])=>r(i)).map(([i,f])=>({id:i,build:f}));if(!o.length)return null;let u=n.build?o.find(i=>i.id===n.build):void 0;if(u)return u;if(n.protocol&&n.protocol>0){let i=B(o,f=>b(f.patch),n.protocol);if(i)return i}if(s!==void 0){let i=B(o,f=>f.released??f.created,s);if(i)return i}return o.find(i=>i.id===c.latest)??o.reduce((i,f)=>w(f,i,b(f.build.patch)??0,b(i.build.patch)??0)>0?f:i)}function T(t,e,a={}){return S(t,e,"game",a)?.build.manifest??null}function R(t,e,a={}){return S(t,e,"greybox",a)?.build.greybox?.file??null}function b(t){let e=t?Number(t.replace(/\./g,"")):NaN;return Number.isFinite(e)?e:void 0}function w(t,e,a,n){return a!==n?a<n?-1:1:t.build.created<e.build.created?-1:t.build.created>e.build.created?1:0}function B(t,e,a){let n,s;for(let c of t){let r=e(c.build);r!==void 0&&(r<=a&&(!n||w(c,n[1],r,n[0])>0)&&(n=[r,c]),(!s||w(c,s[1],r,s[0])<0)&&(s=[r,c]))}return(n??s)?.[1]}function P(t){let e;if(typeof t=="string"){let a=/^(\d{4})-(\d{2})-(\d{2})/.exec(t);e=a&&new Date(Date.UTC(+a[1],+a[2]-1,+a[3])).toISOString().startsWith(a[0])?t.length===10?new Date(`${t}T00:00:00Z`):new Date(t):new Date(NaN)}else e=t;if(Number.isNaN(e.getTime()))throw new RangeError(`not a date: ${String(t)}`);return e.toISOString().slice(0,10)}async function F(t,e){let a=new URL(t,location.href).href,n=e?await e.fetch(a):await(await v(a)).arrayBuffer(),s=JSON.parse(new TextDecoder().decode(n));if(s.format!=="cs2-game-map")throw new Error(`${t}: not a cs2-game-map manifest`);return s.url=a,s}function g(t,e,a){let n=t.tiers[e];if(!n)throw new Error(`${t.map}: no ${e} tier`);let s=t.url??location.href,c=i=>new URL(i,s).href,r=new Map,o=(i,f,l)=>r.has(i)||r.set(i,{url:i,bytes:f,kind:l});o(c(t.geometry.file),t.geometry.bytes,"geometry");for(let i of t.shared)o(c(i.file),i.bytes,"shared");let u=a==="bc"?t.lightmaps.bc[n.lightmaps]:t.lightmaps.compat;for(let i of Object.values(u??{}))i&&o(c(i.file),i.bytes,"lightmap");for(let[,i,f]of n.textures)o(c(`${t.textureBase}${i}.ktx2`),f,"texture");return[...r.values()]}function O(){let t=navigator,e=t.userAgentData?.mobile??(/Android|iPhone|iPad|iPod|Mobile/i.test(t.userAgent)||/Macintosh/.test(t.userAgent)&&t.maxTouchPoints>1),a=t.deviceMemory,n=null;try{n=document.createElement("canvas").getContext("webgl2")}catch{n=null}if(!n)return{webgl2:!1,bc:!1,lightmaps:"compat",mobile:e,renderer:"",deviceMemory:a,tiers:[],recommended:null};let s=!!n.getExtension("EXT_texture_compression_bptc")&&!!n.getExtension("WEBGL_compressed_texture_s3tc"),c=n.getExtension("WEBGL_debug_renderer_info"),r=String(n.getParameter(c?c.UNMASKED_RENDERER_WEBGL:n.RENDERER)??"");return n.getExtension("WEBGL_lose_context")?.loseContext(),{webgl2:!0,bc:s,lightmaps:s?"bc":"compat",mobile:e,renderer:r,deviceMemory:a,tiers:s?["low","medium","high"]:["low","medium"],recommended:"low"}}var G=class t{constructor(e){this.cache=e}cache;full=!1;onFull=null;static async open(e="cs2-game-maps"){try{return typeof caches>"u"?null:new t(await caches.open(e))}catch{return null}}async fetch(e,a){let n=await this.cache.match(e).catch(()=>{});if(n){let r=await n.arrayBuffer();return a?.(r.byteLength),r}let s=await v(e),c=await E(s,a);if(!this.full)try{await this.cache.put(e,new Response(c,{headers:{"Content-Type":s.headers.get("Content-Type")??"application/octet-stream"}}))}catch(r){L(r)?(this.full=!0,this.onFull?.()):console.warn(`cs2-replay: couldn't store ${e}: ${r}`)}return c}async storage(){let e=navigator.storage,a=await e?.estimate?.().catch(()=>{}),n=await e?.persisted?.().catch(()=>!1)??!1,s=a?.quota!=null&&a.usage!=null?Math.max(0,a.quota-a.usage):void 0;return{quota:a?.quota,usage:a?.usage,free:s,persisted:n}}async persist(){return await navigator.storage?.persist?.().catch(()=>!1)??!1}async status(e,a,n){let s=await this.cachedUrls(),c=0,r=0;for(let i of g(e,a,n))c+=i.bytes,s.has(i.url)&&(r+=i.bytes);let{free:o}=await this.storage(),u=c-r;return{totalBytes:c,cachedBytes:r,missingBytes:u,freeBytes:o,fits:o===void 0?null:u*1.05<o}}async list(){let e=await this.cachedUrls(),a=await this.manifests(e),n=new Map,s=r=>{let o=new Set;for(let u of y)if(r.tiers[u])for(let i of["bc","compat"])for(let f of g(r,u,i))o.add(f.url);return o},c=a.map(r=>s(r));for(let r of c)for(let o of r)n.set(o,(n.get(o)??0)+1);return a.map((r,o)=>{let u={};for(let l of y){if(!r.tiers[l])continue;let d={cachedBytes:0,totalBytes:0,complete:!1};for(let x of["bc","compat"]){if(x==="compat"&&!r.tiers[l].compat)continue;let p=0,m=0;for(let h of g(r,l,x))p+=h.bytes,e.has(h.url)&&(m+=h.bytes);(m>d.cachedBytes||m===d.cachedBytes&&p>d.totalBytes)&&(d={cachedBytes:m,totalBytes:p,complete:m===p})}u[l]=d}let i=0,f=M(r);for(let l of c[o])n.get(l)===1&&e.has(l)&&(i+=f.get(l)??0);return{map:r.map,build:r.build,patch:r.patch,manifestUrl:r.url,tiers:u,ownBytes:i}})}async remove(e){let a=await this.cachedUrls(),n=await this.manifests(a),s=n.find(o=>o.url===e);if(!s)return await this.cache.delete(e),0;let c=new Set;for(let o of n)if(o!==s)for(let u of M(o).keys())c.add(u);let r=0;for(let[o,u]of M(s))c.has(o)||!a.has(o)||(await this.cache.delete(o),r+=u);return await this.cache.delete(e),r}async clear(){for(let e of await this.cache.keys())await this.cache.delete(e);this.full=!1}async cachedUrls(){return new Set((await this.cache.keys()).map(e=>e.url))}async manifests(e){let a=[];for(let n of e)if(/\/manifest\.json(\?|$)/.test(n))try{let s=JSON.parse(await(await this.cache.match(n)).text());if(s.format!=="cs2-game-map")continue;s.url=n,a.push(s)}catch{}return a}};function M(t){let e=new Map;for(let a of y)if(t.tiers[a])for(let n of["bc","compat"])for(let s of g(t,a,n))e.set(s.url,s.bytes);return e}async function v(t){let e=await fetch(t,{mode:"cors",credentials:"omit"});if(!e.ok)throw new Error(`${e.status} ${t}`);return e}async function E(t,e){if(!t.body||!e){let o=await t.arrayBuffer();return e?.(o.byteLength),o}let a=t.body.getReader(),n=[],s=0;for(;;){let{done:o,value:u}=await a.read();if(o)break;n.push(u),s+=u.byteLength,e(u.byteLength)}let c=new Uint8Array(s),r=0;for(let o of n)c.set(o,r),r+=o.byteLength;return c.buffer}function L(t){return t instanceof DOMException&&(t.name==="QuotaExceededError"||t.code===22)}function $(t){return t>=1e9?`${(t/1e9).toFixed(1)} GB`:t>=1e6?`${Math.round(t/1e6)} MB`:`${Math.max(1,Math.round(t/1e3))} KB`}export{y as a,k as b,S as c,T as d,R as e,F as f,g,O as h,G as i,E as j,$ as k};
|