reporting-lib 0.4.2 → 0.4.4
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/dist/api/fetch.d.ts.map +1 -1
- package/dist/api/fetch.js +13 -11
- package/dist/api/fetch.js.map +1 -1
- package/dist/api/xhr.d.ts.map +1 -1
- package/dist/api/xhr.js +8 -12
- package/dist/api/xhr.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +2 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/performance/pageStayTimeTracker.js +1 -1
- package/package.json +1 -1
package/dist/api/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.js"],"names":[],"mappings":"AA0EA,sCAEC"}
|
package/dist/api/fetch.js
CHANGED
|
@@ -5,25 +5,25 @@ function overWriteFetch() {
|
|
|
5
5
|
window.fetch = function newFetch(url, config) {
|
|
6
6
|
const startTime = Date.now();
|
|
7
7
|
let request_url = url;
|
|
8
|
-
if (isValidOssVideoUrl(request_url)) {
|
|
9
|
-
request_url = `https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video`;
|
|
10
|
-
}
|
|
11
8
|
const reportData = {
|
|
12
|
-
// startTime,
|
|
13
9
|
request_url,
|
|
14
10
|
method: config?.method || 'GET',
|
|
15
11
|
// sub_type: 'fetch',
|
|
16
|
-
// request_size: parseInt(getRequestBodySize(config?.body)/1000),
|
|
17
12
|
};
|
|
18
|
-
|
|
19
|
-
reportData.
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
if (isValidOssVideoUrl(request_url)) {
|
|
14
|
+
reportData.request_url = `https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video`;
|
|
15
|
+
try {
|
|
16
|
+
reportData.request_size = parseInt(getRequestBodySize(config?.body) / 1000);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
}
|
|
22
20
|
}
|
|
23
21
|
return originalFetch(url, config)
|
|
24
22
|
.then(res => {
|
|
25
23
|
const endTime = Date.now();
|
|
26
|
-
|
|
24
|
+
if (isValidOssVideoUrl(request_url)) {
|
|
25
|
+
reportData.duration = (endTime - startTime);
|
|
26
|
+
}
|
|
27
27
|
reportData.status = res.status;
|
|
28
28
|
const clonedRes = res.clone();
|
|
29
29
|
if (fiterUrl(url)) {
|
|
@@ -42,7 +42,9 @@ function overWriteFetch() {
|
|
|
42
42
|
})
|
|
43
43
|
.catch(err => {
|
|
44
44
|
const endTime = Date.now();
|
|
45
|
-
|
|
45
|
+
if (isValidOssVideoUrl(request_url)) {
|
|
46
|
+
reportData.duration = (endTime - startTime);
|
|
47
|
+
}
|
|
46
48
|
reportData.status = 0;
|
|
47
49
|
reportData.code = reportData.status;
|
|
48
50
|
lazyReportCache('api', reportData);
|
package/dist/api/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/api/fetch.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,kBAAkB,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAEtE,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC;AAEnC,SAAS,cAAc;IACrB,MAAM,CAAC,KAAK,GAAG,SAAS,QAAQ,CAAC,GAAG,EAAE,MAAM;QAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,IAAI,WAAW,GAAG,GAAG,CAAC;QACtB,
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/api/fetch.js"],"names":[],"mapp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@
|
|
|
1
|
-
{"version":3,"file":"xhr.d.ts","sourceRoot":"","sources":["../../src/api/xhr.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xhr.d.ts","sourceRoot":"","sources":["../../src/api/xhr.js"],"names":[],"mappings":"AAgEA,oCAEC"}
|
package/dist/api/xhr.js
CHANGED
|
@@ -25,25 +25,21 @@ function overWriteOpenAndSend() {
|
|
|
25
25
|
}
|
|
26
26
|
catch {
|
|
27
27
|
}
|
|
28
|
-
if (isValidOssVideoUrl(request_url)) {
|
|
29
|
-
request_url = `https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video`;
|
|
30
|
-
}
|
|
31
28
|
let reportData = {
|
|
32
29
|
status,
|
|
33
|
-
duration,
|
|
34
|
-
// startTime,
|
|
35
|
-
// endTime,
|
|
36
30
|
request_url,
|
|
37
31
|
method: method || 'GET',
|
|
38
32
|
code,
|
|
39
|
-
// success: status >= 200 && status < 300,
|
|
40
33
|
// sub_type: 'xhr',
|
|
41
|
-
// request_size: parseInt(requestSize/1000),
|
|
42
34
|
};
|
|
43
|
-
|
|
44
|
-
reportData.
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
if (isValidOssVideoUrl(request_url)) {
|
|
36
|
+
reportData.request_url = `https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video`;
|
|
37
|
+
try {
|
|
38
|
+
reportData.request_size = parseInt(requestSize / 1000);
|
|
39
|
+
reportData.duration = duration;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
}
|
|
47
43
|
}
|
|
48
44
|
lazyReportCache('api', reportData);
|
|
49
45
|
this.removeEventListener('loadend', onLoadEnd, true);
|
package/dist/api/xhr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/api/xhr.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,E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;YACnF,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;YACnB,IAAI,IAAI,GAAG,MAAM,CAAC;YAClB,IAAI,WAAW,GAAG,GAAG,CAAC;YACtB,IAAI,CAAC;gBACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;YACnC,CAAC;YAAA,MAAM,CAAC;YAER,CAAC;YAED,IAAI,UAAU,GAAG;gBACf,MAAM;gBACN,WAAW;gBACX,MAAM,EAAE,MAAM,IAAI,KAAK;gBACvB,IAAI;gBACJ,mBAAmB;aACpB,CAAA;YAED,IAAG,kBAAkB,CAAC,WAAW,CAAC,EAAC,CAAC;gBAClC,UAAU,CAAC,WAAW,GAAG,8DAA8D,CAAC;gBACxF,IAAI,CAAC;oBACH,UAAU,CAAC,YAAY,GAAG,QAAQ,CAAC,WAAW,GAAC,IAAI,CAAC,CAAC;oBACrD,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBACjC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;gBAEjB,CAAC;YACH,CAAC;YAED,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YAEnC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QACvD,CAAC,CAAA;QAED,6CAA6C;QAC7C,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAClD,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC,CAAA;AAGH,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,GAAG;IACzB,oBAAoB,EAAE,CAAC;AACzB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var j={source:"mbp",userId:"",reportUrl:"http://localhost:3001/report/actions",trackerAll:false,slsProject:"",slsEndpoint:"",slsLogstore:"",history:null},
|
|
2
|
-
`).slice(1)){let o=st(n);o.filename&&r.push(o);}return r.slice(0,at)}function X(){window.addEventListener("error",async function(e){let t=e.target;if(t&&(t.src||t.href)){let r={error_type:"resource",...J,msg:F(`\u52A0\u8F7D${t.tagName}\u5931\u8D25\uFF1A${t.src||t.href}`),version:I};p("error",r);}else {let r=Ie(e.error),n=e.message;if(r?.[0]){let{filename:a,functionName:s,lineno:c,colno:l}=r[0];n=`${e.message},${a},line:${c}:${l}`;}let o={error_type:"js",msg:F(n),...J,version:I};p("error",o),await Le()&&p("error",{...o,error_type:"whiteScreen"});}},true),window.addEventListener("unhandledrejection",function(e){let t=e.reason,r=Ie(t),n=t;if(r?.[0]){let{filename:i,functionName:a,lineno:s,colno:c}=r[0];n=`${e?.reason?.message||e?.reason},${i},line:${s}:${c}`;}let o={error_type:"js",msg:F(n),...J,version:I};p("error",o);});}var Be=-1,x=e=>{addEventListener("pageshow",t=>{t.persisted&&(Be=t.timeStamp,e(t));},true);},T=(e,t,r,n)=>{let o,i;return a=>{t.value>=0&&(a||n)&&(i=t.value-(o??0),(i||o===void 0)&&(o=t.value,t.delta=i,t.rating=((s,c)=>s>c[1]?"poor":s>c[0]?"needs-improvement":"good")(t.value,r),e(t)));}},re=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()));},oe=()=>{let e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},k=()=>oe()?.activationStart??0,v=(e,t=-1)=>{let r=oe(),n="navigate";return Be>=0?n="back-forward-cache":r&&(document.prerendering||k()>0?n="prerender":document.wasDiscarded?n="restore":r.type&&(n=r.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:n}},G=new WeakMap;function ie(e,t){return G.get(e)||G.set(e,new t),G.get(e)}var Y=class{t;i=0;o=[];h(t){if(t.hadRecentInput)return;let r=this.o[0],n=this.o.at(-1);this.i&&r&&n&&t.startTime-n.startTime<1e3&&t.startTime-r.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),this.t?.(t);}},R=(e,t,r={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){let n=new PerformanceObserver(o=>{Promise.resolve().then(()=>{t(o.getEntries());});});return n.observe({type:e,buffered:!0,...r}),n}}catch{}},ae=e=>{let t=false;return ()=>{t||(e(),t=true);}},b=-1,Fe=new Set,Ee=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,Q=e=>{if(document.visibilityState==="hidden"){if(e.type==="visibilitychange")for(let t of Fe)t();isFinite(b)||(b=e.type==="visibilitychange"?e.timeStamp:0,removeEventListener("prerenderingchange",Q,true));}},H=()=>{if(b<0){let e=k();b=(document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter(r=>r.name==="hidden"&&r.startTime>e)[0]?.startTime)??Ee(),addEventListener("visibilitychange",Q,true),addEventListener("prerenderingchange",Q,true),x(()=>{setTimeout(()=>{b=Ee();});});}return {get firstHiddenTime(){return b},onHidden(e){Fe.add(e);}}},$=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),true):e();},Me=[1800,3e3],se=(e,t={})=>{$(()=>{let r=H(),n,o=v("FCP"),i=R("paint",a=>{for(let s of a)s.name==="first-contentful-paint"&&(i.disconnect(),s.startTime<r.firstHiddenTime&&(o.value=Math.max(s.startTime-k(),0),o.entries.push(s),n(true)));});i&&(n=T(e,o,Me,t.reportAllChanges),x(a=>{o=v("FCP"),n=T(e,o,Me,t.reportAllChanges),re(()=>{o.value=performance.now()-a.timeStamp,n(true);});}));});},De=[.1,.25],Ne=(e,t={})=>{let r=H();se(ae(()=>{let n,o=v("CLS",0),i=ie(t,Y),a=c=>{for(let l of c)i.h(l);i.i>o.value&&(o.value=i.i,o.entries=i.o,n());},s=R("layout-shift",a);s&&(n=T(e,o,De,t.reportAllChanges),r.onHidden(()=>{a(s.takeRecords()),n(true);}),x(()=>{i.i=0,o=v("CLS",0),n=T(e,o,De,t.reportAllChanges),re(()=>n());}),setTimeout(n));}));},qe=0,K=1/0,q=0,ct=e=>{for(let t of e)t.interactionId&&(K=Math.min(K,t.interactionId),q=Math.max(q,t.interactionId),qe=q?(q-K)/7+1:0);},Z,Oe=()=>Z?qe:performance.interactionCount??0,lt=()=>{"interactionCount"in performance||Z||(Z=R("event",ct,{type:"event",buffered:true,durationThreshold:0}));},ke=0,ee=class{u=[];l=new Map;m;p;v(){ke=Oe(),this.u.length=0,this.l.clear();}L(){let t=Math.min(this.u.length-1,Math.floor((Oe()-ke)/50));return this.u[t]}h(t){if(this.m?.(t),!t.interactionId&&t.entryType!=="first-input")return;let r=this.u.at(-1),n=this.l.get(t.interactionId);if(n||this.u.length<10||t.duration>r.P){if(n?t.duration>n.P?(n.entries=[t],n.P=t.duration):t.duration===n.P&&t.startTime===n.entries[0].startTime&&n.entries.push(t):(n={id:t.interactionId,entries:[t],P:t.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort((o,i)=>i.P-o.P),this.u.length>10){let o=this.u.splice(10);for(let i of o)this.l.delete(i.id);}this.p?.(n);}}},He=e=>{let t=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?e():(e=ae(e),addEventListener("visibilitychange",e,{once:true,capture:true}),t(()=>{e(),removeEventListener("visibilitychange",e,{capture:true});}));},Re=[200,500],$e=(e,t={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;let r=H();$(()=>{lt();let n,o=v("INP"),i=ie(t,ee),a=c=>{He(()=>{for(let u of c)i.h(u);let l=i.L();l&&l.P!==o.value&&(o.value=l.P,o.entries=l.entries,n());});},s=R("event",a,{durationThreshold:t.durationThreshold??40});n=T(e,o,Re,t.reportAllChanges),s&&(s.observe({type:"first-input",buffered:true}),r.onHidden(()=>{a(s.takeRecords()),n(true);}),x(()=>{i.v(),o=v("INP"),n=T(e,o,Re,t.reportAllChanges);}));});},te=class{m;h(t){this.m?.(t);}},_e=[2500,4e3],ze=(e,t={})=>{$(()=>{let r=H(),n,o=v("LCP"),i=ie(t,te),a=c=>{t.reportAllChanges||(c=c.slice(-1));for(let l of c)i.h(l),l.startTime<r.firstHiddenTime&&(o.value=Math.max(l.startTime-k(),0),o.entries=[l],n());},s=R("largest-contentful-paint",a);if(s){n=T(e,o,_e,t.reportAllChanges);let c=ae(()=>{a(s.takeRecords()),s.disconnect(),n(true);}),l=u=>{u.isTrusted&&(He(c),removeEventListener(u.type,l,{capture:true}));};for(let u of ["keydown","click","visibilitychange"])addEventListener(u,l,{capture:true});x(u=>{o=v("LCP"),n=T(e,o,_e,t.reportAllChanges),re(()=>{o.value=performance.now()-u.timeStamp,n(true);});});}});},Ae=[800,1800],ne=e=>{document.prerendering?$(()=>ne(e)):document.readyState!=="complete"?addEventListener("load",()=>ne(e),true):setTimeout(e);},Ue=(e,t={})=>{let r=v("TTFB"),n=T(e,r,Ae,t.reportAllChanges);ne(()=>{let o=oe();o&&(r.value=Math.max(o.responseStart-k(),0),r.entries=[o],n(true),x(()=>{r=v("TTFB",0),n=T(e,r,Ae,t.reportAllChanges),n(true);}));});};function ce(){Ne(_),$e(_),ze(_),se(_),Ue(_);}function _(e){let t={name:e.name,value:e.value};p("performance",t);}var z=XMLHttpRequest.prototype,ut=z.open,dt=z.send;function mt(){z.open=function(...t){this.url=t[1],this.method=t[0],ut.apply(this,t);},z.send=function(...t){this.startTime=Date.now();let r=t[0];this.requestSize=N(r);let n=()=>{this.endTime=Date.now(),this.duration=this.endTime-this.startTime;let{status:o,duration:i,startTime:a,endTime:s,method:c,response:l,requestSize:u}=this,{url:h}=this,g=o,w=h;try{g=JSON.parse(l).code;}catch{}B(w)&&(w="https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video");let C={status:o,duration:i,request_url:w,method:c||"GET",code:g};try{C.request_size=parseInt(u/1e3);}catch{}p("api",C),this.removeEventListener("loadend",n,true);};this.addEventListener("loadend",n,true),dt.apply(this,t);};}function le(){mt();}var ft=window.fetch;function pt(){window.fetch=function(t,r){let n=Date.now(),o=t;B(o)&&(o="https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video");let i={request_url:o,method:r?.method||"GET"};try{i.request_size=parseInt(N(r?.body)/1e3);}catch{}return ft(t,r).then(a=>{let s=Date.now();i.duration=s-n,i.status=a.status;let c=a.clone();return ht(t)&&(c.ok?c.json().then(l=>{i.code=l.code,p("api",i);}):(i.code=i.status,p("api",i))),a}).catch(a=>{let s=Date.now();return i.duration=s-n,i.status=0,i.code=i.status,p("api",i),a})};}function ht(e){let t=true;return (e.indexOf(".js.map")!==-1||e.indexOf(".log.aliyuncs.com")!==-1)&&(t=false),t}function ue(){pt();}function de(){le(),ue();}async function We(e,{project:t,endpoint:r,logstore:n}){if(!t||!r||!n)return;let o=Math.floor(Date.now()/1e3),i={__logs__:e.map(u=>({__time__:o,...Object.keys(u).reduce((h,g)=>(h[g]=String(u[g]),h),{})})),__topic__:"default",__source__:"frontend"},a=JSON.stringify(i),s=`https://${t}.${r}/logstores/${n}/track?APIVersion=0.6.0`,c=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","x-log-apiversion":"0.6.0","x-log-bodyrawsize":a.length.toString()},body:a}),l=await c.text();if(!c.ok)throw new Error(`SLS API error: ${c.status} ${c.statusText} - ${l}`);return c}function gt(e,t,r=false){if(f.reportUrl===null){console.error("\u8BF7\u5148\u914D\u7F6E\u4E0A\u62A5\u5730\u5740");return}let n=[{user_id:Number(f.userId)||0,source:f.source,type:e,url:window.location.pathname,data:t}];if(r){me(n);return}window.requestIdleCallback?window.requestIdleCallback(()=>{me(n);},{timeout:3e3}):me(n);}var je=null;function U(e,t,r,n=3e3){if(t=JSON.stringify({...O,...t}),we(e,t),r){Ve(r);return}clearTimeout(je),je=setTimeout(()=>{Ve();},n);}function Ve(e=false){let t=ye();if(t.size){for(let[r,n]of t)gt(r,n,e);Se();}}function me(e){We(e,{project:f.slsProject,endpoint:f.slsEndpoint,logstore:f.slsLogstore}).catch(t=>{console.error("[reporting-lib] SLS\u4E0A\u62A5\u5931\u8D25:",t);});}function Je(e,t={}){let{minDuration:r=1e3,debounceMs:n=300}=t,o=false,i=null,a=Date.now(),s=(()=>{try{return window.location?.pathname||"/"}catch{return "/"}})(),c,l=false,u=(d,m,S)=>{o||(i&&clearTimeout(i),i=setTimeout(()=>{if(!o&&m>=r)try{e(m,d,S),o=!0;}catch(L){console.error("[trackPageStayTime] onLeave callback error:",L);}},n));},h=()=>{if(document.visibilityState==="hidden"){let d=Date.now(),m=d-a;u("visibilitychange-hidden",m,{startTime:a,endTime:d,pagePath:s,pageTag:c});}else if(document.visibilityState==="visible"){a=Date.now();try{s=window.location?.pathname||s;}catch{}o=false;}};document.addEventListener("visibilitychange",h);let g=d=>{let m=Date.now(),S=m-a,L={startTime:a,endTime:m,pagePath:s,pageTag:c};d.persisted?u("pagehide-bfcache",S,L):u("pagehide",S,L);};window.addEventListener("pagehide",g);let w=()=>{if(!o){let d=Date.now(),m=d-a,S={startTime:a,endTime:d,pagePath:s,pageTag:c};if(m>=r)try{e(m,"beforeunload",S),o=!0;}catch(L){console.error("[trackPageStayTime] onLeave callback error:",L);}}};window.addEventListener("beforeunload",w);let C=()=>{let d=Date.now(),m=d-a;u("popstate",m,{startTime:a,endTime:d,pagePath:s,pageTag:c});};window.addEventListener("popstate",C);let W=()=>{a=Date.now();try{s=window.location?.pathname||s;}catch{}o=false,i&&(clearTimeout(i),i=null);},fe=(d="manual")=>{let m=Date.now(),S=m-a;u(d,S,{startTime:a,endTime:m,pagePath:s,pageTag:c}),d==="route-change"&&setTimeout(()=>{W();},n+50);},pe=d=>{c=d||void 0,d&&(l=true);};return {manualLeave:fe,reset:W,stop:()=>{i&&(clearTimeout(i),i=null),document.removeEventListener("visibilitychange",h),window.removeEventListener("pagehide",g),window.removeEventListener("beforeunload",w),window.removeEventListener("popstate",C);},getCurrentDuration:()=>{let d=Date.now();return document.visibilityState==="visible"?d-a:0},setPageTag:pe,switchPageTag:(d,m="page-tag-change")=>{c&&c!==d?(o=false,fe(m),a=Date.now()):l||(a=Date.now(),o=false),pe(d);}}}var Tt=e=>{try{if(e)return e||"/";let{pathname:t="/"}=window.location||{};return t||"/"}catch{return "/"}},Xe=(e,t,r,n={})=>{let{startTime:o,endTime:i,pagePath:a,pageTag:s}=r,c=Tt(a),l=s?`${c}#${s}`:c,{formatPageName:u}=n;return {pageName:typeof u=="function"?u(l,{duration:e,reason:t,...r}):l,duration:e,startTime:o,endTime:i}};var y=null,P=null;function vt(e={},t,r){let{enabled:n,minDuration:o,debounceMs:i,onLeave:a}=e;n?(y&&(y.stop(),y=null),y=Je(a||r||((c,l,u)=>{}),{minDuration:o,debounceMs:i}),t&&t.listen&&(P&&(P(),P=null),P=t.listen(({location:c,action:l})=>{y&&(l==="PUSH"||l==="REPLACE")&&y.manualLeave("route-change");}))):y&&(y.stop(),y=null,P&&(P(),P=null));}function Ge(e,t){y?.switchPageTag(e,t);}function Ke(e,t){if(!e)return;vt(e,t,(n,o,i)=>{let a=Xe(n,o,i||{startTime:0,endTime:0},{formatPageName:e?.formatPageName});U("pv",a);});}function Ye(e,t){let r=t||f.history;return !r||!r.listen?(console.warn("[reporting-lib] No history instance available. Please provide history in init() or pass it as parameter."),()=>{}):r.listen(e)}var Qe=false,yt={init(e={}){he(e),Ke(e.trackPageStayTime,e.history),Qe||(X(),ce(),de(),Qe=true);},reportToSLS(e,t={},r={}){let{immediate:n=false,timeout:o=3e3}=r;U(e,t,n,o);},switchPageTag(e,t="page-tag-change"){Ge(e,t);},listenRouteChange(e,t){return Ye(e,t)}},Cn=yt;
|
|
1
|
+
'use strict';var j={source:"mbp",userId:"",reportUrl:"http://localhost:3001/report/actions",trackerAll:false,slsProject:"",slsEndpoint:"",slsLogstore:"",history:null},E="",f=j;function he(e){for(let t in j)e[t]&&(j[t]=e[t]);e.version&&(E=e.version);}var D=new Map,O=new Map;function ge(){return D}function Te(e,t){D.get(e)?D.get(e).push(t):D.set(e,[t]);}function ve(){D.clear();}function ye(){return O}function we(e,t){O.get(e)?O.get(e).push(t):O.set(e,[t]);}function Se(){O.clear();}function Ze(e,t,r=false){if(f.reportUrl===null){console.error("\u8BF7\u5148\u914D\u7F6E\u4E0A\u62A5\u5730\u5740");return}let n=JSON.stringify({user_id:Number(f.userId)||0,source:f.source,type:e,url:window.location.pathname,data:t});if(r){V(f.reportUrl,n);return}window.requestIdleCallback?window.requestIdleCallback(()=>{V(f.reportUrl,n);},{timeout:3e3}):setTimeout(()=>{V(f.reportUrl,n);});}var Pe=null;function p(e,t,r=3e3){Te(e,t),clearTimeout(Pe),Pe=setTimeout(()=>{let n=ge();if(n.size){for(let[o,i]of n)Ze(o,i);ve();}},r);}function V(e,t){navigator.sendBeacon?navigator.sendBeacon(e,t):et(e,t);}function et(e,t){let r=new XMLHttpRequest;r.open("POST",e,true),r.setRequestHeader("Content-Type","application/json"),r.send(t);}var tt=({samplePoints:e=6,whiteTags:t=["HTML","BODY","IFRAME"],onDetected:r=(o,i)=>{},threshold:n=.9}={})=>{let o=window.innerWidth,i=window.innerHeight,a=[];for(let u=1;u<=e;u++)a.push([o/2,i/(e+1)*u]);let s=0,c=[];a.forEach(([u,h])=>{let g=document.elementFromPoint(u,h),w=g?.tagName||"NULL";c.push({x:u,y:h,tag:w}),(!g||t.includes(w))&&s++;});let l=s/e>=n;r(l,c);},nt=(e,t=300,r=false)=>{let n=null;return function(...o){let i=this;n&&clearTimeout(n),r&&!n&&e.apply(i,o),n=setTimeout(()=>{r||e.apply(i,o),n=null;},t);}},rt=nt(e=>{tt({onDetected:(t,r)=>{e(t),B=null;}});},1e3),B=null,Le=()=>(B||(B=new Promise(e=>{setTimeout(()=>{rt(e);},3e3);})),B),be=()=>{let e=navigator.userAgent,t="Unknown",r="Unknown";return /edg/i.test(e)?(t="Edge",r=e.match(/edg\/([\d\.]+)/i)?.[1]):/opr/i.test(e)?(t="Opera",r=e.match(/opr\/([\d\.]+)/i)?.[1]):/chrome/i.test(e)?(t="Chrome",r=e.match(/chrome\/([\d\.]+)/i)?.[1]):/firefox/i.test(e)?(t="Firefox",r=e.match(/firefox\/([\d\.]+)/i)?.[1]):/safari/i.test(e)&&!/chrome/i.test(e)?(t="Safari",r=e.match(/version\/([\d\.]+)/i)?.[1]):(/msie/i.test(e)||/trident/i.test(e))&&(t="Internet Explorer",r=e.match(/(msie\s|rv:)([\d\.]+)/i)?.[2]),{name:t,version:r}},xe=()=>{let e=navigator.userAgent||navigator.vendor||window.opera;return /windows phone/i.test(e)?"Windows Phone":/win/i.test(e)?"Windows":/android/i.test(e)?"Android":/iPad|iPhone|iPod/.test(e)&&!window.MSStream?"iOS":/Macintosh|MacIntel|MacPPC|Mac68K/.test(e)?"macOS":/Linux/.test(e)?"Linux":"Unknown OS"},x=e=>{try{let t=new URL(e.indexOf("http")===-1?`https:${e}`:e);return /^\/mbp\/\d+\/video\/[^/?#]+\.[^/?#]+$/i.test(t.pathname)}catch{return false}},F=e=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},N=e=>{if(!e)return 0;try{if(typeof e=="string")return new TextEncoder().encode(e).length;if(e instanceof Blob)return e.size;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e.byteLength;if(e instanceof URLSearchParams)return new TextEncoder().encode(e.toString()).length;if(e instanceof FormData){let t=0;for(let[r,n]of e.entries())t+=new TextEncoder().encode(r).length,typeof n=="string"?t+=new TextEncoder().encode(n).length:n instanceof Blob&&(t+=n.size);return t}}catch{return 0}return 0};var ot={browserInfo:be(),platform:xe()},k=ot;var Ce=k.browserInfor,J={user_agent:Ce?.name+Ce?.version,platform:k.platform},it=/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,at=10;function st(e){let t=e.match(it);if(!t)return {};let r=t[2]||"<anonymous>",n=t[1]||"",o=parseInt(t[3],10)||void 0,i=parseInt(t[4],10)||void 0;return {filename:r,functionName:n,lineno:o,colno:i}}function Ie(e){let{stack:t}=e;if(!t)return [];let r=[];for(let n of t.split(`
|
|
2
|
+
`).slice(1)){let o=st(n);o.filename&&r.push(o);}return r.slice(0,at)}function X(){window.addEventListener("error",async function(e){let t=e.target;if(t&&(t.src||t.href)){let r={error_type:"resource",...J,msg:F(`\u52A0\u8F7D${t.tagName}\u5931\u8D25\uFF1A${t.src||t.href}`),version:E};p("error",r);}else {let r=Ie(e.error),n=e.message;if(r?.[0]){let{filename:a,functionName:s,lineno:c,colno:l}=r[0];n=`${e.message},${a},line:${c}:${l}`;}let o={error_type:"js",msg:F(n),...J,version:E};p("error",o),await Le()&&p("error",{...o,error_type:"whiteScreen"});}},true),window.addEventListener("unhandledrejection",function(e){let t=e.reason,r=Ie(t),n=t;if(r?.[0]){let{filename:i,functionName:a,lineno:s,colno:c}=r[0];n=`${e?.reason?.message||e?.reason},${i},line:${s}:${c}`;}let o={error_type:"js",msg:F(n),...J,version:E};p("error",o);});}var Be=-1,I=e=>{addEventListener("pageshow",t=>{t.persisted&&(Be=t.timeStamp,e(t));},true);},T=(e,t,r,n)=>{let o,i;return a=>{t.value>=0&&(a||n)&&(i=t.value-(o??0),(i||o===void 0)&&(o=t.value,t.delta=i,t.rating=((s,c)=>s>c[1]?"poor":s>c[0]?"needs-improvement":"good")(t.value,r),e(t)));}},re=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()));},oe=()=>{let e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},R=()=>oe()?.activationStart??0,v=(e,t=-1)=>{let r=oe(),n="navigate";return Be>=0?n="back-forward-cache":r&&(document.prerendering||R()>0?n="prerender":document.wasDiscarded?n="restore":r.type&&(n=r.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:n}},G=new WeakMap;function ie(e,t){return G.get(e)||G.set(e,new t),G.get(e)}var Y=class{t;i=0;o=[];h(t){if(t.hadRecentInput)return;let r=this.o[0],n=this.o.at(-1);this.i&&r&&n&&t.startTime-n.startTime<1e3&&t.startTime-r.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),this.t?.(t);}},_=(e,t,r={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){let n=new PerformanceObserver(o=>{Promise.resolve().then(()=>{t(o.getEntries());});});return n.observe({type:e,buffered:!0,...r}),n}}catch{}},ae=e=>{let t=false;return ()=>{t||(e(),t=true);}},C=-1,Fe=new Set,Ee=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,Q=e=>{if(document.visibilityState==="hidden"){if(e.type==="visibilitychange")for(let t of Fe)t();isFinite(C)||(C=e.type==="visibilitychange"?e.timeStamp:0,removeEventListener("prerenderingchange",Q,true));}},H=()=>{if(C<0){let e=R();C=(document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter(r=>r.name==="hidden"&&r.startTime>e)[0]?.startTime)??Ee(),addEventListener("visibilitychange",Q,true),addEventListener("prerenderingchange",Q,true),I(()=>{setTimeout(()=>{C=Ee();});});}return {get firstHiddenTime(){return C},onHidden(e){Fe.add(e);}}},$=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),true):e();},Me=[1800,3e3],se=(e,t={})=>{$(()=>{let r=H(),n,o=v("FCP"),i=_("paint",a=>{for(let s of a)s.name==="first-contentful-paint"&&(i.disconnect(),s.startTime<r.firstHiddenTime&&(o.value=Math.max(s.startTime-R(),0),o.entries.push(s),n(true)));});i&&(n=T(e,o,Me,t.reportAllChanges),I(a=>{o=v("FCP"),n=T(e,o,Me,t.reportAllChanges),re(()=>{o.value=performance.now()-a.timeStamp,n(true);});}));});},De=[.1,.25],Ne=(e,t={})=>{let r=H();se(ae(()=>{let n,o=v("CLS",0),i=ie(t,Y),a=c=>{for(let l of c)i.h(l);i.i>o.value&&(o.value=i.i,o.entries=i.o,n());},s=_("layout-shift",a);s&&(n=T(e,o,De,t.reportAllChanges),r.onHidden(()=>{a(s.takeRecords()),n(true);}),I(()=>{i.i=0,o=v("CLS",0),n=T(e,o,De,t.reportAllChanges),re(()=>n());}),setTimeout(n));}));},qe=0,K=1/0,q=0,ct=e=>{for(let t of e)t.interactionId&&(K=Math.min(K,t.interactionId),q=Math.max(q,t.interactionId),qe=q?(q-K)/7+1:0);},Z,Oe=()=>Z?qe:performance.interactionCount??0,lt=()=>{"interactionCount"in performance||Z||(Z=_("event",ct,{type:"event",buffered:true,durationThreshold:0}));},ke=0,ee=class{u=[];l=new Map;m;p;v(){ke=Oe(),this.u.length=0,this.l.clear();}L(){let t=Math.min(this.u.length-1,Math.floor((Oe()-ke)/50));return this.u[t]}h(t){if(this.m?.(t),!t.interactionId&&t.entryType!=="first-input")return;let r=this.u.at(-1),n=this.l.get(t.interactionId);if(n||this.u.length<10||t.duration>r.P){if(n?t.duration>n.P?(n.entries=[t],n.P=t.duration):t.duration===n.P&&t.startTime===n.entries[0].startTime&&n.entries.push(t):(n={id:t.interactionId,entries:[t],P:t.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort((o,i)=>i.P-o.P),this.u.length>10){let o=this.u.splice(10);for(let i of o)this.l.delete(i.id);}this.p?.(n);}}},He=e=>{let t=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?e():(e=ae(e),addEventListener("visibilitychange",e,{once:true,capture:true}),t(()=>{e(),removeEventListener("visibilitychange",e,{capture:true});}));},Re=[200,500],$e=(e,t={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;let r=H();$(()=>{lt();let n,o=v("INP"),i=ie(t,ee),a=c=>{He(()=>{for(let u of c)i.h(u);let l=i.L();l&&l.P!==o.value&&(o.value=l.P,o.entries=l.entries,n());});},s=_("event",a,{durationThreshold:t.durationThreshold??40});n=T(e,o,Re,t.reportAllChanges),s&&(s.observe({type:"first-input",buffered:true}),r.onHidden(()=>{a(s.takeRecords()),n(true);}),I(()=>{i.v(),o=v("INP"),n=T(e,o,Re,t.reportAllChanges);}));});},te=class{m;h(t){this.m?.(t);}},_e=[2500,4e3],ze=(e,t={})=>{$(()=>{let r=H(),n,o=v("LCP"),i=ie(t,te),a=c=>{t.reportAllChanges||(c=c.slice(-1));for(let l of c)i.h(l),l.startTime<r.firstHiddenTime&&(o.value=Math.max(l.startTime-R(),0),o.entries=[l],n());},s=_("largest-contentful-paint",a);if(s){n=T(e,o,_e,t.reportAllChanges);let c=ae(()=>{a(s.takeRecords()),s.disconnect(),n(true);}),l=u=>{u.isTrusted&&(He(c),removeEventListener(u.type,l,{capture:true}));};for(let u of ["keydown","click","visibilitychange"])addEventListener(u,l,{capture:true});I(u=>{o=v("LCP"),n=T(e,o,_e,t.reportAllChanges),re(()=>{o.value=performance.now()-u.timeStamp,n(true);});});}});},Ae=[800,1800],ne=e=>{document.prerendering?$(()=>ne(e)):document.readyState!=="complete"?addEventListener("load",()=>ne(e),true):setTimeout(e);},Ue=(e,t={})=>{let r=v("TTFB"),n=T(e,r,Ae,t.reportAllChanges);ne(()=>{let o=oe();o&&(r.value=Math.max(o.responseStart-R(),0),r.entries=[o],n(true),I(()=>{r=v("TTFB",0),n=T(e,r,Ae,t.reportAllChanges),n(true);}));});};function ce(){Ne(A),$e(A),ze(A),se(A),Ue(A);}function A(e){let t={name:e.name,value:e.value};p("performance",t);}var z=XMLHttpRequest.prototype,ut=z.open,dt=z.send;function mt(){z.open=function(...t){this.url=t[1],this.method=t[0],ut.apply(this,t);},z.send=function(...t){this.startTime=Date.now();let r=t[0];this.requestSize=N(r);let n=()=>{this.endTime=Date.now(),this.duration=this.endTime-this.startTime;let{status:o,duration:i,startTime:a,endTime:s,method:c,response:l,requestSize:u}=this,{url:h}=this,g=o,w=h;try{g=JSON.parse(l).code;}catch{}let P={status:o,request_url:w,method:c||"GET",code:g};if(x(w)){P.request_url="https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video";try{P.request_size=parseInt(u/1e3),P.duration=i;}catch{}}p("api",P),this.removeEventListener("loadend",n,true);};this.addEventListener("loadend",n,true),dt.apply(this,t);};}function le(){mt();}var ft=window.fetch;function pt(){window.fetch=function(t,r){let n=Date.now(),o=t,i={request_url:o,method:r?.method||"GET"};if(x(o)){i.request_url="https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video";try{i.request_size=parseInt(N(r?.body)/1e3);}catch{}}return ft(t,r).then(a=>{let s=Date.now();x(o)&&(i.duration=s-n),i.status=a.status;let c=a.clone();return ht(t)&&(c.ok?c.json().then(l=>{i.code=l.code,p("api",i);}):(i.code=i.status,p("api",i))),a}).catch(a=>{let s=Date.now();return x(o)&&(i.duration=s-n),i.status=0,i.code=i.status,p("api",i),a})};}function ht(e){let t=true;return (e.indexOf(".js.map")!==-1||e.indexOf(".log.aliyuncs.com")!==-1)&&(t=false),t}function ue(){pt();}function de(){le(),ue();}async function We(e,{project:t,endpoint:r,logstore:n}){if(!t||!r||!n)return;let o=Math.floor(Date.now()/1e3),i={__logs__:e.map(u=>({__time__:o,...Object.keys(u).reduce((h,g)=>(h[g]=String(u[g]),h),{})})),__topic__:"default",__source__:"frontend"},a=JSON.stringify(i),s=`https://${t}.${r}/logstores/${n}/track?APIVersion=0.6.0`,c=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","x-log-apiversion":"0.6.0","x-log-bodyrawsize":a.length.toString()},body:a}),l=await c.text();if(!c.ok)throw new Error(`SLS API error: ${c.status} ${c.statusText} - ${l}`);return c}function gt(e,t,r=false){if(f.reportUrl===null){console.error("\u8BF7\u5148\u914D\u7F6E\u4E0A\u62A5\u5730\u5740");return}let n=[{user_id:Number(f.userId)||0,source:f.source,type:e,url:window.location.pathname,data:t}];if(r){me(n);return}window.requestIdleCallback?window.requestIdleCallback(()=>{me(n);},{timeout:3e3}):me(n);}var je=null;function U(e,t,r,n=3e3){if(t=JSON.stringify({...k,...t}),we(e,t),r){Ve(r);return}clearTimeout(je),je=setTimeout(()=>{Ve();},n);}function Ve(e=false){let t=ye();if(t.size){for(let[r,n]of t)gt(r,n,e);Se();}}function me(e){We(e,{project:f.slsProject,endpoint:f.slsEndpoint,logstore:f.slsLogstore}).catch(t=>{console.error("[reporting-lib] SLS\u4E0A\u62A5\u5931\u8D25:",t);});}function Je(e,t={}){let{minDuration:r=1e3,debounceMs:n=300}=t,o=false,i=null,a=Date.now(),s=(()=>{try{return window.location?.pathname||"/"}catch{return "/"}})(),c,l=false,u=(d,m,S)=>{o||(i&&clearTimeout(i),i=setTimeout(()=>{if(!o&&m>=r)try{e(m,d,S),o=!0;}catch(b){console.error("[trackPageStayTime] onLeave callback error:",b);}},n));},h=()=>{if(document.visibilityState==="hidden"){let d=Date.now(),m=d-a;u("visibilitychange-hidden",m,{startTime:a,endTime:d,pagePath:s,pageTag:c});}else if(document.visibilityState==="visible"){a=Date.now();try{s=window.location?.pathname||s;}catch{}o=false;}};document.addEventListener("visibilitychange",h);let g=d=>{let m=Date.now(),S=m-a,b={startTime:a,endTime:m,pagePath:s,pageTag:c};d.persisted?u("pagehide-bfcache",S,b):u("pagehide",S,b);};window.addEventListener("pagehide",g);let w=()=>{if(!o){let d=Date.now(),m=d-a,S={startTime:a,endTime:d,pagePath:s,pageTag:c};if(m>=r)try{e(m,"beforeunload",S),o=!0;}catch(b){console.error("[trackPageStayTime] onLeave callback error:",b);}}};window.addEventListener("beforeunload",w);let P=()=>{let d=Date.now(),m=d-a;u("popstate",m,{startTime:a,endTime:d,pagePath:s,pageTag:c});};window.addEventListener("popstate",P);let W=()=>{a=Date.now();try{s=window.location?.pathname||s;}catch{}o=false,i&&(clearTimeout(i),i=null);},fe=(d="manual")=>{let m=Date.now(),S=m-a;u(d,S,{startTime:a,endTime:m,pagePath:s,pageTag:c}),d==="route-change"&&setTimeout(()=>{W();},n+50);},pe=d=>{c=d||void 0,d&&(l=true);};return {manualLeave:fe,reset:W,stop:()=>{i&&(clearTimeout(i),i=null),document.removeEventListener("visibilitychange",h),window.removeEventListener("pagehide",g),window.removeEventListener("beforeunload",w),window.removeEventListener("popstate",P);},getCurrentDuration:()=>{let d=Date.now();return document.visibilityState==="visible"?d-a:0},setPageTag:pe,switchPageTag:(d,m="page-tag-change")=>{c&&c!==d?(o=false,fe(m),a=Date.now()):l||(a=Date.now(),o=false),pe(d);}}}var Tt=e=>{try{if(e)return e||"/";let{pathname:t="/"}=window.location||{};return t||"/"}catch{return "/"}},Xe=(e,t,r,n={})=>{let{startTime:o,endTime:i,pagePath:a,pageTag:s}=r,c=Tt(a),l=s?`${c}#${s}`:c,{formatPageName:u}=n;return {pageName:typeof u=="function"?u(l,{duration:e,reason:t,...r}):l,duration:e,startTime:o,endTime:i}};var y=null,L=null;function vt(e={},t,r){let{enabled:n,minDuration:o,debounceMs:i,onLeave:a}=e;n?(y&&(y.stop(),y=null),y=Je(a||r||((c,l,u)=>{}),{minDuration:o,debounceMs:i}),t&&t.listen&&(L&&(L(),L=null),L=t.listen(({location:c,action:l})=>{y&&(l==="PUSH"||l==="REPLACE")&&y.manualLeave("route-change");}))):y&&(y.stop(),y=null,L&&(L(),L=null));}function Ge(e,t){y?.switchPageTag(e,t);}function Ke(e,t){if(!e)return;vt(e,t,(n,o,i)=>{let a=Xe(n,o,i||{startTime:0,endTime:0},{formatPageName:e?.formatPageName});U("pd",a);});}function Ye(e,t){let r=t||f.history;return !r||!r.listen?(console.warn("[reporting-lib] No history instance available. Please provide history in init() or pass it as parameter."),()=>{}):r.listen(e)}var Qe=false,yt={init(e={}){he(e),Ke(e.trackPageStayTime,e.history),Qe||(X(),ce(),de(),Qe=true);},reportToSLS(e,t={},r={}){let{immediate:n=false,timeout:o=3e3}=r;U(e,t,n,o);},switchPageTag(e,t="page-tag-change"){Ge(e,t);},listenRouteChange(e,t){return Ye(e,t)}},Cn=yt;
|
|
3
3
|
module.exports=Cn;//# sourceMappingURL=index.cjs.map
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|