@cloudflare/realtimekit-virtual-background 0.0.1 → 0.0.2-staging.2

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.
Files changed (30) hide show
  1. package/README.md +149 -0
  2. package/dist/index.cjs.js +231 -0
  3. package/dist/index.es.js +4266 -0
  4. package/dist/index.iife.js +231 -0
  5. package/favicon.svg +15 -0
  6. package/package.json +25 -5
  7. package/types/ImageBackgroundTransformer.d.ts +9 -0
  8. package/types/SimpleBackgroundTransformer.d.ts +9 -0
  9. package/types/client/RealtimeKitVideoBackgroundTransformer.d.ts +49 -0
  10. package/types/common/BackgroundTransformer.d.ts +10 -0
  11. package/types/core/helpers/backgroundHelper.d.ts +6 -0
  12. package/types/core/helpers/postProcessingHelper.d.ts +12 -0
  13. package/types/core/helpers/renderingPipelineHelper.d.ts +6 -0
  14. package/types/core/helpers/segmentationHelper.d.ts +16 -0
  15. package/types/core/helpers/sourceHelper.d.ts +11 -0
  16. package/types/core/hooks/useTFLite.d.ts +21 -0
  17. package/types/index.d.ts +2 -0
  18. package/types/pipelines/canvas2d/canvas2dPipeline.d.ts +11 -0
  19. package/types/pipelines/helpers/webglHelper.d.ts +18 -0
  20. package/types/pipelines/webgl2/backgroundBlurStage.d.ts +7 -0
  21. package/types/pipelines/webgl2/backgroundImageStage.d.ts +10 -0
  22. package/types/pipelines/webgl2/jointBilateralFilterStage.d.ts +7 -0
  23. package/types/pipelines/webgl2/loadSegmentationStage.d.ts +6 -0
  24. package/types/pipelines/webgl2/resizingStage.d.ts +7 -0
  25. package/types/pipelines/webgl2/softmaxStage.d.ts +6 -0
  26. package/types/pipelines/webgl2/webgl2Pipeline.d.ts +11 -0
  27. package/types/tflite/tflite-simd.d.ts +2 -0
  28. package/types/tflite/tflite.d.ts +2 -0
  29. package/types/utils/browser.d.ts +3 -0
  30. package/types/utils/image.d.ts +2 -0
