"use strict";var d=require("worker_threads");function C(t,e){for(let a in e)if(!(a in t))return!1;return!0}var f={major:4,minor:5};var y=1;var x=["text/plain","text/markdown","text/latex","application/vnd.code.notebook.stderr","application/vnd.code.notebook.stdout"];var l=new TextDecoder;function I(t,e){let a;return t.kind===y?a=E(t):t.languageId==="raw"?a=S(t):a=M(t,e),a}function b(t){return Array.isArray(t)?t.map(b):t!=null&&typeof t=="object"&&Object.keys(t).length>0?Object.keys(t).sort().reduce((e,a)=>(e[a]=b(t[a]),e),{}):t}function g(t){if(C(t,{cell:!0})){let e=t.cell,a={execution_count:null,...e.metadata??{}};return e.kind===y&&delete a.execution_count,a}else return{...t.metadata??{}}}function N(t,e){t.metadata=t.metadata||{},t.metadata.vscode={languageId:e}}function h(t){t.metadata?.vscode&&delete t.metadata.vscode}function M(t,e){let a=JSON.parse(JSON.stringify(g({cell:t})));a.metadata=a.metadata||{},t.languageId!==e?N(a,t.languageId):h(a);let n={cell_type:"code",execution_count:a.execution_count??null,source:k(t.value),outputs:(t.outputs||[]).map(w),metadata:a.metadata};return a?.id&&(n.id=a.id),n}function S(t){let e=g({cell:t}),a={cell_type:"raw",source:k(t.value),metadata:e?.metadata||{}};return e?.attachments&&(a.attachments=e.attachments),e?.id&&(a.id=e.id),a}function k(t){return u(t.replace(/\r\n/g,`
`))}function u(t){if(Array.isArray(t))return t;let e=t.toString();if(e.length>0){let a=e.split(`
`);return a.map((n,o)=>o<a.length-1?`${n}
`:n).filter(n=>n.length>0)}return[]}function w(t){let e=t.metadata,a;switch(e?.outputType){case"error":{a=O(t);break}case"stream":{a=_(t);break}case"display_data":{a={output_type:"display_data",data:t.items.reduce((o,r)=>(o[r.mime]=m(r.mime,r.data),o),{}),metadata:e?.metadata||{}};break}case"execute_result":{a={output_type:"execute_result",data:t.items.reduce((o,r)=>(o[r.mime]=m(r.mime,r.data),o),{}),metadata:e?.metadata||{},execution_count:typeof e?.executionCount=="number"?e?.executionCount:null};break}case"update_display_data":{a={output_type:"update_display_data",data:t.items.reduce((o,r)=>(o[r.mime]=m(r.mime,r.data),o),{}),metadata:e?.metadata||{}};break}default:{let o=t.items.length===1&&t.items.every(s=>s.mime==="application/vnd.code.notebook.error"),r=t.items.every(s=>s.mime==="application/vnd.code.notebook.stderr"||s.mime==="application/vnd.code.notebook.stdout");if(o)return O(t);let c=e?.outputType||(r?"stream":"display_data"),i;c==="stream"?i=_(t):c==="display_data"?i={data:{},metadata:{},output_type:"display_data"}:i={output_type:c},e?.metadata&&(i.metadata=e.metadata),t.items.length>0&&(i.data=t.items.reduce((s,p)=>(s[p.mime]=m(p.mime,p.data),s),{})),a=i;break}}return a&&e&&e.transient&&(a.transient=e.transient),a}function O(t){let e=t.items[0];if(!e.data)return{output_type:"error",ename:"",evalue:"",traceback:[]};let a=t.metadata?.originalError,n=JSON.parse(l.decode(e.data));return{output_type:"error",ename:n.name,evalue:n.message,traceback:a?.traceback||u(n.stack||n.message||"")}}function D(t){if(t.items.length>0)return t.items[0].mime==="application/vnd.code.notebook.stderr"?"stderr":"stdout"}function _(t){let e=[];t.items.filter(n=>n.mime==="application/vnd.code.notebook.stderr"||n.mime==="application/vnd.code.notebook.stdout").map(n=>l.decode(n.data)).forEach(n=>{let o=n.split(`
`);e.length&&o.length&&o[0].length>0&&(e[e.length-1]=`${e[e.length-1]}${o.shift()}`);for(let r of o)e.push(r)});for(let n=0;n<e.length-1;n++)e[n]=`${e[n]}
`;return e.length&&e[e.length-1].length===0&&e.pop(),{output_type:"stream",name:D(t)||"stdout",text:e}}function m(t,e){if(!e)return"";try{if(t==="application/vnd.code.notebook.error"){let a=l.decode(e);return JSON.parse(a)}else if(t.startsWith("text/")||x.includes(t)){let a=l.decode(e);return u(a)}else{if(t.startsWith("image/")&&t!=="image/svg+xml")return typeof Buffer<"u"&&typeof Buffer.from=="function"?Buffer.from(e).toString("base64"):btoa(e.reduce((a,n)=>a+String.fromCharCode(n),""));if(t.toLowerCase().includes("json")){let a=l.decode(e);return a.length>0?JSON.parse(a):a}else return t==="image/svg+xml"?u(l.decode(e)):l.decode(e)}}catch{return""}}function E(t){let e=g({cell:t}),a={cell_type:"markdown",source:k(t.value),metadata:e?.metadata||{}};return e?.attachments&&(a.attachments=e.attachments),e?.id&&(a.id=e.id),a}function A(t){let e={...t,source:u(t.source)};return e.cell_type!=="code"?(delete e.outputs,delete e.execution_count):e.outputs=e.outputs?e.outputs.map(U):[],e}var K={output_type:"stream",name:"stdout",text:""},R={output_type:"error",ename:"",evalue:"",traceback:[""]},J={output_type:"display_data",data:{},metadata:{}},v={output_type:"execute_result",name:"",execution_count:0,data:{},metadata:{}},j={stream:new Set(Object.keys(K)),error:new Set(Object.keys(R)),display_data:new Set(Object.keys(J)),execute_result:new Set(Object.keys(v))};function U(t){let e;switch(t.output_type){case"stream":case"error":case"execute_result":case"display_data":e=j[t.output_type];break;default:return t}let a={...t};for(let n of Object.keys(t))e.has(n)||delete a[n];return a}function T(t){let e=P(t),a=e.metadata?.language_info?.name??t.cells.find(o=>o.kind===2)?.languageId;e.cells=t.cells.map(o=>I(o,a)).map(A);let n=t.metadata&&typeof t.metadata.indentAmount=="string"?t.metadata.indentAmount:" ";return F(e,n)}function F(t,e){let a=b(t);return JSON.stringify(a,void 0,e)+`
`}function P(t){let e=t.metadata||{},a={};return a.cells=e.cells||[],a.nbformat=e.nbformat||f.major,a.nbformat_minor=e.nbformat_minor??f.minor,a.metadata=e.metadata||{},a}d.parentPort&&d.parentPort.on("message",({id:t,data:e})=>{if(d.parentPort){let a=T(e),n=new TextEncoder().encode(a);d.parentPort.postMessage({id:t,data:n})}});
//# sourceMappingURL=notebookSerializerWorker.js.map
