{"version":3,"file":"index.cjs","sources":["../src/lib/const/pattern.ts","../src/lib/image-processing/image-event.ts","../src/lib/image-processing/loader.ts","../src/lib/math/covarianceMatrix.ts","../src/lib/math/dotProduct.ts","../src/lib/math/euclideanDistance.ts","../src/lib/math/invertMatrix.ts","../src/lib/math/transpose.ts","../src/lib/math/mahalanobisDistance.ts","../src/lib/computing/kMeansPP.ts","../src/lib/color/color-detection.ts","../src/lib/color/color-space.ts"],"sourcesContent":["const URL_PATTERN = /^(http|https):\\/\\/.*$/;\nconst FILE_PATH_PATTERN = /^\\/|\\\\\\\\|\\.\\.|\\.\\\\.$/;\n\nexport { FILE_PATH_PATTERN, URL_PATTERN };\n","/**\n * Generates the image data from an ImageBitmap or HTMLImageElement without accessing the DOM.\n * @param imageBitmap - The ImageBitmap or HTMLImageElement to generate the image data from.\n * @return The generated image data.\n * @throws Thrown if the rendering context is lost.\n */\nexport const getImageDataWithoutDomAccess = (\n  imageBitmap: ImageBitmap | HTMLImageElement,\n) => {\n  const canvas = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);\n  const ctx = canvas.getContext('2d') as OffscreenCanvasRenderingContext2D;\n  if (ctx) {\n    ctx.drawImage(imageBitmap, 0, 0);\n    return ctx.getImageData(0, 0, imageBitmap.width, imageBitmap.height);\n  }\n\n  throw new Error('context lost');\n};\n\n/**\n * Converts an ImageData object into a matrix representation.\n * @param imageData - The ImageData object to convert.\n * @return The matrix representation of the image data.\n*/\n\nexport const imageToMatrix = (imageData: ImageData) => Array.from({ length: imageData.data.length / 4 }, (_, i) => {\n    const r = imageData.data[i * 4];\n    const g = imageData.data[i * 4 + 1];\n    const b = imageData.data[i * 4 + 2];\n    const a = imageData.data[i * 4 + 3];\n\n    return [r, g, b, a / 255];\n  });\n\n/**\n * Generates a matrix representation of the given image.\n * @param image - The image to convert to a matrix.\n * @return The matrix representation of the image.\n */\nexport const getImageMatrix = (image: HTMLImageElement | ImageBitmap) => {\n  const imageData = getImageDataWithoutDomAccess(image);\n  return imageToMatrix(imageData);\n};\n","import type { ImageSource } from '../types/index.js';\nimport { getImageMatrix } from './image-event.js';\n\ntype OptionsLoader = {\n   AccessControlAllowOrigin?: RequestMode,\n};\n/**\n * Converts a Blob into a matrix representation of an image.\n *\n * @param blob - The Blob object representing the image.\n * @return The matrix representation of the image.\n */\nexport const blobToMatrix = async (blob: Blob) => {\n  const imageBitmap = await createImageBitmap(blob);\n  return getImageMatrix(imageBitmap);\n};\n\n/**\n * Asynchronously loads a target, which can be a string or an ArrayBuffer,\n * and returns the result as a matrix using blobToMatrix function.\n *\n * @param target - The target to load, either a string URL\n * or an ArrayBuffer containing the image data.\n * @param options - The options for loading the target.\n * @throws Throws an error if the image is not found.\n * @return A Promise that resolves to the matrix representation\n * of the loaded image.\n */\nasync function loader<T extends ImageSource>(\n  target: T,\n  options: (T extends string ? OptionsLoader : {}) = {},\n) {\n  const { AccessControlAllowOrigin } = options as OptionsLoader;\n\n  if (typeof target === 'string') {\n    const response = await fetch(target, { mode: AccessControlAllowOrigin });\n    if (!response.ok) {\n      throw new Error('image not found');\n    }\n      const result = await blobToMatrix(await response.blob());\n      return result;\n  }\n\n  const result = await blobToMatrix(new Blob([target], { type: 'image/png' }));\n  return result;\n}\n\nexport { loader };\n","/**\n * Calculates the covariance matrix for the given data.\n *\n * @param data - The input data for which to calculate the covariance matrix.\n * @return The covariance matrix.\n */\nexport function covarianceMatrix(data: number[][]) {\n  if (data.length === 0) {\n    return data;\n  }\n\n  const mean = data[0].map((_, i) => data.reduce((sum, row) => sum + row[i], 0) / data.length);\n  const covariance = data[0].map((_, indexI) => data[0].map((__, indexJ) => {\n        const sum = data.reduce((accumulator, row) => {\n            const diffProduct = (row[indexI] - mean[indexI]) * (row[indexJ] - mean[indexJ]);\n            return accumulator + diffProduct;\n        }, 0);\n        return sum / (data.length - 1);\n    }));\n  return covariance;\n}\n","export function dotProduct(matrixA: number[][], matrixB: number[][]) {\n  const rowsA = matrixA.length;\n  const colsA = matrixA[0].length;\n  const rowsB = matrixB.length;\n  const colsB = matrixB[0].length;\n\n  if (colsA !== rowsB) {\n    throw new Error(\n      'The number of columns in matrix A must match the number of rows in matrix B',\n    );\n  }\n\n  const result = Array.from({ length: rowsA }, () => Array(colsB).fill(0));\n\n  for (let i = 0; i < rowsA; i += 1) {\n    for (let j = 0; j < colsB; j += 1) {\n      result[i][j] = matrixA[i].reduce((sum, _, k) => sum + matrixA[i][k] * matrixB[k][j], 0);\n    }\n  }\n\n  return result;\n}\n","export function euclideanDistance(coords1: number[], coords2: number[]) {\n  return Math.hypot(...Object.keys(coords1).map((k) => coords2[parseInt(k, 10)] - coords1[parseInt(k, 10)]));\n}\n","/* eslint-disable no-param-reassign */\n\n/**\n * Inverts a given matrix.\n *\n * @param matrix - The matrix to be inverted.\n * @return The inverted matrix.\n */\nexport function invertMatrix(matrix: number[][]): number[][] {\n  const n = matrix.length;\n  const identityMatrix: number[][] = [];\n  for (let i = 0; i < n; i += 1) {\n    identityMatrix[i] = [];\n    for (let j = 0; j < n; j += 1) {\n      identityMatrix[i][j] = i === j ? 1 : 0;\n    }\n  }\n\n  for (let i = 0; i < n; i += 1) {\n    let maxRow = i;\n    for (let j = i + 1; j < n; j += 1) {\n      if (Math.abs(matrix[j][i]) > Math.abs(matrix[maxRow][i])) {\n        maxRow = j;\n      }\n    }\n\n    const temp = matrix[i];\n    matrix[i] = matrix[maxRow];\n    matrix[maxRow] = temp;\n\n    const tempIdentity = identityMatrix[i];\n    identityMatrix[i] = identityMatrix[maxRow];\n    identityMatrix[maxRow] = tempIdentity;\n\n    const divisor = matrix[i][i];\n    for (let j = 0; j < n; j += 1) {\n      matrix[i][j] /= divisor;\n      identityMatrix[i][j] /= divisor;\n    }\n\n    for (let j = 0; j < n; j += 1) {\n      if (j !== i) {\n        const factor = matrix[j][i];\n        for (let k = 0; k < n; k += 1) {\n          matrix[j][k] -= matrix[i][k] * factor;\n          identityMatrix[j][k] -= identityMatrix[i][k] * factor;\n        }\n      }\n    }\n  }\n\n  return identityMatrix;\n}\n","/**\n * Transposes a matrix.\n * @param matrix - The matrix to be transposed.\n * @return The transposed matrix.\n */\nexport function transpose(matrix: number[][]): number[][] {\n  const rows = matrix.length;\n  const columns = matrix[0].length;\n  const result = Array.from({ length: columns }, (_, i) => Array.from({ length: rows }, (__, j) => matrix[j][i]));\n  return result;\n}\n","import { dotProduct } from './dotProduct.js';\nimport { invertMatrix } from './invertMatrix.js';\nimport { transpose } from './transpose.js';\n\n/**\n * Calculates the Mahalanobis distance between a point and a multivariate distribution.\n *\n * @param x - The coordinates of the point.\n * @param mean - The mean vector of the distribution.\n * @param cov - The covariance matrix of the distribution.\n * @return The Mahalanobis distance between the point and the distribution.\n */\nexport function mahalanobisDistance(\n  x: number[],\n  mean: number[],\n  cov: number[][],\n) {\n  const delta = x.map((val, index) => [val - mean[index]]);\n  const invertedCov = invertMatrix(cov);\n  const deltaTransposed = transpose(delta);\n  const product = dotProduct(deltaTransposed, invertedCov);\n  const result = dotProduct(product, delta);\n  return Math.sqrt(result[0][0]);\n}\n","import { covarianceMatrix, mahalanobisDistance, euclideanDistance } from '../math/index.js';\nimport type { DistanceType, RGBAColor } from '../types/index.js';\n\n/**\n * Calculates the Euclidean distances between each data point and the centroids.\n * @param data Array of data points.\n * @param centroids Number of centroids.\n * @return An array of the computed Euclidean distances.\n */\nfunction computeEuclideanDistances(data: number[][], centroids: number[][]) {\n  return data.map((x) => centroids.reduce((min, centroid) => {\n      const d = euclideanDistance(x, centroid);\n      return d < min ? d : min;\n    }, Infinity));\n}\n\n/**\n * Computes the Mahalanobis distances between data points and centroids.\n * @param data Array of data points.\n * @param centroids Number of centroids.\n * @param covariance Covariance matrix.\n * @return Array of Mahalanobis distances.\n */\nfunction computeMahalanobisDistances(data: number[][], centroids: number[][], cov: number[][]) {\n  return data.map((x) => centroids.reduce((min, centroid) => {\n      const d = mahalanobisDistance(x, centroid, cov);\n      return d < min ? d : min;\n    }, Infinity));\n}\n\n/**\n * Perform the k-means++ algorithm to find the centroids for clustering data.\n * @param data Array of data points.\n * @param k Number of centroids.\n * @return The centroids representing the clusters.\n */\nfunction kMeansPP(\n  data: number[][],\n  k: number,\n  distanceType: DistanceType,\n) {\n  const centroids: number[][] = [];\n  let cov: number[][];\n\n  const initialCentroidIndex = distanceType === 'mahalanobis' ? 0 : Math.floor(Math.random() * data.length);\n  centroids.push(data[initialCentroidIndex]);\n\n  if (distanceType === 'mahalanobis') {\n    cov = covarianceMatrix(data);\n  }\n\n  const distancesFunction = distanceType === 'mahalanobis'\n  ? (d: number[][], c: number[][]) => computeMahalanobisDistances(d, c, cov!)\n  : computeEuclideanDistances;\n\n  for (let i = centroids.length; i < k; i += 1) {\n    const distances = distancesFunction(data, centroids);\n    const sum = distances.reduce((a, b) => a + b);\n    const probabilities = distances.map((d) => d / sum);\n\n    let r = Math.random();\n    let index = 0;\n    while (r > 0) {\n      r -= probabilities[index];\n      index += 1;\n    }\n    index -= 1;\n\n    centroids.push(data[index]);\n  }\n\n  return centroids as RGBAColor[];\n}\n\nexport { computeEuclideanDistances, computeMahalanobisDistances, kMeansPP };\n","import { FILE_PATH_PATTERN, URL_PATTERN } from '../const/index.js';\nimport { loader } from '../image-processing/index.js';\nimport { kMeansPP } from '../computing/index.js';\n\nimport type { Config, ImageSource, Quality } from '../types/index.js';\n\n/**\n * Processes the given color data using the specified distance metric and clustering algorithm.\n *\n * @param colorData - The color data to be processed.\n * @param distance - The distance metric to be used for clustering.\n * @param k - The number of clusters.\n * @throws Throws an error if the color data is empty.\n * @return The result of the clustering algorithm.\n */\nconst processColorData = (colorData: number[][], distance: Quality, k: number) => {\n    if (!colorData || colorData.length === 0) {\n      throw new Error('color data is empty');\n    }\n\n    switch (distance) {\n        case 'fast':\n          return kMeansPP(colorData, k, 'euclidean');\n        case 'quality':\n          return kMeansPP(colorData, k, 'mahalanobis');\n        default:\n          return kMeansPP(colorData, k, 'euclidean');\n      }\n  };\n\n/**\n * Performs color detection on an image source.\n *\n * @param src - The source of the image.\n * @param [config] - The configuration options for the color detection.\n * @return A promise that resolves to an array of RGBA colors\n * representing the detected colors.\n */\nasync function colorDetection<T extends ImageSource>(\n  src: T,\n  config: Config = {} as Config,\n) {\n  const { distance = 'fast', k = 1, AccessControlAllowOrigin } = config;\n\n  if (k < 1) {\n    throw new Error('k must be greater than 0');\n  }\n\n  if (typeof src === 'string' && src.length === 0) {\n    throw new Error(\"Guess you've passed an empty string.\");\n  }\n  if (typeof src === 'string' && !URL_PATTERN.test(src) && !FILE_PATH_PATTERN.test(src)) {\n    throw new Error('Invalid string format. Expected an image URL or file path.');\n  }\n  if (src instanceof ArrayBuffer && src.byteLength === 0) {\n    throw new Error('The buffer that was passed was empty.');\n  }\n\n  const detectedColors = await loader(src, { AccessControlAllowOrigin });\n  return processColorData(detectedColors, distance, k);\n}\n\nexport { colorDetection };\n","import type { RGBAColor, RGBColor } from '../types/index.js';\n\n/**\n * Converts a numeric value to a two-character hexadecimal string.\n *\n * The number is first rounded and then converted to a hexadecimal string.\n * If the resulting string is a single character, it is padded with a leading zero\n * to ensure a two-character output.\n *\n * @param number - The number to be converted to a hexadecimal string.\n * @return A two-character hexadecimal string representation of the number.\n */\nconst NumberToHex = (number: number) => Math.max(0, Math.round(number)).toString(16).padStart(2, '0');\n\n/**\n * Converts an RGBA color to an RGB color by blending it over a background color.\n *\n * The RGBA color is combined with the specified background color, taking into account the alpha\n * value of the RGBA color. If no background color is provided, white is used by default.\n *\n * @param rgbaColor - The RGBA color to be converted.\n * @param backgroundColor - The background color to blend with, defaulting to white.\n * @return The resulting RGB color after blending.\n */\nfunction rgbaToRgb(rgbaColor: RGBAColor, backgroundColor: RGBColor = [255, 255, 255]): RGBColor {\n  const [r, g, b, alpha] = rgbaColor;\n  const [br, bg, bb] = backgroundColor;\n\n  // Calculate the new red, green, and blue values by blending the foreground color\n  // with the background color based on the alpha of the foreground color.\n  const newR = Math.round(br * (1 - alpha) + r * alpha);\n  const newG = Math.round(bg * (1 - alpha) + g * alpha);\n  const newB = Math.round(bb * (1 - alpha) + b * alpha);\n\n  // Return the new RGB color after blending.\n  return [newR, newG, newB];\n}\n\n/**\n * Converts a color tuple to a hexadecimal string representation.\n *\n * @param color - The color tuple to be converted.\n * @return The hexadecimal string representation of the color.\n */\nconst toHex = (color: RGBAColor): string => color.reduce((acc, cv, index) => {\n    // If the last number is 1, do not append 'ff' to the accumulator.\n    if (index === color.length - 1 && cv === 1) {\n      return acc;\n    }\n    // Scale alpha to 255 and convert to hex, otherwise just convert to hex.\n    const value = index === color.length - 1 ? Math.round(cv * 255) : cv;\n    return acc + NumberToHex(value);\n  }, '#');\n/**\n * Converts a color tuple to an RGB string representation.\n *\n * @param color - The color tuple to be converted.\n * @return The RGB string representation of the color.\n */\nconst toRGB = (color: RGBAColor) => `rgb(${rgbaToRgb(color)})`;\n\n/**\n * Converts a color tuple to an RGBA string representation.\n *\n * @param color - The color tuple to be converted.\n * @return The RGBA string representation of the color.\n */\nconst toRGBA = (color: RGBAColor) => `rgba(${color})`;\n\nexport { toHex, toRGB, toRGBA, NumberToHex, rgbaToRgb };\n"],"names":["URL_PATTERN","FILE_PATH_PATTERN","getImageDataWithoutDomAccess","imageBitmap","ctx","imageToMatrix","imageData","_","i","r","g","b","getImageMatrix","image","blobToMatrix","blob","loader","target","options","AccessControlAllowOrigin","response","result","covarianceMatrix","data","mean","sum","row","indexI","__","indexJ","accumulator","diffProduct","dotProduct","matrixA","matrixB","rowsA","colsA","rowsB","colsB","j","k","euclideanDistance","coords1","coords2","invertMatrix","matrix","n","identityMatrix","maxRow","temp","tempIdentity","divisor","factor","transpose","rows","columns","mahalanobisDistance","x","cov","delta","val","index","invertedCov","deltaTransposed","product","computeEuclideanDistances","centroids","min","centroid","d","computeMahalanobisDistances","kMeansPP","distanceType","initialCentroidIndex","distancesFunction","c","distances","a","probabilities","processColorData","colorData","distance","colorDetection","src","config","detectedColors","NumberToHex","number","rgbaToRgb","rgbaColor","backgroundColor","alpha","br","bg","bb","newR","newG","newB","toH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