@@ -0,0 +1,231 @@
1
+ var vt=(G,X,ee)=>{if(!X.has(G))throw TypeError("Cannot "+ee)};var O=(G,X,ee)=>(vt(G,X,"read from private field"),ee?ee.call(G):X.get(G)),ge=(G,X,ee)=>{if(X.has(G))throw TypeError("Cannot add the same private member more than once");X instanceof WeakSet?X.add(G):X.set(G,ee)},de=(G,X,ee,ue)=>(vt(G,X,"write to private field"),ue?ue.call(G,ee):X.set(G,ee),ee);var RealtimeKitVideoBackgroundTransformer=function(){var Q,ve,$,be,we,ye;"use strict";class G{constructor(){this.createCameraVideoElement=async r=>{const e=r,{height:i,width:s}=e.getSettings();if(i===void 0||s===void 0)throw Error("Background removal can't commence as Height and Width of the video feed is undefined");const c=document.createElement("video");c.width=s,c.height=i,c.srcObject=new MediaStream([e]),c.autoplay=!0,c.muted=!0,c.playsInline=!0,c.controls=!0;try{await c.play()}catch{console.warn("RealtimeKitVideoBackgroundTransformer:: Couldn't play raw video feed in detached mode")}return c}}}const X=t=>new Promise((r,e)=>{const i=new Image;i.onload=()=>r(i),i.onerror=e,i.src=t,i.crossOrigin="anonymous"}),ee=t=>new Promise((r,e)=>{const i=document.createElement("canvas"),s=i.getContext("2d");i.width=t.videoWidth,i.height=t.videoHeight,s.drawImage(t,0,0,i.width,i.height);const c=new Image;c.onload=()=>r(c),c.onerror=e,c.src=i.toDataURL("image/jpeg"),c.crossOrigin="anonymous"}),ue={"640x360":[640,360],"256x256":[256,256],"256x144":[256,144],"160x96":[160,96]};function bt(t,r){switch(t){case"meet":return r==="256x144"?"segm_full_v679":"segm_lite_v681";case"mlkit":return"selfiesegmentation_mlkit-256x256-2021_01_19-v1215.f16";default:throw new Error(`No TFLite file for this segmentation model: ${t}`)}}const oe=String.raw;function pe(t,r,e,i,s){const c=wt(t,r,e),f=t.getAttribLocation(c,"a_position");t.enableVertexAttribArray(f),t.bindBuffer(t.ARRAY_BUFFER,i),t.vertexAttribPointer(f,2,t.FLOAT,!1,0,0);const p=t.getAttribLocation(c,"a_texCoord");return t.enableVertexAttribArray(p),t.bindBuffer(t.ARRAY_BUFFER,s),t.vertexAttribPointer(p,2,t.FLOAT,!1,0,0),c}function wt(t,r,e){const i=t.createProgram();if(t.attachShader(i,r),t.attachShader(i,e),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS))throw new Error(`Could not link WebGL program: ${t.getProgramInfoLog(i)}`);return i}function se(t,r,e){const i=t.createShader(r);if(t.shaderSource(i,e),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS))throw new Error(`Could not compile shader: ${t.getShaderInfoLog(i)}`);return i}function me(t,r,e,i,s=t.NEAREST,c=t.NEAREST){const f=t.createTexture();return t.bindTexture(t.TEXTURE_2D,f),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,c),t.texStorage2D(t.TEXTURE_2D,1,r,e,i),f}async function yt(t,r,e,i,s,c,f,p,l){const m=r.createBuffer();return r.bindBuffer(r.PIXEL_PACK_BUFFER,m),r.bufferData(r.PIXEL_PACK_BUFFER,l.byteLength,r.STREAM_READ),r.readPixels(e,i,s,c,f,p,0),r.bindBuffer(r.PIXEL_PACK_BUFFER,null),await Et(t,r,r.PIXEL_PACK_BUFFER,m,0,l),r.deleteBuffer(m),l}async function Et(t,r,e,i,s,c,f,p){const l=r.fenceSync(r.SYNC_GPU_COMMANDS_COMPLETE,0);r.flush();const m=await Rt(t,r,l);r.deleteSync(l),m!==r.WAIT_FAILED&&(r.bindBuffer(e,i),r.getBufferSubData(e,s,c,f,p),r.bindBuffer(e,null))}function Rt(t,r,e){return new Promise(i=>{function s(){const c=r.clientWaitSync(e,0,0);if(c===r.WAIT_FAILED){i(c);return}if(c===r.TIMEOUT_EXPIRED){t.setTimeout(s,0);return}i(c)}t.setTimeout(s,0)})}function Mt(t,r,e,i,s,c,f){const p=St(t,r,e,i,s,c,f),l=At(t,e,i,c);function m(){p.render(),l.render()}function h(w){l.updateCoverage(w)}function u(){l.cleanUp(),p.cleanUp()}return{render:m,updateCoverage:h,cleanUp:u}}function St(t,r,e,i,s,c,f){const p=oe`#version 300 es
2
+
3
+ precision highp float;
4
+
5
+ uniform sampler2D u_inputFrame;
6
+ uniform sampler2D u_personMask;
7
+ uniform vec2 u_texelSize;
8
+ uniform float u_blurAmount;
9
+
10
+ in vec2 v_texCoord;
11
+
12
+ out vec4 outColor;
13
+
14
+ const float offset[5] = float[](0.0, 1.0, 2.0, 3.0, 4.0);
15
+ const float weight[5] = float[](0.2270270270, 0.1945945946, 0.1216216216,
16
+ 0.0540540541, 0.0162162162);
17
+
18
+ void main() {
19
+ vec4 centerColor = texture(u_inputFrame, v_texCoord);
20
+ float personMask = texture(u_personMask, v_texCoord).a;
21
+
22
+ vec4 frameColor = centerColor * weight[0] * (1.0 - personMask);
23
+
24
+ for (int i = 1; i < 5; i++) {
25
+ vec2 offset = vec2(offset[i]) * u_texelSize * u_blurAmount;
26
+
27
+ vec2 texCoord = v_texCoord + offset;
28
+ frameColor += texture(u_inputFrame, texCoord) * weight[i] *
29
+ (1.0 - texture(u_personMask, texCoord).a);
30
+
31
+ texCoord = v_texCoord - offset;
32
+ frameColor += texture(u_inputFrame, texCoord) * weight[i] *
33
+ (1.0 - texture(u_personMask, texCoord).a);
34
+ }
35
+ outColor = vec4(frameColor.rgb + (1.0 - frameColor.a) * centerColor.rgb, 1.0);
36
+ }
37
+ `,l=.5,m=c.width*l,h=c.height*l,u=1/m,w=1/h,E=se(t,t.FRAGMENT_SHADER,p),_=pe(t,r,E,e,i),R=t.getUniformLocation(_,"u_inputFrame"),b=t.getUniformLocation(_,"u_personMask"),T=t.getUniformLocation(_,"u_texelSize"),U=t.getUniformLocation(_,"u_blurAmount"),W=me(t,t.RGBA8,m,h,t.NEAREST,t.LINEAR),j=me(t,t.RGBA8,m,h,t.NEAREST,t.LINEAR),C=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,C),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,W,0);const B=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,B),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,j,0),t.useProgram(_);const x=Math.max(0,Math.min(f.blurLength/10,10));t.uniform1f(U,x),t.uniform1i(b,1);function q(){t.viewport(0,0,m,h),t.useProgram(_),t.uniform1i(R,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,s);for(let N=0;N<3;N++)t.uniform2f(T,0,w),t.bindFramebuffer(t.FRAMEBUFFER,C),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,W),t.uniform1i(R,2),t.uniform2f(T,u,0),t.bindFramebuffer(t.FRAMEBUFFER,B),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.bindTexture(t.TEXTURE_2D,j)}function H(){t.deleteFramebuffer(B),t.deleteFramebuffer(C),t.deleteTexture(j),t.deleteTexture(W),t.deleteProgram(_),t.deleteShader(E)}return{render:q,cleanUp:H}}function At(t,r,e,i){const s=oe`#version 300 es
38
+
39
+ in vec2 a_position;
40
+ in vec2 a_texCoord;
41
+
42
+ out vec2 v_texCoord;
43
+
44
+ void main() {
45
+ // Flipping Y is required when rendering to canvas
46
+ gl_Position = vec4(a_position * vec2(1.0, -1.0), 0.0, 1.0);
47
+ v_texCoord = a_texCoord;
48
+ }
49
+ `,c=oe`#version 300 es
50
+
51
+ precision highp float;
52
+
53
+ uniform sampler2D u_inputFrame;
54
+ uniform sampler2D u_personMask;
55
+ uniform sampler2D u_blurredInputFrame;
56
+ uniform vec2 u_coverage;
57
+
58
+ in vec2 v_texCoord;
59
+
60
+ out vec4 outColor;
61
+
62
+ void main() {
63
+ vec3 color = texture(u_inputFrame, v_texCoord).rgb;
64
+ vec3 blurredColor = texture(u_blurredInputFrame, v_texCoord).rgb;
65
+ float personMask = texture(u_personMask, v_texCoord).a;
66
+ personMask = smoothstep(u_coverage.x, u_coverage.y, personMask);
67
+ outColor = vec4(mix(blurredColor, color, personMask), 1.0);
68
+ }
69
+ `,{width:f,height:p}=i,l=se(t,t.VERTEX_SHADER,s),m=se(t,t.FRAGMENT_SHADER,c),h=pe(t,l,m,r,e),u=t.getUniformLocation(h,"u_inputFrame"),w=t.getUniformLocation(h,"u_personMask"),E=t.getUniformLocation(h,"u_blurredInputFrame"),_=t.getUniformLocation(h,"u_coverage");t.useProgram(h),t.uniform1i(u,0),t.uniform1i(w,1),t.uniform1i(E,2),t.uniform2f(_,0,1);function R(){t.viewport(0,0,f,p),t.useProgram(h),t.bindFramebuffer(t.FRAMEBUFFER,null),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function b(U){t.useProgram(h),t.uniform2f(_,U[0],U[1])}function T(){t.deleteProgram(h),t.deleteShader(m),t.deleteShader(l)}return{render:R,updateCoverage:b,cleanUp:T}}function Ft(t,r,e,i,s,c,f){const p=oe`#version 300 es
70
+
71
+ uniform vec2 u_backgroundScale;
72
+ uniform vec2 u_backgroundOffset;
73
+
74
+ in vec2 a_position;
75
+ in vec2 a_texCoord;
76
+
77
+ out vec2 v_texCoord;
78
+ out vec2 v_backgroundCoord;
79
+
80
+ void main() {
81
+ // Flipping Y is required when rendering to canvas
82
+ gl_Position = vec4(a_position * vec2(1.0, -1.0), 0.0, 1.0);
83
+ v_texCoord = a_texCoord;
84
+ v_backgroundCoord = a_texCoord * u_backgroundScale + u_backgroundOffset;
85
+ }
86
+ `,l=oe`#version 300 es
87
+
88
+ precision highp float;
89
+
90
+ uniform sampler2D u_inputFrame;
91
+ uniform sampler2D u_personMask;
92
+ uniform sampler2D u_background;
93
+ uniform vec2 u_coverage;
94
+ uniform float u_lightWrapping;
95
+ uniform float u_blendMode;
96
+
97
+ in vec2 v_texCoord;
98
+ in vec2 v_backgroundCoord;
99
+
100
+ out vec4 outColor;
101
+
102
+ vec3 screen(vec3 a, vec3 b) {
103
+ return 1.0 - (1.0 - a) * (1.0 - b);
104
+ }
105
+
106
+ vec3 linearDodge(vec3 a, vec3 b) {
107
+ return a + b;
108
+ }
109
+
110
+ void main() {
111
+ vec3 frameColor = texture(u_inputFrame, v_texCoord).rgb;
112
+ vec3 backgroundColor = texture(u_background, v_backgroundCoord).rgb;
113
+ float personMask = texture(u_personMask, v_texCoord).a;
114
+ float lightWrapMask = 1.0 - max(0.0, personMask - u_coverage.y) / (1.0 - u_coverage.y);
115
+ vec3 lightWrap = u_lightWrapping * lightWrapMask * backgroundColor;
116
+ frameColor = u_blendMode * linearDodge(frameColor, lightWrap) +
117
+ (1.0 - u_blendMode) * screen(frameColor, lightWrap);
118
+ personMask = smoothstep(u_coverage.x, u_coverage.y, personMask);
119
+ outColor = vec4(frameColor * personMask + backgroundColor * (1.0 - personMask), 1.0);
120
+ }
121
+ `,{width:m,height:h}=c,u=m/h,w=se(t,t.VERTEX_SHADER,p),E=se(t,t.FRAGMENT_SHADER,l),_=pe(t,w,E,r,e),R=t.getUniformLocation(_,"u_backgroundScale"),b=t.getUniformLocation(_,"u_backgroundOffset"),T=t.getUniformLocation(_,"u_inputFrame"),U=t.getUniformLocation(_,"u_personMask"),W=t.getUniformLocation(_,"u_background"),j=t.getUniformLocation(_,"u_coverage"),C=t.getUniformLocation(_,"u_lightWrapping"),B=t.getUniformLocation(_,"u_blendMode");t.useProgram(_),t.uniform2f(R,1,1),t.uniform2f(b,0,0),t.uniform1i(T,0),t.uniform1i(U,1),t.uniform2f(j,0,1),t.uniform1f(C,0),t.uniform1f(B,0);let x=null;s!=null&&s.complete?H(s):s&&(s.onload=()=>{H(s)});function q(){t.viewport(0,0,m,h),t.useProgram(_),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,i),x!==null&&(t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,x),t.uniform1i(W,2)),t.bindFramebuffer(t.FRAMEBUFFER,null),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function H(F){x=me(t,t.RGBA8,F.naturalWidth,F.naturalHeight,t.LINEAR,t.LINEAR),t.texSubImage2D(t.TEXTURE_2D,0,0,0,F.naturalWidth,F.naturalHeight,t.RGBA,t.UNSIGNED_BYTE,F);let te=0,re=0,J=F.naturalWidth,ne=F.naturalHeight;J/ne<u?(ne=J/u,re=(F.naturalHeight-ne)/2):(J=ne*u,te=(F.naturalWidth-J)/2);const K=J/F.naturalWidth,Ee=ne/F.naturalHeight;te/=F.naturalWidth,re/=F.naturalHeight,t.uniform2f(R,K,Ee),t.uniform2f(b,te,re)}function N(F){t.useProgram(_),t.uniform2f(j,F[0],F[1])}function A(F){t.useProgram(_),t.uniform1f(C,F)}function L(F){t.useProgram(_),t.uniform1f(B,F==="screen"?0:1)}function ae(){t.deleteTexture(x),t.deleteProgram(_),t.deleteShader(E),t.deleteShader(w)}return{render:q,updateCoverage:N,updateLightWrapping:A,updateBlendMode:L,cleanUp:ae}}function Tt(t,r,e,i,s,c,f,p){const l=oe`#version 300 es
122
+
123
+ precision highp float;
124
+
125
+ uniform sampler2D u_inputFrame;
126
+ uniform sampler2D u_segmentationMask;
127
+ uniform vec2 u_texelSize;
128
+ uniform float u_step;
129
+ uniform float u_radius;
130
+ uniform float u_offset;
131
+ uniform float u_sigmaTexel;
132
+ uniform float u_sigmaColor;
133
+
134
+ in vec2 v_texCoord;
135
+
136
+ out vec4 outColor;
137
+
138
+ float gaussian(float x, float sigma) {
139
+ float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);
140
+ return exp((x * x) * coeff);
141
+ }
142
+
143
+ void main() {
144
+ vec2 centerCoord = v_texCoord;
145
+ vec3 centerColor = texture(u_inputFrame, centerCoord).rgb;
146
+ float newVal = 0.0;
147
+
148
+ float spaceWeight = 0.0;
149
+ float colorWeight = 0.0;
150
+ float totalWeight = 0.0;
151
+
152
+ // Subsample kernel space.
153
+ for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {
154
+ for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {
155
+ vec2 shift = vec2(j, i) * u_texelSize;
156
+ vec2 coord = vec2(centerCoord + shift);
157
+ vec3 frameColor = texture(u_inputFrame, coord).rgb;
158
+ float outVal = texture(u_segmentationMask, coord).a;
159
+
160
+ spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);
161
+ colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);
162
+ totalWeight += spaceWeight * colorWeight;
163
+
164
+ newVal += spaceWeight * colorWeight * outVal;
165
+ }
166
+ }
167
+ newVal /= totalWeight;
168
+
169
+ outColor = vec4(vec3(0.0), newVal);
170
+ }
171
+ `,[m,h]=ue[c.inputResolution],{width:u,height:w}=p,E=1/u,_=1/w,R=se(t,t.FRAGMENT_SHADER,l),b=pe(t,r,R,e,i),T=t.getUniformLocation(b,"u_inputFrame"),U=t.getUniformLocation(b,"u_segmentationMask"),W=t.getUniformLocation(b,"u_texelSize"),j=t.getUniformLocation(b,"u_step"),C=t.getUniformLocation(b,"u_radius"),B=t.getUniformLocation(b,"u_offset"),x=t.getUniformLocation(b,"u_sigmaTexel"),q=t.getUniformLocation(b,"u_sigmaColor"),H=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,H),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,f,0),t.useProgram(b),t.uniform1i(T,0),t.uniform1i(U,1),t.uniform2f(W,E,_),A(0),L(0);function N(){t.viewport(0,0,u,w),t.useProgram(b),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,s),t.bindFramebuffer(t.FRAMEBUFFER,H),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function A(F){F*=Math.max(u/m,w/h);const te=.66,J=Math.max(1,Math.sqrt(F)*te),ne=F,V=J>1?J*.5:0,K=Math.max(E,_)*F;t.useProgram(b),t.uniform1f(j,J),t.uniform1f(C,ne),t.uniform1f(B,V),t.uniform1f(x,K)}function L(F){t.useProgram(b),t.uniform1f(q,F)}function ae(){t.deleteFramebuffer(H),t.deleteProgram(b),t.deleteShader(R)}return{render:N,updateSigmaSpace:A,updateSigmaColor:L,cleanUp:ae}}function xt(t,r,e,i,s,c,f){const p=oe`#version 300 es
172
+
173
+ precision highp float;
174
+
175
+ uniform sampler2D u_inputSegmentation;
176
+
177
+ in vec2 v_texCoord;
178
+
179
+ out vec4 outColor;
180
+
181
+ void main() {
182
+ float segmentation = texture(u_inputSegmentation, v_texCoord).r;
183
+ outColor = vec4(vec3(0.0), segmentation);
184
+ }
185
+ `,l=c._getOutputMemoryOffset()/4,[m,h]=ue[s.inputResolution],u=se(t,t.FRAGMENT_SHADER,p),w=pe(t,r,u,e,i),E=t.getUniformLocation(w,"u_inputSegmentation"),_=me(t,t.R32F,m,h),R=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,R),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,f,0),t.useProgram(w),t.uniform1i(E,1);function b(){t.viewport(0,0,m,h),t.useProgram(w),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,_),t.texSubImage2D(t.TEXTURE_2D,0,0,0,m,h,t.RED,t.FLOAT,c.HEAPF32,l),t.bindFramebuffer(t.FRAMEBUFFER,R),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function T(){t.deleteFramebuffer(R),t.deleteTexture(_),t.deleteProgram(w),t.deleteShader(u)}return{render:b,cleanUp:T}}function Ct(t,r,e,i,s,c,f){const p=oe`#version 300 es
186
+
187
+ precision highp float;
188
+
189
+ uniform sampler2D u_inputFrame;
190
+
191
+ in vec2 v_texCoord;
192
+
193
+ out vec4 outColor;
194
+
195
+ void main() {
196
+ outColor = texture(u_inputFrame, v_texCoord);
197
+ }
198
+ `,l=f._getInputMemoryOffset()/4,[m,h]=ue[c.inputResolution],u=m*h,w=se(r,r.FRAGMENT_SHADER,p),E=pe(r,e,w,i,s),_=r.getUniformLocation(E,"u_inputFrame"),R=me(r,r.RGBA8,m,h),b=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,b),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,R,0);const T=new Uint8Array(u*4);r.useProgram(E),r.uniform1i(_,0);async function U(){r.viewport(0,0,m,h),r.useProgram(E),r.bindFramebuffer(r.FRAMEBUFFER,b),r.drawArrays(r.TRIANGLE_STRIP,0,4);const j=yt(t,r,0,0,m,h,r.RGBA,r.UNSIGNED_BYTE,T);c.deferInputResizing||await j;for(let C=0;C<u;C++){const B=l+C*3,x=C*4;f.HEAPF32[B]=T[x]/255,f.HEAPF32[B+1]=T[x+1]/255,f.HEAPF32[B+2]=T[x+2]/255}}function W(){r.deleteFramebuffer(b),r.deleteTexture(R),r.deleteProgram(E),r.deleteShader(w)}return{render:U,cleanUp:W}}function Bt(t,r,e,i,s,c,f){const p=oe`#version 300 es
199
+
200
+ precision highp float;
201
+
202
+ uniform sampler2D u_inputSegmentation;
203
+
204
+ in vec2 v_texCoord;
205
+
206
+ out vec4 outColor;
207
+
208
+ void main() {
209
+ vec2 segmentation = texture(u_inputSegmentation, v_texCoord).rg;
210
+ float shift = max(segmentation.r, segmentation.g);
211
+ float backgroundExp = exp(segmentation.r - shift);
212
+ float personExp = exp(segmentation.g - shift);
213
+ outColor = vec4(vec3(0.0), personExp / (backgroundExp + personExp));
214
+ }
215
+ `,l=c._getOutputMemoryOffset()/4,[m,h]=ue[s.inputResolution],u=se(t,t.FRAGMENT_SHADER,p),w=pe(t,r,u,e,i),E=t.getUniformLocation(w,"u_inputSegmentation"),_=me(t,t.RG32F,m,h),R=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,R),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,f,0),t.useProgram(w),t.uniform1i(E,1);function b(){t.viewport(0,0,m,h),t.useProgram(w),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,_),t.texSubImage2D(t.TEXTURE_2D,0,0,0,m,h,t.RG,t.FLOAT,c.HEAPF32,l),t.bindFramebuffer(t.FRAMEBUFFER,R),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function T(){t.deleteFramebuffer(R),t.deleteTexture(_),t.deleteProgram(w),t.deleteShader(u)}return{render:b,cleanUp:T}}function pt(t,r,e,i,s,c){const f=oe`#version 300 es
216
+
217
+ in vec2 a_position;
218
+ in vec2 a_texCoord;
219
+
220
+ out vec2 v_texCoord;
221
+
222
+ void main() {
223
+ gl_Position = vec4(a_position, 0.0, 1.0);
224
+ v_texCoord = a_texCoord;
225
+ }
226
+ `,{width:p,height:l}=t,[m,h]=ue[e.inputResolution],u=i.getContext("webgl2"),w=se(u,u.VERTEX_SHADER,f),E=u.createVertexArray();u.bindVertexArray(E);const _=u.createBuffer();u.bindBuffer(u.ARRAY_BUFFER,_),u.bufferData(u.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),u.STATIC_DRAW);const R=u.createBuffer();u.bindBuffer(u.ARRAY_BUFFER,R),u.bufferData(u.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),u.STATIC_DRAW);const b=u.createTexture();u.bindTexture(u.TEXTURE_2D,b),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST);const T=me(u,u.RGBA8,m,h),U=me(u,u.RGBA8,p,l),W=Ct(c,u,w,_,R,e,s),j=e.model==="meet"?Bt(u,w,_,R,e,s,T):xt(u,w,_,R,e,s,T),C=Tt(u,w,_,R,T,e,U,i),B=r.type==="blur"?Mt(u,w,_,R,U,i,r):Ft(u,_,R,U,r.backgroundImage,i);async function x(){u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,b),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,t.htmlElement),u.bindVertexArray(E),await W.render(),s._runInference(),j.render(),C.render(),B.render()}function q(N){if(C.updateSigmaSpace(N.jointBilateralFilter.sigmaSpace),C.updateSigmaColor(N.jointBilateralFilter.sigmaColor),r.type==="image"){const A=B;A.updateCoverage(N.coverage),A.updateLightWrapping(N.lightWrapping),A.updateBlendMode(N.blendMode)}else if(r.type==="blur")B.updateCoverage(N.coverage);else{const A=B;A.updateCoverage([0,.9999]),A.updateLightWrapping(0)}}function H(){B.cleanUp(),C.cleanUp(),j.cleanUp(),W.cleanUp(),u.deleteTexture(U),u.deleteTexture(T),u.deleteTexture(b),u.deleteBuffer(R),u.deleteBuffer(_),u.deleteVertexArray(E),u.deleteShader(w)}return{render:x,updatePostProcessingConfig:q,cleanUp:H}}const Pt={"Amazon Silk":"amazon_silk","Android Browser":"android",Bada:"bada",BlackBerry:"blackberry",Chrome:"chrome",Chromium:"chromium",Electron:"electron",Epiphany:"epiphany",Firefox:"firefox",Focus:"focus",Generic:"generic","Google Search":"google_search",Googlebot:"googlebot","Internet Explorer":"ie","K-Meleon":"k_meleon",Maxthon:"maxthon","Microsoft Edge":"edge","MZ Browser":"mz","NAVER Whale Browser":"naver",Opera:"opera","Opera Coast":"opera_coast",PhantomJS:"phantomjs",Puffin:"puffin",QupZilla:"qupzilla",QQ:"qq",QQLite:"qqlite",Safari:"safari",Sailfish:"sailfish","Samsung Internet for Android":"samsung_internet",SeaMonkey:"seamonkey",Sleipnir:"sleipnir",Swing:"swing",Tizen:"tizen","UC Browser":"uc",Vivaldi:"vivaldi","WebOS Browser":"webos",WeChat:"wechat","Yandex Browser":"yandex",Roku:"roku"},ht={amazon_silk:"Amazon Silk",android:"Android Browser",bada:"Bada",blackberry:"BlackBerry",chrome:"Chrome",chromium:"Chromium",electron:"Electron",epiphany:"Epiphany",firefox:"Firefox",focus:"Focus",generic:"Generic",googlebot:"Googlebot",google_search:"Google Search",ie:"Internet Explorer",k_meleon:"K-Meleon",maxthon:"Maxthon",edge:"Microsoft Edge",mz:"MZ Browser",naver:"NAVER Whale Browser",opera:"Opera",opera_coast:"Opera Coast",phantomjs:"PhantomJS",puffin:"Puffin",qupzilla:"QupZilla",qq:"QQ Browser",qqlite:"QQ Browser Lite",safari:"Safari",sailfish:"Sailfish",samsung_internet:"Samsung Internet for Android",seamonkey:"SeaMonkey",sleipnir:"Sleipnir",swing:"Swing",tizen:"Tizen",uc:"UC Browser",vivaldi:"Vivaldi",webos:"WebOS Browser",wechat:"WeChat",yandex:"Yandex Browser"},D={tablet:"tablet",mobile:"mobile",desktop:"desktop",tv:"tv"},z={WindowsPhone:"Windows Phone",Windows:"Windows",MacOS:"macOS",iOS:"iOS",Android:"Android",WebOS:"WebOS",BlackBerry:"BlackBerry",Bada:"Bada",Tizen:"Tizen",Linux:"Linux",ChromeOS:"Chrome OS",PlayStation4:"PlayStation 4",Roku:"Roku"},le={EdgeHTML:"EdgeHTML",Blink:"Blink",Trident:"Trident",Presto:"Presto",Gecko:"Gecko",WebKit:"WebKit"};class a{static getFirstMatch(r,e){const i=e.match(r);return i&&i.length>0&&i[1]||""}static getSecondMatch(r,e){const i=e.match(r);return i&&i.length>1&&i[2]||""}static matchAndReturnConst(r,e,i){if(r.test(e))return i}static getWindowsVersionName(r){switch(r){case"NT":return"NT";case"XP":return"XP";case"NT 5.0":return"2000";case"NT 5.1":return"XP";case"NT 5.2":return"2003";case"NT 6.0":return"Vista";case"NT 6.1":return"7";case"NT 6.2":return"8";case"NT 6.3":return"8.1";case"NT 10.0":return"10";default:return}}static getMacOSVersionName(r){const e=r.split(".").splice(0,2).map(i=>parseInt(i,10)||0);if(e.push(0),e[0]===10)switch(e[1]){case 5:return"Leopard";case 6:return"Snow Leopard";case 7:return"Lion";case 8:return"Mountain Lion";case 9:return"Mavericks";case 10:return"Yosemite";case 11:return"El Capitan";case 12:return"Sierra";case 13:return"High Sierra";case 14:return"Mojave";case 15:return"Catalina";default:return}}static getAndroidVersionName(r){const e=r.split(".").splice(0,2).map(i=>parseInt(i,10)||0);if(e.push(0),!(e[0]===1&&e[1]<5)){if(e[0]===1&&e[1]<6)return"Cupcake";if(e[0]===1&&e[1]>=6)return"Donut";if(e[0]===2&&e[1]<2)return"Eclair";if(e[0]===2&&e[1]===2)return"Froyo";if(e[0]===2&&e[1]>2)return"Gingerbread";if(e[0]===3)return"Honeycomb";if(e[0]===4&&e[1]<1)return"Ice Cream Sandwich";if(e[0]===4&&e[1]<4)return"Jelly Bean";if(e[0]===4&&e[1]>=4)return"KitKat";if(e[0]===5)return"Lollipop";if(e[0]===6)return"Marshmallow";if(e[0]===7)return"Nougat";if(e[0]===8)return"Oreo";if(e[0]===9)return"Pie"}}static getVersionPrecision(r){return r.split(".").length}static compareVersions(r,e,i=!1){const s=a.getVersionPrecision(r),c=a.getVersionPrecision(e);let f=Math.max(s,c),p=0;const l=a.map([r,e],m=>{const h=f-a.getVersionPrecision(m),u=m+new Array(h+1).join(".0");return a.map(u.split("."),w=>new Array(20-w.length).join("0")+w).reverse()});for(i&&(p=f-Math.min(s,c)),f-=1;f>=p;){if(l[0][f]>l[1][f])return 1;if(l[0][f]===l[1][f]){if(f===p)return 0;f-=1}else if(l[0][f]<l[1][f])return-1}}static map(r,e){const i=[];let s;if(Array.prototype.map)return Array.prototype.map.call(r,e);for(s=0;s<r.length;s+=1)i.push(e(r[s]));return i}static find(r,e){let i,s;if(Array.prototype.find)return Array.prototype.find.call(r,e);for(i=0,s=r.length;i<s;i+=1){const c=r[i];if(e(c,i))return c}}static assign(r,...e){const i=r;let s,c;if(Object.assign)return Object.assign(r,...e);for(s=0,c=e.length;s<c;s+=1){const f=e[s];typeof f=="object"&&f!==null&&Object.keys(f).forEach(l=>{i[l]=f[l]})}return r}static getBrowserAlias(r){return Pt[r]}static getBrowserTypeByAlias(r){return ht[r]||""}}const P=/version\/(\d+(\.?_?\d+)+)/i,kt=[{test:[/googlebot/i],describe(t){const r={name:"Googlebot"},e=a.getFirstMatch(/googlebot\/(\d+(\.\d+))/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/opera/i],describe(t){const r={name:"Opera"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/opr\/|opios/i],describe(t){const r={name:"Opera"},e=a.getFirstMatch(/(?:opr|opios)[\s/](\S+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/SamsungBrowser/i],describe(t){const r={name:"Samsung Internet for Android"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/Whale/i],describe(t){const r={name:"NAVER Whale Browser"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/MZBrowser/i],describe(t){const r={name:"MZ Browser"},e=a.getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/focus/i],describe(t){const r={name:"Focus"},e=a.getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/swing/i],describe(t){const r={name:"Swing"},e=a.getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/coast/i],describe(t){const r={name:"Opera Coast"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/opt\/\d+(?:.?_?\d+)+/i],describe(t){const r={name:"Opera Touch"},e=a.getFirstMatch(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/yabrowser/i],describe(t){const r={name:"Yandex Browser"},e=a.getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/ucbrowser/i],describe(t){const r={name:"UC Browser"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/Maxthon|mxios/i],describe(t){const r={name:"Maxthon"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/epiphany/i],describe(t){const r={name:"Epiphany"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/puffin/i],describe(t){const r={name:"Puffin"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/sleipnir/i],describe(t){const r={name:"Sleipnir"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/k-meleon/i],describe(t){const r={name:"K-Meleon"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/micromessenger/i],describe(t){const r={name:"WeChat"},e=a.getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/qqbrowser/i],describe(t){const r={name:/qqbrowserlite/i.test(t)?"QQ Browser Lite":"QQ Browser"},e=a.getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/msie|trident/i],describe(t){const r={name:"Internet Explorer"},e=a.getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/\sedg\//i],describe(t){const r={name:"Microsoft Edge"},e=a.getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/edg([ea]|ios)/i],describe(t){const r={name:"Microsoft Edge"},e=a.getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/vivaldi/i],describe(t){const r={name:"Vivaldi"},e=a.getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/seamonkey/i],describe(t){const r={name:"SeaMonkey"},e=a.getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/sailfish/i],describe(t){const r={name:"Sailfish"},e=a.getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i,t);return e&&(r.version=e),r}},{test:[/silk/i],describe(t){const r={name:"Amazon Silk"},e=a.getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/phantom/i],describe(t){const r={name:"PhantomJS"},e=a.getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/slimerjs/i],describe(t){const r={name:"SlimerJS"},e=a.getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe(t){const r={name:"BlackBerry"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/(web|hpw)[o0]s/i],describe(t){const r={name:"WebOS Browser"},e=a.getFirstMatch(P,t)||a.getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/bada/i],describe(t){const r={name:"Bada"},e=a.getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/tizen/i],describe(t){const r={name:"Tizen"},e=a.getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/qupzilla/i],describe(t){const r={name:"QupZilla"},e=a.getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/firefox|iceweasel|fxios/i],describe(t){const r={name:"Firefox"},e=a.getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/electron/i],describe(t){const r={name:"Electron"},e=a.getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/MiuiBrowser/i],describe(t){const r={name:"Miui"},e=a.getFirstMatch(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/chromium/i],describe(t){const r={name:"Chromium"},e=a.getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/chrome|crios|crmo/i],describe(t){const r={name:"Chrome"},e=a.getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/GSA/i],describe(t){const r={name:"Google Search"},e=a.getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test(t){const r=!t.test(/like android/i),e=t.test(/android/i);return r&&e},describe(t){const r={name:"Android Browser"},e=a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/playstation 4/i],describe(t){const r={name:"PlayStation 4"},e=a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/safari|applewebkit/i],describe(t){const r={name:"Safari"},e=a.getFirstMatch(P,t);return e&&(r.version=e),r}},{test:[/.*/i],describe(t){const r=/^(.*)\/(.*) /,e=/^(.*)\/(.*)[ \t]\((.*)/,s=t.search("\\(")!==-1?e:r;return{name:a.getFirstMatch(s,t),version:a.getSecondMatch(s,t)}}}];var Ot=[{test:[/Roku\/DVP/],describe(t){const r=a.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i,t);return{name:z.Roku,version:r}}},{test:[/windows phone/i],describe(t){const r=a.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i,t);return{name:z.WindowsPhone,version:r}}},{test:[/windows /i],describe(t){const r=a.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i,t),e=a.getWindowsVersionName(r);return{name:z.Windows,version:r,versionName:e}}},{test:[/Macintosh(.*?) FxiOS(.*?)\//],describe(t){const r={name:z.iOS},e=a.getSecondMatch(/(Version\/)(\d[\d.]+)/,t);return e&&(r.version=e),r}},{test:[/macintosh/i],describe(t){const r=a.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i,t).replace(/[_\s]/g,"."),e=a.getMacOSVersionName(r),i={name:z.MacOS,version:r};return e&&(i.versionName=e),i}},{test:[/(ipod|iphone|ipad)/i],describe(t){const r=a.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i,t).replace(/[_\s]/g,".");return{name:z.iOS,version:r}}},{test(t){const r=!t.test(/like android/i),e=t.test(/android/i);return r&&e},describe(t){const r=a.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i,t),e=a.getAndroidVersionName(r),i={name:z.Android,version:r};return e&&(i.versionName=e),i}},{test:[/(web|hpw)[o0]s/i],describe(t){const r=a.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i,t),e={name:z.WebOS};return r&&r.length&&(e.version=r),e}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe(t){const r=a.getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i,t)||a.getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i,t)||a.getFirstMatch(/\bbb(\d+)/i,t);return{name:z.BlackBerry,version:r}}},{test:[/bada/i],describe(t){const r=a.getFirstMatch(/bada\/(\d+(\.\d+)*)/i,t);return{name:z.Bada,version:r}}},{test:[/tizen/i],describe(t){const r=a.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i,t);return{name:z.Tizen,version:r}}},{test:[/linux/i],describe(){return{name:z.Linux}}},{test:[/CrOS/],describe(){return{name:z.ChromeOS}}},{test:[/PlayStation 4/],describe(t){const r=a.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i,t);return{name:z.PlayStation4,version:r}}}],Ut=[{test:[/googlebot/i],describe(){return{type:"bot",vendor:"Google"}}},{test:[/huawei/i],describe(t){const r=a.getFirstMatch(/(can-l01)/i,t)&&"Nova",e={type:D.mobile,vendor:"Huawei"};return r&&(e.model=r),e}},{test:[/nexus\s*(?:7|8|9|10).*/i],describe(){return{type:D.tablet,vendor:"Nexus"}}},{test:[/ipad/i],describe(){return{type:D.tablet,vendor:"Apple",model:"iPad"}}},{test:[/Macintosh(.*?) FxiOS(.*?)\//],describe(){return{type:D.tablet,vendor:"Apple",model:"iPad"}}},{test:[/kftt build/i],describe(){return{type:D.tablet,vendor:"Amazon",model:"Kindle Fire HD 7"}}},{test:[/silk/i],describe(){return{type:D.tablet,vendor:"Amazon"}}},{test:[/tablet(?! pc)/i],describe(){return{type:D.tablet}}},{test(t){const r=t.test(/ipod|iphone/i),e=t.test(/like (ipod|iphone)/i);return r&&!e},describe(t){const r=a.getFirstMatch(/(ipod|iphone)/i,t);return{type:D.mobile,vendor:"Apple",model:r}}},{test:[/nexus\s*[0-6].*/i,/galaxy nexus/i],describe(){return{type:D.mobile,vendor:"Nexus"}}},{test:[/[^-]mobi/i],describe(){return{type:D.mobile}}},{test(t){return t.getBrowserName(!0)==="blackberry"},describe(){return{type:D.mobile,vendor:"BlackBerry"}}},{test(t){return t.getBrowserName(!0)==="bada"},describe(){return{type:D.mobile}}},{test(t){return t.getBrowserName()==="windows phone"},describe(){return{type:D.mobile,vendor:"Microsoft"}}},{test(t){const r=Number(String(t.getOSVersion()).split(".")[0]);return t.getOSName(!0)==="android"&&r>=3},describe(){return{type:D.tablet}}},{test(t){return t.getOSName(!0)==="android"},describe(){return{type:D.mobile}}},{test(t){return t.getOSName(!0)==="macos"},describe(){return{type:D.desktop,vendor:"Apple"}}},{test(t){return t.getOSName(!0)==="windows"},describe(){return{type:D.desktop}}},{test(t){return t.getOSName(!0)==="linux"},describe(){return{type:D.desktop}}},{test(t){return t.getOSName(!0)==="playstation 4"},describe(){return{type:D.tv}}},{test(t){return t.getOSName(!0)==="roku"},describe(){return{type:D.tv}}}],It=[{test(t){return t.getBrowserName(!0)==="microsoft edge"},describe(t){if(/\sedg\//i.test(t))return{name:le.Blink};const e=a.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i,t);return{name:le.EdgeHTML,version:e}}},{test:[/trident/i],describe(t){const r={name:le.Trident},e=a.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test(t){return t.test(/presto/i)},describe(t){const r={name:le.Presto},e=a.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test(t){const r=t.test(/gecko/i),e=t.test(/like gecko/i);return r&&!e},describe(t){const r={name:le.Gecko},e=a.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/(apple)?webkit\/537\.36/i],describe(){return{name:le.Blink}}},{test:[/(apple)?webkit/i],describe(t){const r={name:le.WebKit},e=a.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}}];class _t{constructor(r,e=!1){if(r==null||r==="")throw new Error("UserAgent parameter can't be empty");this._ua=r,this.parsedResult={},e!==!0&&this.parse()}getUA(){return this._ua}test(r){return r.test(this._ua)}parseBrowser(){this.parsedResult.browser={};const r=a.find(kt,e=>{if(typeof e.test=="function")return e.test(this);if(e.test instanceof Array)return e.test.some(i=>this.test(i));throw new Error("Browser's test function is not valid")});return r&&(this.parsedResult.browser=r.describe(this.getUA())),this.parsedResult.browser}getBrowser(){return this.parsedResult.browser?this.parsedResult.browser:this.parseBrowser()}getBrowserName(r){return r?String(this.getBrowser().name).toLowerCase()||"":this.getBrowser().name||""}getBrowserVersion(){return this.getBrowser().version}getOS(){return this.parsedResult.os?this.parsedResult.os:this.parseOS()}parseOS(){this.parsedResult.os={};const r=a.find(Ot,e=>{if(typeof e.test=="function")return e.test(this);if(e.test instanceof Array)return e.test.some(i=>this.test(i));throw new Error("Browser's test function is not valid")});return r&&(this.parsedResult.os=r.describe(this.getUA())),this.parsedResult.os}getOSName(r){const{name:e}=this.getOS();return r?String(e).toLowerCase()||"":e||""}getOSVersion(){return this.getOS().version}getPlatform(){return this.parsedResult.platform?this.parsedResult.platform:this.parsePlatform()}getPlatformType(r=!1){const{type:e}=this.getPlatform();return r?String(e).toLowerCase()||"":e||""}parsePlatform(){this.parsedResult.platform={};const r=a.find(Ut,e=>{if(typeof e.test=="function")return e.test(this);if(e.test instanceof Array)return e.test.some(i=>this.test(i));throw new Error("Browser's test function is not valid")});return r&&(this.parsedResult.platform=r.describe(this.getUA())),this.parsedResult.platform}getEngine(){return this.parsedResult.engine?this.parsedResult.engine:this.parseEngine()}getEngineName(r){return r?String(this.getEngine().name).toLowerCase()||"":this.getEngine().name||""}parseEngine(){this.parsedResult.engine={};const r=a.find(It,e=>{if(typeof e.test=="function")return e.test(this);if(e.test instanceof Array)return e.test.some(i=>this.test(i));throw new Error("Browser's test function is not valid")});return r&&(this.parsedResult.engine=r.describe(this.getUA())),this.parsedResult.engine}parse(){return this.parseBrowser(),this.parseOS(),this.parsePlatform(),this.parseEngine(),this}getResult(){return a.assign({},this.parsedResult)}satisfies(r){const e={};let i=0;const s={};let c=0;if(Object.keys(r).forEach(p=>{const l=r[p];typeof l=="string"?(s[p]=l,c+=1):typeof l=="object"&&(e[p]=l,i+=1)}),i>0){const p=Object.keys(e),l=a.find(p,h=>this.isOS(h));if(l){const h=this.satisfies(e[l]);if(h!==void 0)return h}const m=a.find(p,h=>this.isPlatform(h));if(m){const h=this.satisfies(e[m]);if(h!==void 0)return h}}if(c>0){const p=Object.keys(s),l=a.find(p,m=>this.isBrowser(m,!0));if(l!==void 0)return this.compareVersion(s[l])}}isBrowser(r,e=!1){const i=this.getBrowserName().toLowerCase();let s=r.toLowerCase();const c=a.getBrowserTypeByAlias(s);return e&&c&&(s=c.toLowerCase()),s===i}compareVersion(r){let e=[0],i=r,s=!1;const c=this.getBrowserVersion();if(typeof c=="string")return r[0]===">"||r[0]==="<"?(i=r.substr(1),r[1]==="="?(s=!0,i=r.substr(2)):e=[],r[0]===">"?e.push(1):e.push(-1)):r[0]==="="?i=r.substr(1):r[0]==="~"&&(s=!0,i=r.substr(1)),e.indexOf(a.compareVersions(c,i,s))>-1}isOS(r){return this.getOSName(!0)===String(r).toLowerCase()}isPlatform(r){return this.getPlatformType(!0)===String(r).toLowerCase()}isEngine(r){return this.getEngineName(!0)===String(r).toLowerCase()}is(r,e=!1){return this.isBrowser(r,e)||this.isOS(r)||this.isPlatform(r)}some(r=[]){return r.some(e=>this.is(e))}}/*!
227
+ * Bowser - a browser detector
228
+ * https://github.com/lancedikson/bowser
229
+ * MIT License | (c) Dustin Diaz 2012-2015
230
+ * MIT License | (c) Denis Demchenko 2015-2019
231
+ */class Lt{static getParser(r,e=!1){if(typeof r!="string")throw new Error("UserAgent should be a string");return new _t(r,e)}static parse(r){return new _t(r).getResult()}static get BROWSER_MAP(){return ht}static get ENGINE_MAP(){return le}static get OS_MAP(){return z}static get PLATFORMS_MAP(){return D}}function Ce(){return Lt.getParser(window.navigator.userAgent)}function gt(t,r,e,i,s,c){const f=i.getContext("2d"),[p,l]=ue[e.inputResolution],m=p*l,h=new ImageData(p,l),u=document.createElement("canvas");u.width=p,u.height=l;const w=u.getContext("2d",{willReadFrequently:!0}),E=s._getInputMemoryOffset()/4,_=s._getOutputMemoryOffset()/4;let R,b=null;const T=X("https://assets.dyte.io/backgrounds/blur.jpg");async function U(){b=await ee(t.htmlElement),r.type!=="none"&&C(),r.type!=="none"&&B(),await x()}function W(A){R=A}function j(){}function C(){if(w.drawImage(b,0,0,t.width,t.height,0,0,p,l),e.model==="meet"||e.model==="mlkit"){const A=w.getImageData(0,0,p,l);for(let L=0;L<m;L++)s.HEAPF32[E+L*3]=A.data[L*4]/255,s.HEAPF32[E+L*3+1]=A.data[L*4+1]/255,s.HEAPF32[E+L*3+2]=A.data[L*4+2]/255}}function B(){s._runInference();for(let A=0;A<m;A++)if(e.model==="meet"){const L=s.HEAPF32[_+A*2],ae=s.HEAPF32[_+A*2+1],F=Math.max(L,ae),te=Math.exp(L-F),re=Math.exp(ae-F);h.data[A*4+3]=255*re/(te+re)}else if(e.model==="mlkit"){const L=s.HEAPF32[_+A];h.data[A*4+3]=255*L}w.putImageData(h,0,0)}async function x(){f.globalCompositeOperation="copy",f.filter="none",f.drawImage(b,0,0),R!=null&&R.smoothSegmentationMask&&(r.type==="blur"?f.filter="blur(8px)":r.type==="image"&&(f.filter="blur(4px)")),r.type!=="none"&&(f.globalCompositeOperation="destination-in",f.filter="none",H()),r.type==="blur"?await N():q()}function q(){f.globalCompositeOperation="destination-over",f.drawImage(r.backgroundImage,0,0)}function H(){f.drawImage(u,0,0,p,l,0,0,t.width,t.height)}async function N(){if(f.globalCompositeOperation="destination-over",Ce().getBrowserName()==="Safari"){const A=await T;f.drawImage(A,0,0)}else f.filter=`blur(${r.blurLength}px)`,f.drawImage(b,0,0)}return{render:U,updatePostProcessingConfig:W,cleanUp:j}}const Oe=class extends G{constructor(e){super();ge(this,Q,void 0);ge(this,ve,void 0);de(this,Q,e)}static async init(e){return new Oe(e)}async createStaticBackgroundImageVideoMiddleware(e){const i=await X(e);return async({canvas:s,WorkerTimers:c})=>{const f=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;de(this,ve,f);const p=await this.createCameraVideoElement(O(this,Q).meeting.self.rawVideoTrack);s.width=p.width,s.height=p.height;const m=(O(this,Q).segmentationConfig.pipeline==="canvas2dCpu"?gt:pt)({htmlElement:p,width:O(this,Q).meeting.self.rawVideoTrack.getSettings().width,height:O(this,Q).meeting.self.rawVideoTrack.getSettings().height},{type:"image",backgroundImage:i},O(this,Q).segmentationConfig,s,O(this,Q).tflite,c);m.updatePostProcessingConfig(O(this,Q).postProcessingConfig);const h=1e3/O(this,Q).segmentationConfig.targetFps,u=async()=>{if(f!==O(this,ve)||!O(this,Q).meeting.self.videoEnabled){await m.cleanUp();return}const w=performance.now();await m.render(),c.setTimeout(u,Math.max(0,h-(performance.now()-w)))};c.setTimeout(()=>{u()},0)}}destruct(){de(this,ve,null)}};let Be=Oe;Q=new WeakMap,ve=new WeakMap;const Ue=class extends G{constructor(e){super();ge(this,$,void 0);ge(this,be,void 0);de(this,$,e)}static async init(e){return new Ue(e)}async createBackgroundBlurVideoMiddleware(e){return async({canvas:i,WorkerTimers:s})=>{const c=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;de(this,be,c);const f=await this.createCameraVideoElement(O(this,$).meeting.self.rawVideoTrack);i.width=f.width,i.height=f.height;const l=(O(this,$).segmentationConfig.pipeline==="canvas2dCpu"?gt:pt)({htmlElement:f,width:O(this,$).meeting.self.rawVideoTrack.getSettings().width,height:O(this,$).meeting.self.rawVideoTrack.getSettings().height},{type:"blur",blurLength:e},O(this,$).segmentationConfig,i,O(this,$).tflite,s);l.updatePostProcessingConfig(O(this,$).postProcessingConfig);const m=1e3/O(this,$).segmentationConfig.targetFps,h=async()=>{if(c!==O(this,be)||!O(this,$).meeting.self.videoEnabled){await l.cleanUp();return}const u=performance.now();await l.render(),s.setTimeout(h,Math.max(0,m-(performance.now()-u)))};s.setTimeout(()=>{h()},0)}}async destruct(){de(this,be,null)}};let Pe=Ue;$=new WeakMap,be=new WeakMap;var Dt=(()=>{var t="https://assets.dyte.io/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&Y("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var k=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|k:g=(g&7)<<18|S<<12|k<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var Z=g-65536;M+=String.fromCharCode(55296|Z>>10,56320|Z&1023)}}return M}var j,C,B,x;function q(n){j=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],N=[],A=[];function L(){return R}function ae(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)re(e.preRun.shift());he(H)}function F(){he(N)}function te(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ne(e.postRun.shift());he(A)}function re(n){H.unshift(n)}function J(n){N.unshift(n)}function ne(n){A.unshift(n)}var V=0,K=null;function Ee(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Le(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&K){var o=K;K=null,o()}}function Y(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var De="data:application/octet-stream;base64,";function Re(n){return n.startsWith(De)}var I;I="tflite.wasm",Re(I)||(I=h(I));function Me(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){Y(o)}}function je(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return Me(I)}):Promise.resolve().then(function(){return Me(I)})}function Ne(){var n={env:Te,wasi_snapshot_preview1:Te};function o(g,S){var k=g.exports;e.asm=k,b=e.asm.memory,q(b.buffer),e.asm.__indirect_function_table,J(e.asm.__wasm_call_ctors),Le()}Ee();function d(g){o(g.instance)}function v(g){return je().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),Y(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!Re(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(k){return E("wasm streaming compile failed: "+k),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function We(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function he(n){for(;n.length>0;)n.shift()(e)}function He(n){}var Se="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function Ve(n,o){Y(Se)}function Ge(n,o){Y(Se)}var Xe=!0;function ze(){return Xe}function qe(n,o,d,v,y,M){return-52}function Ke(n,o,d,v,y,M){}function Ye(){Y("")}function Qe(){return Date.now()}function Ae(){return 2147483648}function $e(){return Ae()}var Fe;Fe=()=>performance.now();function Je(n,o,d){B.copyWithin(n,o,o+d)}function Ze(n){try{return b.grow(n-j.byteLength+65535>>>16),q(b.buffer),1}catch{}}function et(n){var o=B.length;n=n>>>0;var d=Ae();if(n>d)return!1;let v=(k,Z)=>k+(Z-k%Z)%Z;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ze(g);if(S)return!0}return!1}var _e={};function tt(){return f||"./this.program"}function ie(){if(!ie.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:tt()};for(var d in _e)_e[d]===void 0?delete o[d]:o[d]=_e[d];var v=[];for(var d in o)v.push(d+"="+o[d]);ie.strings=v}return ie.strings}function rt(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function nt(n,o){var d=0;return ie().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,rt(v,M),d+=v.length+1}),0}function it(n,o){var d=ie();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function ot(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new We(n))}function st(n,o){ot(n)}var at=st;function ut(n){return 52}function ct(n,o,d,v,y){return 70}var ft=[null,[],[]];function dt(n,o){var d=ft[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function mt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var k=0;k<S;k++)dt(n,B[g+k]);y+=S}return x[v>>2]=y,0}function lt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>Y("randomDevice")}function ce(n,o){ce.randomDevice||(ce.randomDevice=lt());for(var d=0;d<o;d++)C[n+d>>0]=ce.randomDevice();return 0}var Te={_dlinit:He,_dlopen_js:Ve,_dlsym_js:Ge,_emscripten_get_now_is_monotonic:ze,_mmap_js:qe,_munmap_js:Ke,abort:Ye,emscripten_date_now:Qe,emscripten_get_heap_max:$e,emscripten_get_now:Fe,emscripten_memcpy_big:Je,emscripten_resize_heap:et,environ_get:nt,environ_sizes_get:it,exit:at,fd_close:ut,fd_seek:ct,fd_write:mt,getentropy:ce};Ne(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var fe;K=function n(){fe||xe(),fe||(K=n)};function xe(n){if(V>0||(ae(),V>0))return;function o(){fe||(fe=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),te()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return xe(),r.ready}})(),jt=(()=>{var t="https://assets.dyte.io/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&Y("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var k=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|k:g=(g&7)<<18|S<<12|k<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var Z=g-65536;M+=String.fromCharCode(55296|Z>>10,56320|Z&1023)}}return M}var j,C,B,x;function q(n){j=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],N=[],A=[];function L(){return R}function ae(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)re(e.preRun.shift());he(H)}function F(){he(N)}function te(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ne(e.postRun.shift());he(A)}function re(n){H.unshift(n)}function J(n){N.unshift(n)}function ne(n){A.unshift(n)}var V=0,K=null;function Ee(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Le(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&K){var o=K;K=null,o()}}function Y(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var De="data:application/octet-stream;base64,";function Re(n){return n.startsWith(De)}var I;I="tflite-simd.wasm",Re(I)||(I=h(I));function Me(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){Y(o)}}function je(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return Me(I)}):Promise.resolve().then(function(){return Me(I)})}function Ne(){var n={env:Te,wasi_snapshot_preview1:Te};function o(g,S){var k=g.exports;e.asm=k,b=e.asm.memory,q(b.buffer),e.asm.__indirect_function_table,J(e.asm.__wasm_call_ctors),Le()}Ee();function d(g){o(g.instance)}function v(g){return je().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),Y(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!Re(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(k){return E("wasm streaming compile failed: "+k),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function We(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function he(n){for(;n.length>0;)n.shift()(e)}function He(n){}var Se="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function Ve(n,o){Y(Se)}function Ge(n,o){Y(Se)}var Xe=!0;function ze(){return Xe}function qe(n,o,d,v,y,M){return-52}function Ke(n,o,d,v,y,M){}function Ye(){Y("")}function Qe(){return Date.now()}function Ae(){return 2147483648}function $e(){return Ae()}var Fe;Fe=()=>performance.now();function Je(n,o,d){B.copyWithin(n,o,o+d)}function Ze(n){try{return b.grow(n-j.byteLength+65535>>>16),q(b.buffer),1}catch{}}function et(n){var o=B.length;n=n>>>0;var d=Ae();if(n>d)return!1;let v=(k,Z)=>k+(Z-k%Z)%Z;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ze(g);if(S)return!0}return!1}var _e={};function tt(){return f||"./this.program"}function ie(){if(!ie.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:tt()};for(var d in _e)_e[d]===void 0?delete o[d]:o[d]=_e[d];var v=[];for(var d in o)v.push(d+"="+o[d]);ie.strings=v}return ie.strings}function rt(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function nt(n,o){var d=0;return ie().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,rt(v,M),d+=v.length+1}),0}function it(n,o){var d=ie();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function ot(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new We(n))}function st(n,o){ot(n)}var at=st;function ut(n){return 52}function ct(n,o,d,v,y){return 70}var ft=[null,[],[]];function dt(n,o){var d=ft[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function mt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var k=0;k<S;k++)dt(n,B[g+k]);y+=S}return x[v>>2]=y,0}function lt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>Y("randomDevice")}function ce(n,o){ce.randomDevice||(ce.randomDevice=lt());for(var d=0;d<o;d++)C[n+d>>0]=ce.randomDevice();return 0}var Te={_dlinit:He,_dlopen_js:Ve,_dlsym_js:Ge,_emscripten_get_now_is_monotonic:ze,_mmap_js:qe,_munmap_js:Ke,abort:Ye,emscripten_date_now:Qe,emscripten_get_heap_max:$e,emscripten_get_now:Fe,emscripten_memcpy_big:Je,emscripten_resize_heap:et,environ_get:nt,environ_sizes_get:it,exit:at,fd_close:ut,fd_seek:ct,fd_write:mt,getentropy:ce};Ne(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var fe;K=function n(){fe||xe(),fe||(K=n)};function xe(n){if(V>0||(ae(),V>0))return;function o(){fe||(fe=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),te()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return xe(),r.ready}})();async function Nt(t){let r=null,e=null,i=null,s=!1;async function c(){r=await Dt();try{e=await jt(),s=!0,t.backend="wasmSimd"}catch(p){console.warn("Failed to create TFLite SIMD WebAssembly module.",p)}}await c();async function f(){if(!r||s&&!e||!s&&t.backend==="wasmSimd"||t.model!=="meet"&&t.model!=="mlkit")return;i=null;const p=t.backend==="wasmSimd"?e:r;if(!p)throw new Error(`TFLite backend unavailable: ${t.backend}`);const l=bt(t.model,t.inputResolution),h=await(await fetch(`https://dyte-plugins.s3.ap-south-1.amazonaws.com/tf-assets/models/${l}.tflite`)).arrayBuffer(),u=p._getModelBufferMemoryOffset();p.HEAPU8.set(new Uint8Array(h),u),p._loadModel(h.byteLength),i=p}return await f(),{tflite:i,isSIMDSupported:s}}const Ie=class{constructor(r,e){ge(this,we,void 0);ge(this,ye,void 0);de(this,we,r),de(this,ye,e)}static async init({meeting:r,segmentationConfig:e,postProcessingConfig:i}){this.isSupported()||console.error("Initialising it in an unsupported environment, the middleware might not work"),window.addEventListener("error",l=>{var m;!((m=l.filename)!=null&&m.includes("localhost"))&&l.lineno!==0&&console.error("RealtimeKitVideoBackgroundTransformer::UnhandledError",l.error)}),window.addEventListener("unhandledrejection",l=>{console.error("RealtimeKitVideoBackgroundTransformer::UnhandledRejection",l.reason)});const s={model:"mlkit",backend:"wasmSimd",inputResolution:"256x256",pipeline:"webgl2",targetFps:35,deferInputResizing:!0,...e||{}};Ce().getEngineName()==="WebKit"&&(s.pipeline="canvas2dCpu");const f={smoothSegmentationMask:!0,jointBilateralFilter:{sigmaSpace:1,sigmaColor:.1},coverage:[.5,.75],lightWrapping:.3,blendMode:"screen",...i||{}};await r.self.setVideoMiddlewareGlobalConfig({disablePerFrameCanvasRendering:!0});const{tflite:p}=await Nt(s);return new Ie(await Be.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}),await Pe.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}))}static isSupported(){var e;let r=!1;try{const i=Ce(),s=document.createElement("canvas"),c=s.getContext("webgl2",{})||s.getContext("webgl",{}),f=+((e=i.getBrowserVersion())==null?void 0:e.split(".")[0]);if(!c||i.getOSName()==="iOS"||i.getBrowserName()==="Safari"&&f<17)return!1;r=!0}catch{r=!1}return r}async createStaticBackgroundVideoMiddleware(r){return await O(this,we).createStaticBackgroundImageVideoMiddleware(r)}async createBackgroundBlurVideoMiddleware(r=50){return O(this,ye).createBackgroundBlurVideoMiddleware(r)}destruct(){O(this,we).destruct(),O(this,ye).destruct()}};let ke=Ie;return we=new WeakMap,ye=new WeakMap,ke}();
package/favicon.svg ADDED
@@ -0,0 +1,15 @@
1
+ <svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
3
+ <path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
4
+ <defs>
5
+ <linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
6
+ <stop stop-color="#41D1FF"/>
7
+ <stop offset="1" stop-color="#BD34FE"/>
8
+ </linearGradient>
9
+ <linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
10
+ <stop stop-color="#FFEA83"/>
11
+ <stop offset="0.0833333" stop-color="#FFDD35"/>
12
+ <stop offset="1" stop-color="#FFA800"/>
13
+ </linearGradient>
14
+ </defs>
15
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
- "name": "@cloudflare/realtimekit-virtual-background",
3
- "version": "0.0.1",
4
- "private": false,
5
- "scripts": {}
6
- }
2
+ "name": "@cloudflare/realtimekit-virtual-background",
3
+ "version": "0.0.2-staging.2",
4
+ "description": "A Package that allows ease of use for RealtimeKit's video middlewares",
5
+ "main": "./dist/index.cjs.js",
6
+ "module": "./dist/index.es.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.es.js",
10
+ "require": "./dist/index.cjs.js",
11
+ "types": "./types/index.d.ts"
12
+ }
13
+ },
14
+ "types": "./types/index.d.ts",
15
+ "bugs": {
16
+ "url": "https://docs.dyte.in/discuss"
17
+ },
18
+ "private": false,
19
+ "dependencies": {},
20
+ "publishConfig": {
21
+ "tag": "staging"
22
+ },
23
+ "scripts": {
24
+ "postpublish": "mv package.json.bak package.json"
25
+ }
26
+ }
@@ -0,0 +1,9 @@
1
+ import { BackgroundTransformer, VideoMiddleware } from './common/BackgroundTransformer';
2
+ import { InitParams } from './client/RealtimeKitVideoBackgroundTransformer';
3
+ export default class ImageBackgroundTransformer extends BackgroundTransformer {
4
+ #private;
5
+ constructor(initParams: InitParams);
6
+ static init(initParams: InitParams): Promise<ImageBackgroundTransformer>;
7
+ createStaticBackgroundImageVideoMiddleware(backgroundImageUrl: string): Promise<VideoMiddleware>;
8
+ destruct(): void;
9
+ }
@@ -0,0 +1,9 @@
1
+ import { BackgroundTransformer, VideoMiddleware } from './common/BackgroundTransformer';
2
+ import { InitParams } from './client/RealtimeKitVideoBackgroundTransformer';
3
+ export default class SimpleBackgroundTransformer extends BackgroundTransformer {
4
+ #private;
5
+ constructor(initParams: InitParams);
6
+ static init(initParams: InitParams): Promise<SimpleBackgroundTransformer>;
7
+ createBackgroundBlurVideoMiddleware(blurLength: number): Promise<VideoMiddleware>;
8
+ destruct(): Promise<void>;
9
+ }
@@ -0,0 +1,49 @@
1
+ import RealtimeKitMeeting from '@cloudflare/realtimekit';
2
+ import { SegmentationConfig } from '../core/helpers/segmentationHelper';
3
+ import { TFLite } from '../core/hooks/useTFLite';
4
+ export type BlendMode = 'screen' | 'linearDodge';
5
+ export type JointBilateralFilterConfig = {
6
+ sigmaSpace: number;
7
+ sigmaColor: number;
8
+ };
9
+ export type PostProcessingConfig = {
10
+ smoothSegmentationMask: boolean;
11
+ jointBilateralFilter: JointBilateralFilterConfig;
12
+ coverage: [number, number];
13
+ lightWrapping: number;
14
+ blendMode: BlendMode;
15
+ };
16
+ export interface InitParams {
17
+ meeting: RealtimeKitMeeting;
18
+ segmentationConfig: SegmentationConfig;
19
+ postProcessingConfig: PostProcessingConfig;
20
+ tflite: TFLite;
21
+ }
22
+ export default class RealtimeKitVideoBackgroundTransformer {
23
+ #private;
24
+ private constructor();
25
+ /**
26
+ * The `init` method can be used to instantiate the RealtimeKitVideoBackgroundTransformer class.
27
+ * This returns an instance of `RealtimeKitVideoBackgroundTransformer`,
28
+ * which can be used to create video middlewares for RealtimeKit Meetings.
29
+ */
30
+ static init({ meeting, segmentationConfig: passedSegmentationConfig, postProcessingConfig: passedPostProcessingConfig, }: {
31
+ meeting: RealtimeKitMeeting;
32
+ segmentationConfig?: Partial<SegmentationConfig>;
33
+ postProcessingConfig?: Partial<PostProcessingConfig>;
34
+ }): Promise<RealtimeKitVideoBackgroundTransformer>;
35
+ /**
36
+ * Tells if the current browser supports this middleware or not
37
+ * @returns isSupported
38
+ */
39
+ static isSupported(): boolean;
40
+ /**
41
+ * Expects a static background image url and returns a video middleware
42
+ * which adds the given image url as the background.
43
+ * @param staticBackgroundImageURL
44
+ * @returns VideoMiddleware
45
+ */
46
+ createStaticBackgroundVideoMiddleware(staticBackgroundImageURL: string): Promise<import("../common/BackgroundTransformer").VideoMiddleware>;
47
+ createBackgroundBlurVideoMiddleware(blurLength?: number): Promise<import("../common/BackgroundTransformer").VideoMiddleware>;
48
+ destruct(): void;
49
+ }
@@ -0,0 +1,10 @@
1
+ export type VideoMiddleware = ({ canvas }: {
2
+ canvas: HTMLCanvasElement;
3
+ }) => Promise<void>;
4
+ export type WorkerTimersInterface = {
5
+ setTimeout(callback: () => void, timeoutMs?: number): number;
6
+ clearTimeout(timerId: number): void;
7
+ };
8
+ export declare abstract class BackgroundTransformer {
9
+ createCameraVideoElement: (rawVideoTrack: MediaStreamTrack) => Promise<HTMLVideoElement>;
10
+ }
@@ -0,0 +1,6 @@
1
+ export type BackgroundConfig = {
2
+ type: 'none' | 'blur' | 'image';
3
+ backgroundImage?: HTMLImageElement | null;
4
+ blurLength?: number;
5
+ };
6
+ export declare const backgroundImageUrls: string[];
@@ -0,0 +1,12 @@
1
+ export type BlendMode = 'screen' | 'linearDodge';
2
+ export type JointBilateralFilterConfig = {
3
+ sigmaSpace: number;
4
+ sigmaColor: number;
5
+ };
6
+ export type PostProcessingConfig = {
7
+ smoothSegmentationMask: boolean;
8
+ jointBilateralFilter: JointBilateralFilterConfig;
9
+ coverage: [number, number];
10
+ lightWrapping: number;
11
+ blendMode: BlendMode;
12
+ };
@@ -0,0 +1,6 @@
1
+ import { PostProcessingConfig } from './postProcessingHelper';
2
+ export type RenderingPipeline = {
3
+ render(): Promise<void>;
4
+ updatePostProcessingConfig(newPostProcessingConfig: PostProcessingConfig): void;
5
+ cleanUp(): void;
6
+ };
@@ -0,0 +1,16 @@
1
+ export type SegmentationModel = 'bodyPix' | 'meet' | 'mlkit';
2
+ export type SegmentationBackend = 'webgl' | 'wasm' | 'wasmSimd';
3
+ export type InputResolution = '640x360' | '256x256' | '256x144' | '160x96';
4
+ export declare const inputResolutions: {
5
+ [resolution in InputResolution]: [number, number];
6
+ };
7
+ export type PipelineName = 'canvas2dCpu' | 'webgl2';
8
+ export type SegmentationConfig = {
9
+ model: SegmentationModel;
10
+ backend: SegmentationBackend;
11
+ inputResolution: InputResolution;
12
+ pipeline: PipelineName;
13
+ targetFps: number;
14
+ deferInputResizing: boolean;
15
+ };
16
+ export declare function getTFLiteModelFileName(model: SegmentationModel, inputResolution: InputResolution): "segm_full_v679" | "segm_lite_v681" | "selfiesegmentation_mlkit-256x256-2021_01_19-v1215.f16";
@@ -0,0 +1,11 @@
1
+ export type SourceConfig = {
2
+ type: 'image' | 'video' | 'camera';
3
+ url?: string;
4
+ };
5
+ export type SourcePlayback = {
6
+ htmlElement: HTMLImageElement | HTMLVideoElement;
7
+ width: number;
8
+ height: number;
9
+ };
10
+ export declare const sourceImageUrls: string[];
11
+ export declare const sourceVideoUrls: string[];
@@ -0,0 +1,21 @@
1
+ import { SegmentationConfig } from '../helpers/segmentationHelper';
2
+ export interface TFLite {
3
+ HEAPF32: any;
4
+ HEAPU8: any;
5
+ _getModelBufferMemoryOffset(): number;
6
+ _getInputMemoryOffset(): number;
7
+ _getInputHeight(): number;
8
+ _getInputWidth(): number;
9
+ _getInputChannelCount(): number;
10
+ _getOutputMemoryOffset(): number;
11
+ _getOutputHeight(): number;
12
+ _getOutputWidth(): number;
13
+ _getOutputChannelCount(): number;
14
+ _loadModel(bufferSize: number): number;
15
+ _runInference(): number;
16
+ }
17
+ declare function useTFLite(segmentationConfig: SegmentationConfig): Promise<{
18
+ tflite: TFLite;
19
+ isSIMDSupported: boolean;
20
+ }>;
21
+ export default useTFLite;
@@ -0,0 +1,2 @@
1
+ import RealtimeKitVideoBackgroundTransformer from './client/RealtimeKitVideoBackgroundTransformer';
2
+ export default RealtimeKitVideoBackgroundTransformer;
@@ -0,0 +1,11 @@
1
+ import { WorkerTimersInterface } from '../../common/BackgroundTransformer';
2
+ import { BackgroundConfig } from '../../core/helpers/backgroundHelper';
3
+ import { PostProcessingConfig } from '../../core/helpers/postProcessingHelper';
4
+ import { SegmentationConfig } from '../../core/helpers/segmentationHelper';
5
+ import { SourcePlayback } from '../../core/helpers/sourceHelper';
6
+ import { TFLite } from '../../core/hooks/useTFLite';
7
+ export declare function buildCanvas2dPipeline(sourcePlayback: SourcePlayback, backgroundConfig: BackgroundConfig, segmentationConfig: SegmentationConfig, canvas: HTMLCanvasElement, tflite: TFLite, WorkerTimers: WorkerTimersInterface): {
8
+ render: () => Promise<void>;
9
+ updatePostProcessingConfig: (newPostProcessingConfig: PostProcessingConfig) => void;
10
+ cleanUp: () => void;
11
+ };
@@ -0,0 +1,18 @@
1
+ import { WorkerTimersInterface } from '../../common/BackgroundTransformer';
2
+ /**
3
+ * Use it along with boyswan.glsl-literal VSCode extension
4
+ * to get GLSL syntax highlighting.
5
+ * https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
6
+ *
7
+ * On VSCode OSS, boyswan.glsl-literal requires slevesque.shader extension
8
+ * to be installed as well.
9
+ * https://marketplace.visualstudio.com/items?itemName=slevesque.shader
10
+ */
11
+ export declare const glsl: (template: {
12
+ raw: readonly string[] | ArrayLike<string>;
13
+ }, ...substitutions: any[]) => string;
14
+ export declare function createPiplelineStageProgram(gl: WebGL2RenderingContext, vertexShader: WebGLShader, fragmentShader: WebGLShader, positionBuffer: WebGLBuffer, texCoordBuffer: WebGLBuffer): WebGLProgram;
15
+ export declare function createProgram(gl: WebGL2RenderingContext, vertexShader: WebGLShader, fragmentShader: WebGLShader): WebGLProgram;
16
+ export declare function compileShader(gl: WebGL2RenderingContext, shaderType: number, shaderSource: string): WebGLShader;
17
+ export declare function createTexture(gl: WebGL2RenderingContext, internalformat: number, width: number, height: number, minFilter?: number, magFilter?: number): WebGLTexture;
18
+ export declare function readPixelsAsync(timerWorker: WorkerTimersInterface, gl: WebGL2RenderingContext, x: number, y: number, width: number, height: number, format: number, type: number, dest: ArrayBufferView): Promise<ArrayBufferView>;
@@ -0,0 +1,7 @@
1
+ import { BackgroundConfig } from '../../core/helpers/backgroundHelper';
2
+ export type BackgroundBlurStage = {
3
+ render(): void;
4
+ updateCoverage(coverage: [number, number]): void;
5
+ cleanUp(): void;
6
+ };
7
+ export declare function buildBackgroundBlurStage(gl: WebGL2RenderingContext, vertexShader: WebGLShader, positionBuffer: WebGLBuffer, texCoordBuffer: WebGLBuffer, personMaskTexture: WebGLTexture, canvas: HTMLCanvasElement, backgroundConfig: BackgroundConfig): BackgroundBlurStage;