pxt-core
Version:
Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors
1 lines • 5.12 kB
JavaScript
var pxt;"undefined"==typeof navigator||!/Trident/i.test(navigator.userAgent)||/skipbrowsercheck=1/i.exec(window.location.href)||/\/browsers/i.exec(window.location.href)||(window.location.href="/browsers"),function(e){const t=[];let r,o,n,s,i=!1,a=!1,p=!1;class c{constructor(e){this.log=e,this.q=[],t.push(this)}track(e,t,r){i?this.log(e,t,r):(this.q.push([e,t,r]),this.q.length>20&&this.q.shift())}flush(){for(;this.q.length;){const[e,t,r]=this.q.shift();this.log(e,t,r)}}}function f(e){e=e||(()=>!0);const t=[],r=[];return{subscribe:o=>(r.forEach((t=>e(t)&&o(t))),t.push(o),()=>{const e=t.indexOf(o);-1!==e&&t.splice(e,1)}),emit(o){r.push(o),e(o)&&t.forEach((e=>e(o)))},forEach(t){r.forEach((r=>e(r)&&t(r)))}}}function l(e=!1){try{const e=new URLSearchParams(window.location.search);e.has("partner")&&(r=e.get("partner"))}catch(e){console.warn("Could not parse search string",e)}const o=window.loadAppInsights;o&&(p=o(e,m),i=!0,t.forEach((e=>e.flush())))}function m(e){const t=window.pxtConfig;if("PageviewData"==e.baseType&&!e.baseData.properties)return!1;if("PageviewPerformanceData"==e.baseType){const t=e.baseData.name;e.baseData.name=window.location.origin,e.baseData.properties||(e.baseData.properties={}),e.baseData.properties.pageName=t,e.baseData.properties.pathName=window.location.pathname}if(void 0===t||!t)return!0;const o=e.baseData;o.properties=o.properties||{},o.properties.target=t.targetId,o.properties.stage=(t.relprefix||"/--").replace(/[^a-z]/gi,""),o.properties.targetVersion=t.targetVersion,o.properties.pxtVersion=t.pxtVersion,r&&(o.properties.partner=r);const n=navigator.userAgent.toLowerCase(),s=/\belectron\/(\d+\.\d+\.\d+.*?)(?: |$)/i.exec(n);s&&(o.properties.Electron=1,o.properties.ElectronVersion=s[1]);const i=window.pxtElectron;void 0!==i&&(o.properties.PxtElectron=1,o.properties.ElectronVersion=i.versions.electronVersion,o.properties.ChromiumVersion=i.versions.chromiumVersion,o.properties.NodeVersion=i.versions.nodeVersion,o.properties.PxtElectronVersion=i.versions.pxtElectronVersion,o.properties.PxtCoreVersion=i.versions.pxtCoreVersion,o.properties.PxtTargetVersion=i.versions.pxtTargetVersion,o.properties.PxtElectronIsProd=i.versions.isProd);const c=/\((MakeCode Arcade Kiosk UWP)\/([\S]+)\/([\S]+)\)/i.exec(n);return c&&(o.properties.KioskUwp=1,o.properties.KioskUwpVersion=c[2],o.properties.KioskUwpPlatform=c[3]),o.properties.cookie=a&&p,!0}!function(e){let t;function r(){return Math.round(performance.now()-e.startTimeMs)}function o(e){let t=(e=Math.round(e))%1e3,r=Math.floor(e/1e3),o=r%60,n=Math.floor(r/60);return n>0?`${n}m${o}s`:r>5?`${r}s`:r>0?`${r}s${t}ms`:`${e}ms`}function n(t,o){const n=r();e.stats.milestones.emit({milestone:t,time:n,params:o})}function s(){if(t=performance&&!!performance.mark&&!!performance.measure,t){performance.measure("measure from the start of navigation to now");let t=performance.getEntriesByType("measure")[0];e.startTimeMs=t.startTime}}e.measurementThresholdMs=10,e.stats={durations:f((t=>t.duration>=e.measurementThresholdMs)),milestones:f()},e.isEnabled=function(){return t},e.perfReportLogged=!1,e.splitMs=r,e.prettyStr=o,e.splitStr=function(){return o(r())},e.recordMilestone=n,e.init=s,e.measureStart=function(e){t&&performance.mark(`${e} start`)},e.measureEnd=function(r,o){if(t&&performance.getEntriesByName(`${r} start`).length){performance.mark(`${r} end`),performance.measure(`${r} elapsed`,`${r} start`,`${r} end`);let t=performance.getEntriesByName(`${r} elapsed`,"measure");if(t&&1===t.length){let n=t[0],s=n.duration;e.stats.durations.emit({name:r,start:n.startTime,duration:s,params:o})}performance.clearMarks(`${r} start`),performance.clearMarks(`${r} end`),performance.clearMeasures(`${r} elapsed`)}},e.report=function(){if(e.perfReportLogged=!0,t){const r={},n={};let s="Performance Report:\n";return s+="\n",s+="\tMilestones:\n",e.stats.milestones.forEach((({milestone:e,time:t,params:n})=>{let i=o(t);s+=`\t\t${e} @ ${i}`;for(let e of Object.keys(n||{}))s+=`\n\t\t\t${e}: ${n[e]}`;s+="\n",r[e]=t})),s+="\n",s+="\tMeasurements:\n",e.stats.durations.forEach((({name:e,start:t,duration:r,params:i})=>{let a=o(r);s+=`\t\t${e} took ~ ${a}`,s+=` (${o(t)} - ${o(t+r)})`;for(let e of Object.keys(i||{}))s+=`\n\t\t\t${e}: ${i[e]}`;s+="\n",n[e]=r})),console.log(s),t=!1,{milestones:r,durations:n}}},s(),n("first JS running")}(s=e.perf||(e.perf={})),e.initAnalyticsAsync=function(){(function(){const e="undefined"!=typeof window,t=e&&!!window.pxtElectron,r=e&&!!window.ipcRenderer||/ipc=1/.test(location.hash)||/ipc=1/.test(location.search);return t||r})()||function(){try{return window&&window.self!==window.top}catch(e){return!1}}()&&/nocookiebanner=1/i.test(window.location.href)?l(!0):window.pxtSkipAnalyticsCookie?l(!1):l(!0)},e.aiTrackEvent=function(e,t,r){o||(o=new c(((e,t,r)=>window.appInsights.trackEvent({name:e,properties:t,measurements:r})))),o.track(e,t,r)},e.aiTrackException=function(e,t,r){n||(n=new c(((e,t,r)=>window.appInsights.trackException({exception:e,properties:t?{...r,kind:t}:r})))),n.track(e,t,r)},e.initializeAppInsightsInternal=l,e.setInteractiveConsent=function(e){a=e}}(pxt||(pxt={}));