"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.deserialize=exports.serialize=exports.isSerializableObject=exports.isPromise=void 0;let electron_1=require("electron");function isPromise(e){return e&&e.then&&e.then instanceof Function&&e.constructor&&e.constructor.reject&&e.constructor.reject instanceof Function&&e.constructor.resolve&&e.constructor.resolve instanceof Function}exports.isPromise=isPromise;let serializableTypes=[Boolean,Number,String,Date,Error,RegExp,ArrayBuffer];function isSerializableObject(e){return null===e||ArrayBuffer.isView(e)||serializableTypes.some(t=>e instanceof t)}exports.isSerializableObject=isSerializableObject;let objectMap=function(e,t){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e,t(r)]))};function serializeNativeImage(e){let t=[],r=e.getScaleFactors();if(1===r.length){let i=r[0],a=e.getSize(i),s=e.toBitmap({scaleFactor:i});t.push({scaleFactor:i,size:a,buffer:s})}else for(let i of r){let r=e.getSize(i),a=e.toDataURL({scaleFactor:i});t.push({scaleFactor:i,size:r,dataURL:a})}return{__ELECTRON_SERIALIZED_NativeImage__:!0,representations:t}}function deserializeNativeImage(e){let t=electron_1.nativeImage.createEmpty();if(1===e.representations.length){let{buffer:r,size:i,scaleFactor:a}=e.representations[0],{width:s,height:n}=i;t.addRepresentation({buffer:r,scaleFactor:a,width:s,height:n})}else for(let r of e.representations){let{dataURL:e,size:i,scaleFactor:a}=r,{width:s,height:n}=i;t.addRepresentation({dataURL:e,scaleFactor:a,width:s,height:n})}return t}function serialize(e){return e&&e.constructor&&"NativeImage"===e.constructor.name?serializeNativeImage(e):Array.isArray(e)?e.map(serialize):isSerializableObject(e)?e:e instanceof Object?objectMap(e,serialize):e}function deserialize(e){return e&&e.__ELECTRON_SERIALIZED_NativeImage__?deserializeNativeImage(e):Array.isArray(e)?e.map(deserialize):isSerializableObject(e)?e:e instanceof Object?objectMap(e,deserialize):e}exports.serialize=serialize,exports.deserialize=deserialize;