{"version":3,"sources":["../../src/utils/formatters.ts"],"names":["formatTime","ms","formatted","toFixed","leftPad","string","length","padLength","Math","max","repeat","rightPad","formatValue","v","options","EPSILON","isInteger","Array","isArray","ArrayBuffer","isView","formatArrayValue","Number","isFinite","String","abs","toPrecision","decimal","indexOf","slice","maxElts","size","i","terminator","formatImage","image","message","scale","maxWidth","imageUrl","src","replace","width","min","height","style","floor","join"],"mappings":"AAWA,OAAO,SAASA,UAAT,CAAoBC,EAApB,EAAwC;AAC7C,MAAIC,SAAJ;;AACA,MAAID,EAAE,GAAG,EAAT,EAAa;AACXC,IAAAA,SAAS,GAAI,GAAED,EAAE,CAACE,OAAH,CAAW,CAAX,CAAc,IAA7B;AACD,GAFD,MAEO,IAAIF,EAAE,GAAG,GAAT,EAAc;AACnBC,IAAAA,SAAS,GAAI,GAAED,EAAE,CAACE,OAAH,CAAW,CAAX,CAAc,IAA7B;AACD,GAFM,MAEA,IAAIF,EAAE,GAAG,IAAT,EAAe;AACpBC,IAAAA,SAAS,GAAI,GAAED,EAAE,CAACE,OAAH,CAAW,CAAX,CAAc,IAA7B;AACD,GAFM,MAEA;AACLD,IAAAA,SAAS,GAAI,GAAE,CAACD,EAAE,GAAG,IAAN,EAAYE,OAAZ,CAAoB,CAApB,CAAuB,GAAtC;AACD;;AACD,SAAOD,SAAP;AACD;AAED,OAAO,SAASE,OAAT,CAAiBC,MAAjB,EAA6D;AAAA,MAA5BC,MAA4B,uEAAX,CAAW;AAClE,QAAMC,SAAS,GAAGC,IAAI,CAACC,GAAL,CAASH,MAAM,GAAGD,MAAM,CAACC,MAAzB,EAAiC,CAAjC,CAAlB;AACA,SAAQ,GAAE,IAAII,MAAJ,CAAWH,SAAX,CAAsB,GAAEF,MAAO,EAAzC;AACD;AAED,OAAO,SAASM,QAAT,CAAkBN,MAAlB,EAA8D;AAAA,MAA5BC,MAA4B,uEAAX,CAAW;AACnE,QAAMC,SAAS,GAAGC,IAAI,CAACC,GAAL,CAASH,MAAM,GAAGD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Q,KAAK,GAAG,CACZ,gBADY,EAEX,WAAUrC,IAAI,CAACsC,KAAL,CAAWF,MAAM,GAAG,CAApB,CAAuB,MAAKpC,IAAI,CAACsC,KAAL,CAAWJ,KAAK,GAAG,CAAnB,CAAsB,KAFjD,EAGX,eAAcE,MAAO,KAHV,EAIX,kBAAiBL,QAAS,IAJf,EAKX,mBAAkBG,KAAM,MAAKE,MAAO,KALzB,EAMZ,oBANY,EAOZG,IAPY,CAOP,EAPO,CAAd;AASA,SAAO,CAAE,GAAEX,OAAQ,MAAZ,EAAmBS,KAAnB,CAAP;AACD","sourcesContent":["// probe.gl, MIT license\n\nexport type FormatValueOptions = {\n isInteger?: boolean;\n maxElts?: number;\n size?: number;\n};\n\n/**\n * Format time\n */\nexport function formatTime(ms: number): string {\n let formatted;\n if (ms < 10) {\n formatted = `${ms.toFixed(2)}ms`;\n } else if (ms < 100) {\n formatted = `${ms.toFixed(1)}ms`;\n } else if (ms < 1000) {\n formatted = `${ms.toFixed(0)}ms`;\n } else {\n formatted = `${(ms / 1000).toFixed(2)}s`;\n }\n return formatted;\n}\n\nexport function leftPad(string: string, length: number = 8): string {\n const padLength = Math.max(length - string.length, 0);\n return `${' '.repeat(padLength)}${string}`;\n}\n\nexport function rightPad(string: string, length: number = 8): string {\n const padLength = Math.max(length - string.length, 0);\n return `${string}${' '.repeat(padLength)}`;\n}\n\nexport function formatValue(v: unknown, options: FormatValueOptions = {}): string {\n const EPSILON = 1e-16;\n const {isInteger = false} = options;\n if (Array.isArray(v) || ArrayBuffer.isView(v)) {\n return formatArrayValue(v, options);\n }\n if (!Number.isFinite(v)) {\n return String(v);\n }\n // @ts-expect-error\n if (Math.abs(v) < EPSILON) {\n return isInteger ? '0' : '0.';\n }\n if (isInteger) {\n // @ts-expect-error\n return v.toFixed(0);\n }\n // @ts-expect-error\n if (Math.abs(v) > 100 && Math.abs(v) < 10000) {\n // @ts-expect-error\n return v.toFixed(0);\n }\n // @ts-expect-error\n const string = v.toPrecision(2);\n const decimal = string.indexOf('.0');\n return decimal === string.length - 2 ? string.slice(0, -1) : string;\n}\n\n/** Helper to formatValue */\nfunction formatArrayValue(v: any, options: FormatValueOptions) {\n const {maxElts = 16, size = 1} = options;\n let string = '[';\n for (let i = 0; i < v.length && i < maxElts; ++i) {\n if (i > 0) {\n string += `,${i % size === 0 ? ' ' : ''}`;\n }\n string += formatValue(v[i], options);\n }\n const terminator = v.length > maxElts ? '...' : ']';\n return `${string}${terminator}`;\n}\n\n/**\n * Log an image to the console (uses browser specific console formatting styles)\n * Inspired by https://github.com/hughsk/console-image (MIT license)\n */\nexport function formatImage(image: any, message: string, scale: number, maxWidth: number = 600) {\n const imageUrl = image.src.replace(/\\(/g, '%28').replace(/\\)/g, '%29');\n\n if (image.width > maxWidth) {\n scale = Math.min(scale, maxWidth / image.width);\n }\n\n const width = image.width * scale;\n const height = image.height * scale;\n\n const style = [\n 'font-size:1px;',\n `padding:${Math.floor(height / 2)}px ${Math.floor(width / 2)}px;`,\n `line-height:${height}px;`,\n `background:url(${imageUrl});`,\n `background-size:${width}px ${height}px;`,\n 'color:transparent;'\n ].join('');\n\n return [`${message} %c+`, style];\n}\n"],"file":"formatters.js"}