@weavelogic/knowledge-graph-agent 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -3
  3. package/dist/_virtual/__vite-browser-external.js +2 -2
  4. package/dist/_virtual/__vite-browser-external.js.map +1 -1
  5. package/dist/_virtual/index12.js +7 -0
  6. package/dist/_virtual/index12.js.map +1 -0
  7. package/dist/_virtual/ort-web.min.js +8 -0
  8. package/dist/_virtual/ort-web.min.js.map +1 -0
  9. package/dist/_virtual/ort-web.min2.js +5 -0
  10. package/dist/_virtual/ort-web.min2.js.map +1 -0
  11. package/dist/agents/base-agent.d.ts +63 -0
  12. package/dist/agents/base-agent.d.ts.map +1 -1
  13. package/dist/agents/base-agent.js +139 -0
  14. package/dist/agents/base-agent.js.map +1 -1
  15. package/dist/agents/coordinator-agent.d.ts +422 -0
  16. package/dist/agents/coordinator-agent.d.ts.map +1 -0
  17. package/dist/agents/documenter-agent.d.ts +298 -0
  18. package/dist/agents/documenter-agent.d.ts.map +1 -0
  19. package/dist/agents/index.d.ts +11 -1
  20. package/dist/agents/index.d.ts.map +1 -1
  21. package/dist/agents/index.js +4 -0
  22. package/dist/agents/index.js.map +1 -1
  23. package/dist/agents/mixins/index.d.ts +9 -0
  24. package/dist/agents/mixins/index.d.ts.map +1 -0
  25. package/dist/agents/mixins/trajectory-mixin.d.ts +112 -0
  26. package/dist/agents/mixins/trajectory-mixin.d.ts.map +1 -0
  27. package/dist/agents/optimizer-agent.d.ts +388 -0
  28. package/dist/agents/optimizer-agent.d.ts.map +1 -0
  29. package/dist/agents/planner-agent.d.ts +395 -0
  30. package/dist/agents/planner-agent.d.ts.map +1 -0
  31. package/dist/agents/registry.d.ts.map +1 -1
  32. package/dist/agents/registry.js +5 -0
  33. package/dist/agents/registry.js.map +1 -1
  34. package/dist/agents/reviewer-agent.d.ts +330 -0
  35. package/dist/agents/reviewer-agent.d.ts.map +1 -0
  36. package/dist/agents/types.d.ts +12 -1
  37. package/dist/agents/types.d.ts.map +1 -1
  38. package/dist/agents/types.js +1 -0
  39. package/dist/agents/types.js.map +1 -1
  40. package/dist/cli/commands/hive-mind/add-frontmatter.d.ts +102 -0
  41. package/dist/cli/commands/hive-mind/add-frontmatter.d.ts.map +1 -0
  42. package/dist/cli/commands/hive-mind/add-frontmatter.js +439 -0
  43. package/dist/cli/commands/hive-mind/add-frontmatter.js.map +1 -0
  44. package/dist/cli/commands/hive-mind/analyze-links.d.ts +80 -0
  45. package/dist/cli/commands/hive-mind/analyze-links.d.ts.map +1 -0
  46. package/dist/cli/commands/hive-mind/analyze-links.js +367 -0
  47. package/dist/cli/commands/hive-mind/analyze-links.js.map +1 -0
  48. package/dist/cli/commands/hive-mind/find-connections.d.ts +75 -0
  49. package/dist/cli/commands/hive-mind/find-connections.d.ts.map +1 -0
  50. package/dist/cli/commands/hive-mind/find-connections.js +347 -0
  51. package/dist/cli/commands/hive-mind/find-connections.js.map +1 -0
  52. package/dist/cli/commands/hive-mind/index.d.ts +37 -0
  53. package/dist/cli/commands/hive-mind/index.d.ts.map +1 -0
  54. package/dist/cli/commands/hive-mind/index.js +33 -0
  55. package/dist/cli/commands/hive-mind/index.js.map +1 -0
  56. package/dist/cli/commands/hive-mind/validate-names.d.ts +79 -0
  57. package/dist/cli/commands/hive-mind/validate-names.d.ts.map +1 -0
  58. package/dist/cli/commands/hive-mind/validate-names.js +353 -0
  59. package/dist/cli/commands/hive-mind/validate-names.js.map +1 -0
  60. package/dist/cli/commands/vector.js +2 -0
  61. package/dist/cli/commands/vector.js.map +1 -1
  62. package/dist/cli/index.d.ts.map +1 -1
  63. package/dist/cli/index.js +7 -0
  64. package/dist/cli/index.js.map +1 -1
  65. package/dist/equilibrium/agent-equilibrium.d.ts +194 -0
  66. package/dist/equilibrium/agent-equilibrium.d.ts.map +1 -0
  67. package/dist/equilibrium/agent-equilibrium.js +304 -0
  68. package/dist/equilibrium/agent-equilibrium.js.map +1 -0
  69. package/dist/equilibrium/graph-equilibrium.d.ts +177 -0
  70. package/dist/equilibrium/graph-equilibrium.d.ts.map +1 -0
  71. package/dist/equilibrium/index.d.ts +11 -0
  72. package/dist/equilibrium/index.d.ts.map +1 -0
  73. package/dist/equilibrium/memory-equilibrium.d.ts +153 -0
  74. package/dist/equilibrium/memory-equilibrium.d.ts.map +1 -0
  75. package/dist/graphql/resolvers/index.d.ts.map +1 -1
  76. package/dist/graphql/resolvers/queries.d.ts +11 -0
  77. package/dist/graphql/resolvers/queries.d.ts.map +1 -1
  78. package/dist/index.d.ts +2 -0
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +10 -4
  81. package/dist/index.js.map +1 -1
  82. package/dist/inference/index.d.ts +9 -0
  83. package/dist/inference/index.d.ts.map +1 -0
  84. package/dist/inference/model-selection.d.ts +131 -0
  85. package/dist/inference/model-selection.d.ts.map +1 -0
  86. package/dist/integrations/agentic-flow/adapters/agent-booster-adapter.d.ts +265 -0
  87. package/dist/integrations/agentic-flow/adapters/agent-booster-adapter.d.ts.map +1 -0
  88. package/dist/integrations/agentic-flow/adapters/agentdb-adapter.d.ts +197 -0
  89. package/dist/integrations/agentic-flow/adapters/agentdb-adapter.d.ts.map +1 -0
  90. package/dist/integrations/agentic-flow/adapters/agentdb-vector-store.d.ts +249 -0
  91. package/dist/integrations/agentic-flow/adapters/agentdb-vector-store.d.ts.map +1 -0
  92. package/dist/integrations/agentic-flow/adapters/base-adapter.d.ts +120 -0
  93. package/dist/integrations/agentic-flow/adapters/base-adapter.d.ts.map +1 -0
  94. package/dist/integrations/agentic-flow/adapters/federation-hub-adapter.d.ts +444 -0
  95. package/dist/integrations/agentic-flow/adapters/federation-hub-adapter.d.ts.map +1 -0
  96. package/dist/integrations/agentic-flow/adapters/index.d.ts +17 -0
  97. package/dist/integrations/agentic-flow/adapters/index.d.ts.map +1 -0
  98. package/dist/integrations/agentic-flow/adapters/model-router-adapter.d.ts +242 -0
  99. package/dist/integrations/agentic-flow/adapters/model-router-adapter.d.ts.map +1 -0
  100. package/dist/integrations/agentic-flow/adapters/quic-transport-adapter.d.ts +364 -0
  101. package/dist/integrations/agentic-flow/adapters/quic-transport-adapter.d.ts.map +1 -0
  102. package/dist/integrations/agentic-flow/adapters/reasoning-bank-adapter.d.ts +209 -0
  103. package/dist/integrations/agentic-flow/adapters/reasoning-bank-adapter.d.ts.map +1 -0
  104. package/dist/integrations/agentic-flow/benchmark/index.d.ts +9 -0
  105. package/dist/integrations/agentic-flow/benchmark/index.d.ts.map +1 -0
  106. package/dist/integrations/agentic-flow/benchmark/vector-benchmark.d.ts +253 -0
  107. package/dist/integrations/agentic-flow/benchmark/vector-benchmark.d.ts.map +1 -0
  108. package/dist/integrations/agentic-flow/config.d.ts +109 -0
  109. package/dist/integrations/agentic-flow/config.d.ts.map +1 -0
  110. package/dist/integrations/agentic-flow/feature-flags.d.ts +140 -0
  111. package/dist/integrations/agentic-flow/feature-flags.d.ts.map +1 -0
  112. package/dist/integrations/agentic-flow/index.d.ts +22 -0
  113. package/dist/integrations/agentic-flow/index.d.ts.map +1 -0
  114. package/dist/integrations/agentic-flow/migration/index.d.ts +9 -0
  115. package/dist/integrations/agentic-flow/migration/index.d.ts.map +1 -0
  116. package/dist/integrations/agentic-flow/migration/migrate-to-agentdb.d.ts +242 -0
  117. package/dist/integrations/agentic-flow/migration/migrate-to-agentdb.d.ts.map +1 -0
  118. package/dist/learning/index.d.ts +91 -0
  119. package/dist/learning/index.d.ts.map +1 -0
  120. package/dist/learning/learning-loop.d.ts +176 -0
  121. package/dist/learning/learning-loop.d.ts.map +1 -0
  122. package/dist/learning/services/ab-testing-framework.d.ts +135 -0
  123. package/dist/learning/services/ab-testing-framework.d.ts.map +1 -0
  124. package/dist/learning/services/agent-priming-service.d.ts +207 -0
  125. package/dist/learning/services/agent-priming-service.d.ts.map +1 -0
  126. package/dist/learning/services/daily-log-generator.d.ts +113 -0
  127. package/dist/learning/services/daily-log-generator.d.ts.map +1 -0
  128. package/dist/learning/services/index.d.ts +14 -0
  129. package/dist/learning/services/index.d.ts.map +1 -0
  130. package/dist/learning/services/memory-extraction-service.d.ts +87 -0
  131. package/dist/learning/services/memory-extraction-service.d.ts.map +1 -0
  132. package/dist/learning/services/task-completion-consumer.d.ts +162 -0
  133. package/dist/learning/services/task-completion-consumer.d.ts.map +1 -0
  134. package/dist/learning/services/trajectory-tracker.d.ts +174 -0
  135. package/dist/learning/services/trajectory-tracker.d.ts.map +1 -0
  136. package/dist/learning/types.d.ts +516 -0
  137. package/dist/learning/types.d.ts.map +1 -0
  138. package/dist/mcp/clients/claude-flow-memory-client.d.ts +259 -0
  139. package/dist/mcp/clients/claude-flow-memory-client.d.ts.map +1 -0
  140. package/dist/mcp/clients/claude-flow-memory-client.js +305 -0
  141. package/dist/mcp/clients/claude-flow-memory-client.js.map +1 -0
  142. package/dist/mcp/clients/index.d.ts +11 -0
  143. package/dist/mcp/clients/index.d.ts.map +1 -0
  144. package/dist/mcp/clients/mcp-client-adapter.d.ts +146 -0
  145. package/dist/mcp/clients/mcp-client-adapter.d.ts.map +1 -0
  146. package/dist/mcp/clients/mcp-client-adapter.js +372 -0
  147. package/dist/mcp/clients/mcp-client-adapter.js.map +1 -0
  148. package/dist/mcp/index.d.ts +10 -0
  149. package/dist/mcp/index.d.ts.map +1 -0
  150. package/dist/memory/vault-sync.d.ts +12 -0
  151. package/dist/memory/vault-sync.d.ts.map +1 -1
  152. package/dist/memory/vault-sync.js +94 -11
  153. package/dist/memory/vault-sync.js.map +1 -1
  154. package/dist/node_modules/@huggingface/jinja/dist/index.js +118 -0
  155. package/dist/node_modules/@huggingface/jinja/dist/index.js.map +1 -0
  156. package/dist/node_modules/@typescript-eslint/project-service/dist/index.js +1 -1
  157. package/dist/node_modules/@xenova/transformers/src/backends/onnx.js +24 -0
  158. package/dist/node_modules/@xenova/transformers/src/backends/onnx.js.map +1 -0
  159. package/dist/node_modules/@xenova/transformers/src/configs.js +52 -0
  160. package/dist/node_modules/@xenova/transformers/src/configs.js.map +1 -0
  161. package/dist/node_modules/@xenova/transformers/src/env.js +35 -0
  162. package/dist/node_modules/@xenova/transformers/src/env.js.map +1 -0
  163. package/dist/node_modules/@xenova/transformers/src/models.js +3852 -0
  164. package/dist/node_modules/@xenova/transformers/src/models.js.map +1 -0
  165. package/dist/node_modules/@xenova/transformers/src/tokenizers.js +144 -0
  166. package/dist/node_modules/@xenova/transformers/src/tokenizers.js.map +1 -0
  167. package/dist/node_modules/@xenova/transformers/src/utils/core.js +52 -0
  168. package/dist/node_modules/@xenova/transformers/src/utils/core.js.map +1 -0
  169. package/dist/node_modules/@xenova/transformers/src/utils/generation.js +623 -0
  170. package/dist/node_modules/@xenova/transformers/src/utils/generation.js.map +1 -0
  171. package/dist/node_modules/@xenova/transformers/src/utils/hub.js +395 -0
  172. package/dist/node_modules/@xenova/transformers/src/utils/hub.js.map +1 -0
  173. package/dist/node_modules/@xenova/transformers/src/utils/image.js +12 -0
  174. package/dist/node_modules/@xenova/transformers/src/utils/image.js.map +1 -0
  175. package/dist/node_modules/@xenova/transformers/src/utils/maths.js +89 -0
  176. package/dist/node_modules/@xenova/transformers/src/utils/maths.js.map +1 -0
  177. package/dist/node_modules/@xenova/transformers/src/utils/tensor.js +750 -0
  178. package/dist/node_modules/@xenova/transformers/src/utils/tensor.js.map +1 -0
  179. package/dist/node_modules/fdir/dist/index.js +13 -13
  180. package/dist/node_modules/fdir/dist/index.js.map +1 -1
  181. package/dist/node_modules/onnxruntime-common/dist/lib/backend-impl.js +67 -0
  182. package/dist/node_modules/onnxruntime-common/dist/lib/backend-impl.js.map +1 -0
  183. package/dist/node_modules/onnxruntime-common/dist/lib/env-impl.js +24 -0
  184. package/dist/node_modules/onnxruntime-common/dist/lib/env-impl.js.map +1 -0
  185. package/dist/node_modules/onnxruntime-common/dist/lib/env.js +6 -0
  186. package/dist/node_modules/onnxruntime-common/dist/lib/env.js.map +1 -0
  187. package/dist/node_modules/onnxruntime-common/dist/lib/index.js +11 -0
  188. package/dist/node_modules/onnxruntime-common/dist/lib/index.js.map +1 -0
  189. package/dist/node_modules/onnxruntime-common/dist/lib/inference-session-impl.js +162 -0
  190. package/dist/node_modules/onnxruntime-common/dist/lib/inference-session-impl.js.map +1 -0
  191. package/dist/node_modules/onnxruntime-common/dist/lib/inference-session.js +6 -0
  192. package/dist/node_modules/onnxruntime-common/dist/lib/inference-session.js.map +1 -0
  193. package/dist/node_modules/onnxruntime-common/dist/lib/tensor-impl.js +393 -0
  194. package/dist/node_modules/onnxruntime-common/dist/lib/tensor-impl.js.map +1 -0
  195. package/dist/node_modules/onnxruntime-common/dist/lib/tensor.js +6 -0
  196. package/dist/node_modules/onnxruntime-common/dist/lib/tensor.js.map +1 -0
  197. package/dist/node_modules/onnxruntime-web/dist/ort-web.min.js +12919 -0
  198. package/dist/node_modules/onnxruntime-web/dist/ort-web.min.js.map +1 -0
  199. package/dist/node_modules/tinyglobby/dist/index.js +14 -14
  200. package/dist/node_modules/tinyglobby/dist/index.js.map +1 -1
  201. package/dist/node_modules/typescript/lib/typescript.js +24 -24
  202. package/dist/node_modules/typescript/lib/typescript.js.map +1 -1
  203. package/dist/transport/agent-transport.d.ts +269 -0
  204. package/dist/transport/agent-transport.d.ts.map +1 -0
  205. package/dist/transport/index.d.ts +10 -0
  206. package/dist/transport/index.d.ts.map +1 -0
  207. package/dist/vector/index.d.ts +1 -1
  208. package/dist/vector/index.d.ts.map +1 -1
  209. package/dist/vector/services/embedding-service.d.ts +244 -0
  210. package/dist/vector/services/embedding-service.d.ts.map +1 -0
  211. package/dist/vector/services/embedding-service.js +10 -0
  212. package/dist/vector/services/embedding-service.js.map +1 -0
  213. package/dist/vector/services/hybrid-search.d.ts +320 -0
  214. package/dist/vector/services/hybrid-search.d.ts.map +1 -0
  215. package/dist/vector/services/hybrid-search.js +3 -0
  216. package/dist/vector/services/hybrid-search.js.map +1 -0
  217. package/dist/vector/services/index.d.ts +4 -0
  218. package/dist/vector/services/index.d.ts.map +1 -1
  219. package/package.json +10 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.js","sources":["../../../../../../node_modules/@xenova/transformers/src/utils/image.js"],"sourcesContent":["\n/**\n * @file Helper module for image processing. \n * \n * These functions and classes are only used internally, \n * meaning an end-user shouldn't need to access anything here.\n * \n * @module utils/image\n */\n\nimport { getFile } from './hub.js';\nimport { env } from '../env.js';\nimport { Tensor } from './tensor.js';\n\n// Will be empty (or not used) if running in browser or web-worker\nimport sharp from 'sharp';\n\nconst BROWSER_ENV = typeof self !== 'undefined';\nconst WEBWORKER_ENV = BROWSER_ENV && self.constructor.name === 'DedicatedWorkerGlobalScope';\n\nlet createCanvasFunction;\nlet ImageDataClass;\nlet loadImageFunction;\nif (BROWSER_ENV) {\n // Running in browser or web-worker\n createCanvasFunction = (/** @type {number} */ width, /** @type {number} */ height) => {\n if (!self.OffscreenCanvas) {\n throw new Error('OffscreenCanvas not supported by this browser.');\n }\n return new self.OffscreenCanvas(width, height)\n };\n loadImageFunction = self.createImageBitmap;\n ImageDataClass = self.ImageData;\n\n} else if (sharp) {\n // Running in Node.js, electron, or other non-browser environment\n\n loadImageFunction = async (/**@type {sharp.Sharp}*/img) => {\n const metadata = await img.metadata();\n const rawChannels = metadata.channels;\n\n let { data, info } = await img.rotate().raw().toBuffer({ resolveWithObject: true });\n\n const newImage = new RawImage(new Uint8ClampedArray(data), info.width, info.height, info.channels);\n if (rawChannels !== undefined && rawChannels !== info.channels) {\n // Make sure the new image has the same number of channels as the input image.\n // This is necessary for grayscale images.\n newImage.convert(rawChannels);\n }\n return newImage;\n }\n\n} else {\n throw new Error('Unable to load image processing library.');\n}\n\n\n// Defined here: https://github.com/python-pillow/Pillow/blob/a405e8406b83f8bfb8916e93971edc7407b8b1ff/src/libImaging/Imaging.h#L262-L268\nconst RESAMPLING_MAPPING = {\n 0: 'nearest',\n 1: 'lanczos',\n 2: 'bilinear',\n 3: 'bicubic',\n 4: 'box',\n 5: 'hamming',\n}\n\n/**\n * Mapping from file extensions to MIME types.\n */\nconst CONTENT_TYPE_MAP = new Map([\n ['png', 'image/png'],\n ['jpg', 'image/jpeg'],\n ['jpeg', 'image/jpeg'],\n ['gif', 'image/gif'],\n]);\n\nexport class RawImage {\n\n /**\n * Create a new `RawImage` object.\n * @param {Uint8ClampedArray|Uint8Array} data The pixel data.\n * @param {number} width The width of the image.\n * @param {number} height The height of the image.\n * @param {1|2|3|4} channels The number of channels.\n */\n constructor(data, width, height, channels) {\n this.data = data;\n this.width = width;\n this.height = height;\n this.channels = channels;\n }\n\n /** \n * Returns the size of the image (width, height).\n * @returns {[number, number]} The size of the image (width, height).\n */\n get size() {\n return [this.width, this.height];\n }\n\n /**\n * Helper method for reading an image from a variety of input types.\n * @param {RawImage|string|URL} input \n * @returns The image object.\n * \n * **Example:** Read image from a URL.\n * ```javascript\n * let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg');\n * // RawImage {\n * // \"data\": Uint8ClampedArray [ 25, 25, 25, 19, 19, 19, ... ],\n * // \"width\": 800,\n * // \"height\": 533,\n * // \"channels\": 3\n * // }\n * ```\n */\n static async read(input) {\n if (input instanceof RawImage) {\n return input;\n } else if (typeof input === 'string' || input instanceof URL) {\n return await this.fromURL(input);\n } else {\n throw new Error(`Unsupported input type: ${typeof input}`);\n }\n }\n\n\n /**\n * Read an image from a URL or file path.\n * @param {string|URL} url The URL or file path to read the image from.\n * @returns {Promise<RawImage>} The image object.\n */\n static async fromURL(url) {\n let response = await getFile(url);\n if (response.status !== 200) {\n throw new Error(`Unable to read image from \"${url}\" (${response.status} ${response.statusText})`);\n }\n let blob = await response.blob();\n return this.fromBlob(blob);\n }\n\n /**\n * Helper method to create a new Image from a blob.\n * @param {Blob} blob The blob to read the image from.\n * @returns {Promise<RawImage>} The image object.\n */\n static async fromBlob(blob) {\n if (BROWSER_ENV) {\n // Running in environment with canvas\n let img = await loadImageFunction(blob);\n\n const ctx = createCanvasFunction(img.width, img.height).getContext('2d');\n\n // Draw image to context\n ctx.drawImage(img, 0, 0);\n\n return new this(ctx.getImageData(0, 0, img.width, img.height).data, img.width, img.height, 4);\n\n } else {\n // Use sharp.js to read (and possible resize) the image.\n let img = sharp(await blob.arrayBuffer());\n\n return await loadImageFunction(img);\n }\n }\n\n /**\n * Helper method to create a new Image from a tensor\n * @param {Tensor} tensor \n */\n static fromTensor(tensor, channel_format = 'CHW') {\n if (tensor.dims.length !== 3) {\n throw new Error(`Tensor should have 3 dimensions, but has ${tensor.dims.length} dimensions.`);\n }\n\n if (channel_format === 'CHW') {\n tensor = tensor.transpose(1, 2, 0);\n } else if (channel_format === 'HWC') {\n // Do nothing\n } else {\n throw new Error(`Unsupported channel format: ${channel_format}`);\n }\n if (!(tensor.data instanceof Uint8ClampedArray || tensor.data instanceof Uint8Array)) {\n throw new Error(`Unsupported tensor type: ${tensor.type}`);\n }\n switch (tensor.dims[2]) {\n case 1:\n case 2:\n case 3:\n case 4:\n return new RawImage(tensor.data, tensor.dims[1], tensor.dims[0], tensor.dims[2]);\n default:\n throw new Error(`Unsupported number of channels: ${tensor.dims[2]}`);\n }\n }\n\n /**\n * Convert the image to grayscale format.\n * @returns {RawImage} `this` to support chaining.\n */\n grayscale() {\n if (this.channels === 1) {\n return this;\n }\n\n let newData = new Uint8ClampedArray(this.width * this.height * 1);\n switch (this.channels) {\n case 3: // rgb to grayscale\n case 4: // rgba to grayscale\n for (let i = 0, offset = 0; i < this.data.length; i += this.channels) {\n const red = this.data[i];\n const green = this.data[i + 1];\n const blue = this.data[i + 2];\n\n newData[offset++] = Math.round(0.2989 * red + 0.5870 * green + 0.1140 * blue);\n }\n break;\n default:\n throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`);\n }\n return this._update(newData, this.width, this.height, 1);\n }\n\n /**\n * Convert the image to RGB format.\n * @returns {RawImage} `this` to support chaining.\n */\n rgb() {\n if (this.channels === 3) {\n return this;\n }\n\n let newData = new Uint8ClampedArray(this.width * this.height * 3);\n\n switch (this.channels) {\n case 1: // grayscale to rgb\n for (let i = 0, offset = 0; i < this.data.length; ++i) {\n newData[offset++] = this.data[i];\n newData[offset++] = this.data[i];\n newData[offset++] = this.data[i];\n }\n break;\n case 4: // rgba to rgb\n for (let i = 0, offset = 0; i < this.data.length; i += 4) {\n newData[offset++] = this.data[i];\n newData[offset++] = this.data[i + 1];\n newData[offset++] = this.data[i + 2];\n }\n break;\n default:\n throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`);\n }\n return this._update(newData, this.width, this.height, 3);\n\n }\n\n /**\n * Convert the image to RGBA format.\n * @returns {RawImage} `this` to support chaining.\n */\n rgba() {\n if (this.channels === 4) {\n return this;\n }\n\n let newData = new Uint8ClampedArray(this.width * this.height * 4);\n\n switch (this.channels) {\n case 1: // grayscale to rgba\n for (let i = 0, offset = 0; i < this.data.length; ++i) {\n newData[offset++] = this.data[i];\n newData[offset++] = this.data[i];\n newData[offset++] = this.data[i];\n newData[offset++] = 255;\n }\n break;\n case 3: // rgb to rgba\n for (let i = 0, offset = 0; i < this.data.length; i += 3) {\n newData[offset++] = this.data[i];\n newData[offset++] = this.data[i + 1];\n newData[offset++] = this.data[i + 2];\n newData[offset++] = 255;\n }\n break;\n default:\n throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`);\n }\n\n return this._update(newData, this.width, this.height, 4);\n }\n\n /**\n * Resize the image to the given dimensions. This method uses the canvas API to perform the resizing.\n * @param {number} width The width of the new image.\n * @param {number} height The height of the new image.\n * @param {Object} options Additional options for resizing.\n * @param {0|1|2|3|4|5|string} [options.resample] The resampling method to use.\n * @returns {Promise<RawImage>} `this` to support chaining.\n */\n async resize(width, height, {\n resample = 2,\n } = {}) {\n\n // Ensure resample method is a string\n let resampleMethod = RESAMPLING_MAPPING[resample] ?? resample;\n\n if (BROWSER_ENV) {\n // TODO use `resample` in browser environment\n\n // Store number of channels before resizing\n let numChannels = this.channels;\n\n // Create canvas object for this image\n let canvas = this.toCanvas();\n\n // Actually perform resizing using the canvas API\n const ctx = createCanvasFunction(width, height).getContext('2d');\n\n // Draw image to context, resizing in the process\n ctx.drawImage(canvas, 0, 0, width, height);\n\n // Create image from the resized data\n let resizedImage = new RawImage(ctx.getImageData(0, 0, width, height).data, width, height, 4);\n\n // Convert back so that image has the same number of channels as before\n return resizedImage.convert(numChannels);\n\n } else {\n // Create sharp image from raw data, and resize\n let img = this.toSharp();\n\n switch (resampleMethod) {\n case 'box':\n case 'hamming':\n if (resampleMethod === 'box' || resampleMethod === 'hamming') {\n console.warn(`Resampling method ${resampleMethod} is not yet supported. Using bilinear instead.`);\n resampleMethod = 'bilinear';\n }\n\n case 'nearest':\n case 'bilinear':\n case 'bicubic':\n // Perform resizing using affine transform. \n // This matches how the python Pillow library does it.\n img = img.affine([width / this.width, 0, 0, height / this.height], {\n interpolator: resampleMethod\n });\n break;\n\n case 'lanczos':\n // https://github.com/python-pillow/Pillow/discussions/5519\n // https://github.com/lovell/sharp/blob/main/docs/api-resize.md\n img = img.resize({\n width, height,\n fit: 'fill',\n kernel: 'lanczos3', // PIL Lanczos uses a kernel size of 3 \n });\n break;\n\n default:\n throw new Error(`Resampling method ${resampleMethod} is not supported.`);\n }\n\n return await loadImageFunction(img);\n }\n\n }\n\n async pad([left, right, top, bottom]) {\n left = Math.max(left, 0);\n right = Math.max(right, 0);\n top = Math.max(top, 0);\n bottom = Math.max(bottom, 0);\n\n if (left === 0 && right === 0 && top === 0 && bottom === 0) {\n // No padding needed\n return this;\n }\n\n if (BROWSER_ENV) {\n // Store number of channels before padding\n let numChannels = this.channels;\n\n // Create canvas object for this image\n let canvas = this.toCanvas();\n\n let newWidth = this.width + left + right;\n let newHeight = this.height + top + bottom;\n\n // Create a new canvas of the desired size.\n const ctx = createCanvasFunction(newWidth, newHeight).getContext('2d');\n\n // Draw image to context, padding in the process\n ctx.drawImage(canvas,\n 0, 0, this.width, this.height,\n left, top, newWidth, newHeight\n );\n\n // Create image from the padded data\n let paddedImage = new RawImage(\n ctx.getImageData(0, 0, newWidth, newHeight).data,\n newWidth, newHeight, 4);\n\n // Convert back so that image has the same number of channels as before\n return paddedImage.convert(numChannels);\n\n } else {\n let img = this.toSharp().extend({ left, right, top, bottom });\n return await loadImageFunction(img);\n }\n }\n\n async crop([x_min, y_min, x_max, y_max]) {\n // Ensure crop bounds are within the image\n x_min = Math.max(x_min, 0);\n y_min = Math.max(y_min, 0);\n x_max = Math.min(x_max, this.width - 1);\n y_max = Math.min(y_max, this.height - 1);\n\n // Do nothing if the crop is the entire image\n if (x_min === 0 && y_min === 0 && x_max === this.width - 1 && y_max === this.height - 1) {\n return this;\n }\n\n const crop_width = x_max - x_min + 1;\n const crop_height = y_max - y_min + 1;\n\n if (BROWSER_ENV) {\n // Store number of channels before resizing\n const numChannels = this.channels;\n\n // Create canvas object for this image\n const canvas = this.toCanvas();\n\n // Create a new canvas of the desired size. This is needed since if the \n // image is too small, we need to pad it with black pixels.\n const ctx = createCanvasFunction(crop_width, crop_height).getContext('2d');\n\n // Draw image to context, cropping in the process\n ctx.drawImage(canvas,\n x_min, y_min, crop_width, crop_height,\n 0, 0, crop_width, crop_height\n );\n\n // Create image from the resized data\n const resizedImage = new RawImage(ctx.getImageData(0, 0, crop_width, crop_height).data, crop_width, crop_height, 4);\n\n // Convert back so that image has the same number of channels as before\n return resizedImage.convert(numChannels);\n\n } else {\n // Create sharp image from raw data\n const img = this.toSharp().extract({\n left: x_min,\n top: y_min,\n width: crop_width,\n height: crop_height,\n });\n\n return await loadImageFunction(img);\n }\n\n }\n\n async center_crop(crop_width, crop_height) {\n // If the image is already the desired size, return it\n if (this.width === crop_width && this.height === crop_height) {\n return this;\n }\n\n // Determine bounds of the image in the new canvas\n let width_offset = (this.width - crop_width) / 2;\n let height_offset = (this.height - crop_height) / 2;\n\n\n if (BROWSER_ENV) {\n // Store number of channels before resizing\n let numChannels = this.channels;\n\n // Create canvas object for this image\n let canvas = this.toCanvas();\n\n // Create a new canvas of the desired size. This is needed since if the \n // image is too small, we need to pad it with black pixels.\n const ctx = createCanvasFunction(crop_width, crop_height).getContext('2d');\n\n let sourceX = 0;\n let sourceY = 0;\n let destX = 0;\n let destY = 0;\n\n if (width_offset >= 0) {\n sourceX = width_offset;\n } else {\n destX = -width_offset;\n }\n\n if (height_offset >= 0) {\n sourceY = height_offset;\n } else {\n destY = -height_offset;\n }\n\n // Draw image to context, cropping in the process\n ctx.drawImage(canvas,\n sourceX, sourceY, crop_width, crop_height,\n destX, destY, crop_width, crop_height\n );\n\n // Create image from the resized data\n let resizedImage = new RawImage(ctx.getImageData(0, 0, crop_width, crop_height).data, crop_width, crop_height, 4);\n\n // Convert back so that image has the same number of channels as before\n return resizedImage.convert(numChannels);\n\n } else {\n // Create sharp image from raw data\n let img = this.toSharp();\n\n if (width_offset >= 0 && height_offset >= 0) {\n // Cropped image lies entirely within the original image\n img = img.extract({\n left: Math.floor(width_offset),\n top: Math.floor(height_offset),\n width: crop_width,\n height: crop_height,\n })\n } else if (width_offset <= 0 && height_offset <= 0) {\n // Cropped image lies entirely outside the original image,\n // so we add padding\n let top = Math.floor(-height_offset);\n let left = Math.floor(-width_offset);\n img = img.extend({\n top: top,\n left: left,\n\n // Ensures the resulting image has the desired dimensions\n right: crop_width - this.width - left,\n bottom: crop_height - this.height - top,\n });\n } else {\n // Cropped image lies partially outside the original image.\n // We first pad, then crop.\n\n let y_padding = [0, 0];\n let y_extract = 0;\n if (height_offset < 0) {\n y_padding[0] = Math.floor(-height_offset);\n y_padding[1] = crop_height - this.height - y_padding[0];\n } else {\n y_extract = Math.floor(height_offset);\n }\n\n let x_padding = [0, 0];\n let x_extract = 0;\n if (width_offset < 0) {\n x_padding[0] = Math.floor(-width_offset);\n x_padding[1] = crop_width - this.width - x_padding[0];\n } else {\n x_extract = Math.floor(width_offset);\n }\n\n img = img.extend({\n top: y_padding[0],\n bottom: y_padding[1],\n left: x_padding[0],\n right: x_padding[1],\n }).extract({\n left: x_extract,\n top: y_extract,\n width: crop_width,\n height: crop_height,\n })\n }\n\n return await loadImageFunction(img);\n }\n }\n\n async toBlob(type = 'image/png', quality = 1) {\n if (!BROWSER_ENV) {\n throw new Error('toBlob() is only supported in browser environments.')\n }\n\n const canvas = this.toCanvas();\n return await canvas.convertToBlob({ type, quality });\n }\n\n toTensor(channel_format = 'CHW') {\n let tensor = new Tensor(\n 'uint8',\n new Uint8Array(this.data),\n [this.height, this.width, this.channels]\n );\n\n if (channel_format === 'HWC') {\n // Do nothing\n } else if (channel_format === 'CHW') { // hwc -> chw\n tensor = tensor.permute(2, 0, 1);\n } else {\n throw new Error(`Unsupported channel format: ${channel_format}`);\n }\n return tensor;\n }\n\n toCanvas() {\n if (!BROWSER_ENV) {\n throw new Error('toCanvas() is only supported in browser environments.')\n }\n\n // Clone, and convert data to RGBA before drawing to canvas.\n // This is because the canvas API only supports RGBA\n let cloned = this.clone().rgba();\n\n // Create canvas object for the cloned image\n let clonedCanvas = createCanvasFunction(cloned.width, cloned.height);\n\n // Draw image to context\n let data = new ImageDataClass(cloned.data, cloned.width, cloned.height);\n clonedCanvas.getContext('2d').putImageData(data, 0, 0);\n\n return clonedCanvas;\n }\n\n /**\n * Helper method to update the image data.\n * @param {Uint8ClampedArray} data The new image data.\n * @param {number} width The new width of the image.\n * @param {number} height The new height of the image.\n * @param {1|2|3|4|null} [channels] The new number of channels of the image.\n * @private\n */\n _update(data, width, height, channels = null) {\n this.data = data;\n this.width = width;\n this.height = height;\n if (channels !== null) {\n this.channels = channels;\n }\n return this;\n }\n\n /**\n * Clone the image\n * @returns {RawImage} The cloned image\n */\n clone() {\n return new RawImage(this.data.slice(), this.width, this.height, this.channels);\n }\n\n /**\n * Helper method for converting image to have a certain number of channels\n * @param {number} numChannels The number of channels. Must be 1, 3, or 4.\n * @returns {RawImage} `this` to support chaining.\n */\n convert(numChannels) {\n if (this.channels === numChannels) return this; // Already correct number of channels\n\n switch (numChannels) {\n case 1:\n this.grayscale();\n break;\n case 3:\n this.rgb();\n break;\n case 4:\n this.rgba();\n break;\n default:\n throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`);\n }\n return this;\n }\n\n /**\n * Save the image to the given path.\n * @param {string} path The path to save the image to.\n */\n async save(path) {\n\n if (BROWSER_ENV) {\n if (WEBWORKER_ENV) {\n throw new Error('Unable to save an image from a Web Worker.')\n }\n\n const extension = path.split('.').pop().toLowerCase();\n const mime = CONTENT_TYPE_MAP.get(extension) ?? 'image/png';\n\n // Convert image to Blob\n const blob = await this.toBlob(mime);\n\n // Convert the canvas content to a data URL\n const dataURL = URL.createObjectURL(blob);\n\n // Create an anchor element with the data URL as the href attribute\n const downloadLink = document.createElement('a');\n downloadLink.href = dataURL;\n\n // Set the download attribute to specify the desired filename for the downloaded image\n downloadLink.download = path;\n\n // Trigger the download\n downloadLink.click();\n\n // Clean up: remove the anchor element from the DOM\n downloadLink.remove();\n\n } else if (!env.useFS) {\n throw new Error('Unable to save the image because filesystem is disabled in this environment.')\n\n } else {\n const img = this.toSharp();\n return await img.toFile(path);\n }\n }\n\n toSharp() {\n if (BROWSER_ENV) {\n throw new Error('toSharp() is only supported in server-side environments.')\n }\n\n return sharp(this.data, {\n raw: {\n width: this.width,\n height: this.height,\n channels: this.channels\n }\n });\n }\n}\n"],"names":[],"mappings":";;;;;AAiBA,MAAM,cAAc,OAAO,SAAS;AAMpC,IAAI,YAAa;AAAA,SAWN,MAAO;AAAA,KAkBX;AACH,QAAM,IAAI,MAAM,0CAA0C;AAC9D;","x_google_ignoreList":[0]}
@@ -0,0 +1,89 @@
1
+ function permute_data(array, dims, axes) {
2
+ const shape = new Array(axes.length);
3
+ const stride = new Array(axes.length);
4
+ for (let i = axes.length - 1, s = 1; i >= 0; --i) {
5
+ stride[i] = s;
6
+ shape[i] = dims[axes[i]];
7
+ s *= shape[i];
8
+ }
9
+ const invStride = axes.map((_, i) => stride[axes.indexOf(i)]);
10
+ const permutedData = new array.constructor(array.length);
11
+ for (let i = 0; i < array.length; ++i) {
12
+ let newIndex = 0;
13
+ for (let j = dims.length - 1, k = i; j >= 0; --j) {
14
+ newIndex += k % dims[j] * invStride[j];
15
+ k = Math.floor(k / dims[j]);
16
+ }
17
+ permutedData[newIndex] = array[i];
18
+ }
19
+ return [permutedData, shape];
20
+ }
21
+ function softmax(arr) {
22
+ const maxVal = max(arr)[0];
23
+ const exps = arr.map((x) => Math.exp(x - maxVal));
24
+ const sumExps = exps.reduce((acc, val) => acc + val, 0);
25
+ const softmaxArr = exps.map((x) => x / sumExps);
26
+ return (
27
+ /** @type {T} */
28
+ softmaxArr
29
+ );
30
+ }
31
+ function log_softmax(arr) {
32
+ const softmaxArr = softmax(arr);
33
+ const logSoftmaxArr = softmaxArr.map((x) => Math.log(x));
34
+ return (
35
+ /** @type {T} */
36
+ logSoftmaxArr
37
+ );
38
+ }
39
+ function getTopItems(items, top_k = 0) {
40
+ items = Array.from(items).map((x, i) => [i, x]).sort((a, b) => b[1] - a[1]);
41
+ if (top_k !== null && top_k > 0) {
42
+ items = items.slice(0, top_k);
43
+ }
44
+ return items;
45
+ }
46
+ function max(arr) {
47
+ if (arr.length === 0) throw Error("Array must not be empty");
48
+ let max2 = arr[0];
49
+ let indexOfMax = 0;
50
+ for (let i = 1; i < arr.length; ++i) {
51
+ if (arr[i] > max2) {
52
+ max2 = arr[i];
53
+ indexOfMax = i;
54
+ }
55
+ }
56
+ return [Number(max2), indexOfMax];
57
+ }
58
+ function medianFilter(data, windowSize) {
59
+ if (windowSize % 2 === 0 || windowSize <= 0) {
60
+ throw new Error("Window size must be a positive odd number");
61
+ }
62
+ const outputArray = new data.constructor(data.length);
63
+ const buffer = new data.constructor(windowSize);
64
+ const halfWindowSize = Math.floor(windowSize / 2);
65
+ for (let i = 0; i < data.length; ++i) {
66
+ let valuesIndex = 0;
67
+ for (let j = -halfWindowSize; j <= halfWindowSize; ++j) {
68
+ let index = i + j;
69
+ if (index < 0) {
70
+ index = Math.abs(index);
71
+ } else if (index >= data.length) {
72
+ index = 2 * (data.length - 1) - index;
73
+ }
74
+ buffer[valuesIndex++] = data[index];
75
+ }
76
+ buffer.sort();
77
+ outputArray[i] = buffer[halfWindowSize];
78
+ }
79
+ return outputArray;
80
+ }
81
+ export {
82
+ getTopItems,
83
+ log_softmax,
84
+ max,
85
+ medianFilter,
86
+ permute_data,
87
+ softmax
88
+ };
89
+ //# sourceMappingURL=maths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maths.js","sources":["../../../../../../node_modules/@xenova/transformers/src/utils/maths.js"],"sourcesContent":["\n/**\n * @file Helper module for mathematical processing. \n * \n * These functions and classes are only used internally, \n * meaning an end-user shouldn't need to access anything here.\n * \n * @module utils/maths\n */\n\n/**\n * @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array} TypedArray\n * @typedef {BigInt64Array | BigUint64Array} BigTypedArray\n * @typedef {TypedArray | BigTypedArray} AnyTypedArray\n */\n\n/**\n * @param {TypedArray} input\n */\nexport function interpolate_data(input, [in_channels, in_height, in_width], [out_height, out_width], mode = 'bilinear', align_corners = false) {\n // TODO use mode and align_corners\n\n // Output image dimensions\n const x_scale = out_width / in_width;\n const y_scale = out_height / in_height;\n\n // Output image\n // @ts-ignore\n const out_img = new input.constructor(out_height * out_width * in_channels);\n\n // Pre-calculate strides\n const inStride = in_height * in_width;\n const outStride = out_height * out_width;\n\n for (let i = 0; i < out_height; ++i) {\n for (let j = 0; j < out_width; ++j) {\n // Calculate output offset\n const outOffset = i * out_width + j;\n\n // Calculate input pixel coordinates\n const x = (j + 0.5) / x_scale - 0.5;\n const y = (i + 0.5) / y_scale - 0.5;\n\n // Calculate the four nearest input pixels\n // We also check if the input pixel coordinates are within the image bounds\n let x1 = Math.floor(x);\n let y1 = Math.floor(y);\n const x2 = Math.min(x1 + 1, in_width - 1);\n const y2 = Math.min(y1 + 1, in_height - 1);\n\n x1 = Math.max(x1, 0);\n y1 = Math.max(y1, 0);\n\n\n // Calculate the fractional distances between the input pixel and the four nearest pixels\n const s = x - x1;\n const t = y - y1;\n\n // Perform bilinear interpolation\n const w1 = (1 - s) * (1 - t);\n const w2 = s * (1 - t);\n const w3 = (1 - s) * t;\n const w4 = s * t;\n\n // Calculate the four nearest input pixel indices\n const yStride = y1 * in_width;\n const xStride = y2 * in_width;\n const idx1 = yStride + x1;\n const idx2 = yStride + x2;\n const idx3 = xStride + x1;\n const idx4 = xStride + x2;\n\n for (let k = 0; k < in_channels; ++k) {\n // Calculate channel offset\n const cOffset = k * inStride;\n\n out_img[k * outStride + outOffset] =\n w1 * input[cOffset + idx1] +\n w2 * input[cOffset + idx2] +\n w3 * input[cOffset + idx3] +\n w4 * input[cOffset + idx4];\n }\n }\n }\n\n return out_img;\n}\n\n\n/**\n * Helper method to permute a `AnyTypedArray` directly\n * @template {AnyTypedArray} T \n * @param {T} array \n * @param {number[]} dims \n * @param {number[]} axes \n * @returns {[T, number[]]} The permuted array and the new shape.\n */\nexport function permute_data(array, dims, axes) {\n // Calculate the new shape of the permuted array\n // and the stride of the original array\n const shape = new Array(axes.length);\n const stride = new Array(axes.length);\n\n for (let i = axes.length - 1, s = 1; i >= 0; --i) {\n stride[i] = s;\n shape[i] = dims[axes[i]];\n s *= shape[i];\n }\n\n // Precompute inverse mapping of stride\n const invStride = axes.map((_, i) => stride[axes.indexOf(i)]);\n\n // Create the permuted array with the new shape\n // @ts-ignore\n const permutedData = new array.constructor(array.length);\n\n // Permute the original array to the new array\n for (let i = 0; i < array.length; ++i) {\n let newIndex = 0;\n for (let j = dims.length - 1, k = i; j >= 0; --j) {\n newIndex += (k % dims[j]) * invStride[j];\n k = Math.floor(k / dims[j]);\n }\n permutedData[newIndex] = array[i];\n }\n\n return [permutedData, shape];\n}\n\n\n/**\n * Compute the softmax of an array of numbers.\n * @template {TypedArray|number[]} T\n * @param {T} arr The array of numbers to compute the softmax of.\n * @returns {T} The softmax array.\n */\nexport function softmax(arr) {\n // Compute the maximum value in the array\n const maxVal = max(arr)[0];\n\n // Compute the exponentials of the array values\n const exps = arr.map(x => Math.exp(x - maxVal));\n\n // Compute the sum of the exponentials\n // @ts-ignore\n const sumExps = exps.reduce((acc, val) => acc + val, 0);\n\n // Compute the softmax values\n const softmaxArr = exps.map(x => x / sumExps);\n\n return /** @type {T} */(softmaxArr);\n}\n\n/**\n * Calculates the logarithm of the softmax function for the input array.\n * @template {TypedArray|number[]} T\n * @param {T} arr The input array to calculate the log_softmax function for.\n * @returns {T} The resulting log_softmax array.\n */\nexport function log_softmax(arr) {\n // Compute the softmax values\n const softmaxArr = softmax(arr);\n\n // Apply log formula to each element\n const logSoftmaxArr = softmaxArr.map(x => Math.log(x));\n\n return /** @type {T} */(logSoftmaxArr);\n}\n\n/**\n * Calculates the dot product of two arrays.\n * @param {number[]} arr1 The first array.\n * @param {number[]} arr2 The second array.\n * @returns {number} The dot product of arr1 and arr2.\n */\nexport function dot(arr1, arr2) {\n let result = 0;\n for (let i = 0; i < arr1.length; ++i) {\n result += arr1[i] * arr2[i];\n }\n return result;\n}\n\n\n/**\n * Get the top k items from an iterable, sorted by descending order\n * @param {any[]|TypedArray} items The items to be sorted\n * @param {number|null} [top_k=0] The number of top items to return (default: 0 = return all)\n * @returns {[number, any][]} The top k items, sorted by descending order\n */\nexport function getTopItems(items, top_k = 0) {\n // if top == 0, return all\n\n items = Array.from(items)\n .map((x, i) => [i, x]) // Get indices ([index, score])\n .sort((a, b) => b[1] - a[1]) // Sort by log probabilities\n\n if (top_k !== null && top_k > 0) {\n items = items.slice(0, top_k); // Get top k items\n }\n\n return items\n}\n\n/**\n * Computes the cosine similarity between two arrays.\n *\n * @param {number[]} arr1 The first array.\n * @param {number[]} arr2 The second array.\n * @returns {number} The cosine similarity between the two arrays.\n */\nexport function cos_sim(arr1, arr2) {\n // Calculate dot product of the two arrays\n const dotProduct = dot(arr1, arr2);\n\n // Calculate the magnitude of the first array\n const magnitudeA = magnitude(arr1);\n\n // Calculate the magnitude of the second array\n const magnitudeB = magnitude(arr2);\n\n // Calculate the cosine similarity\n const cosineSimilarity = dotProduct / (magnitudeA * magnitudeB);\n\n return cosineSimilarity;\n}\n\n/**\n * Calculates the magnitude of a given array.\n * @param {number[]} arr The array to calculate the magnitude of.\n * @returns {number} The magnitude of the array.\n */\nexport function magnitude(arr) {\n return Math.sqrt(arr.reduce((acc, val) => acc + val * val, 0));\n}\n\n\n/**\n * Returns the value and index of the minimum element in an array.\n * @param {number[]|TypedArray} arr array of numbers.\n * @returns {number[]} the value and index of the minimum element, of the form: [valueOfMin, indexOfMin]\n * @throws {Error} If array is empty.\n */\nexport function min(arr) {\n if (arr.length === 0) throw Error('Array must not be empty');\n let min = arr[0];\n let indexOfMin = 0;\n for (let i = 1; i < arr.length; ++i) {\n if (arr[i] < min) {\n min = arr[i];\n indexOfMin = i;\n }\n }\n return [min, indexOfMin];\n}\n\n\n/**\n * Returns the value and index of the maximum element in an array.\n * @param {number[]|AnyTypedArray} arr array of numbers.\n * @returns {[number, number]} the value and index of the maximum element, of the form: [valueOfMax, indexOfMax]\n * @throws {Error} If array is empty.\n */\nexport function max(arr) {\n if (arr.length === 0) throw Error('Array must not be empty');\n let max = arr[0];\n let indexOfMax = 0;\n for (let i = 1; i < arr.length; ++i) {\n if (arr[i] > max) {\n max = arr[i];\n indexOfMax = i;\n }\n }\n return [Number(max), indexOfMax];\n}\n\nfunction isPowerOfTwo(number) {\n // Check if the number is greater than 0 and has only one bit set to 1\n return (number > 0) && ((number & (number - 1)) === 0);\n}\n\n/**\n * Implementation of Radix-4 FFT.\n * \n * P2FFT class provides functionality for performing Fast Fourier Transform on arrays\n * which are a power of two in length.\n * Code adapted from https://www.npmjs.com/package/fft.js\n */\nclass P2FFT {\n /**\n * @param {number} size The size of the input array. Must be a power of two larger than 1.\n * @throws {Error} FFT size must be a power of two larger than 1.\n */\n constructor(size) {\n this.size = size | 0; // convert to a 32-bit signed integer\n if (this.size <= 1 || !isPowerOfTwo(this.size))\n throw new Error('FFT size must be a power of two larger than 1');\n\n this._csize = size << 1;\n\n this.table = new Float64Array(this.size * 2);\n for (let i = 0; i < this.table.length; i += 2) {\n const angle = Math.PI * i / this.size;\n this.table[i] = Math.cos(angle);\n this.table[i + 1] = -Math.sin(angle);\n }\n\n // Find size's power of two\n let power = 0;\n for (let t = 1; this.size > t; t <<= 1)\n ++power;\n\n // Calculate initial step's width:\n // * If we are full radix-4, it is 2x smaller to give inital len=8\n // * Otherwise it is the same as `power` to give len=4\n this._width = power % 2 === 0 ? power - 1 : power;\n\n // Pre-compute bit-reversal patterns\n this._bitrev = new Int32Array(1 << this._width);\n for (let j = 0; j < this._bitrev.length; ++j) {\n this._bitrev[j] = 0;\n for (let shift = 0; shift < this._width; shift += 2) {\n const revShift = this._width - shift - 2;\n this._bitrev[j] |= ((j >>> shift) & 3) << revShift;\n }\n }\n }\n\n /**\n * Create a complex number array with size `2 * size`\n *\n * @returns {Float64Array} A complex number array with size `2 * size`\n */\n createComplexArray() {\n return new Float64Array(this._csize);\n }\n\n /**\n * Converts a complex number representation stored in a Float64Array to an array of real numbers.\n * \n * @param {Float64Array} complex The complex number representation to be converted.\n * @param {number[]} [storage] An optional array to store the result in.\n * @returns {number[]} An array of real numbers representing the input complex number representation.\n */\n fromComplexArray(complex, storage) {\n const res = storage || new Array(complex.length >>> 1);\n for (let i = 0; i < complex.length; i += 2)\n res[i >>> 1] = complex[i];\n return res;\n }\n\n /**\n * Convert a real-valued input array to a complex-valued output array.\n * @param {Float64Array} input The real-valued input array.\n * @param {Float64Array} [storage] Optional buffer to store the output array.\n * @returns {Float64Array} The complex-valued output array.\n */\n toComplexArray(input, storage) {\n const res = storage || this.createComplexArray();\n for (let i = 0; i < res.length; i += 2) {\n res[i] = input[i >>> 1];\n res[i + 1] = 0;\n }\n return res;\n }\n\n /**\n * Performs a Fast Fourier Transform (FFT) on the given input data and stores the result in the output buffer.\n * \n * @param {Float64Array} out The output buffer to store the result.\n * @param {Float64Array} data The input data to transform.\n * \n * @throws {Error} Input and output buffers must be different.\n * \n * @returns {void}\n */\n transform(out, data) {\n if (out === data)\n throw new Error('Input and output buffers must be different');\n\n this._transform4(out, data, 1 /* DONE */);\n }\n\n /**\n * Performs a real-valued forward FFT on the given input buffer and stores the result in the given output buffer.\n * The input buffer must contain real values only, while the output buffer will contain complex values. The input and\n * output buffers must be different.\n *\n * @param {Float64Array} out The output buffer.\n * @param {Float64Array} data The input buffer containing real values.\n *\n * @throws {Error} If the input and output buffers are the same.\n */\n realTransform(out, data) {\n if (out === data)\n throw new Error('Input and output buffers must be different');\n\n this._realTransform4(out, data, 1 /* DONE */);\n }\n\n /**\n * Performs an inverse FFT transformation on the given `data` array, and stores the result in `out`.\n * The `out` array must be a different buffer than the `data` array. The `out` array will contain the\n * result of the transformation. The `data` array will not be modified.\n * \n * @param {Float64Array} out The output buffer for the transformed data.\n * @param {Float64Array} data The input data to transform.\n * @throws {Error} If `out` and `data` refer to the same buffer.\n * @returns {void}\n */\n inverseTransform(out, data) {\n if (out === data)\n throw new Error('Input and output buffers must be different');\n\n this._transform4(out, data, -1 /* DONE */);\n for (let i = 0; i < out.length; ++i)\n out[i] /= this.size;\n }\n\n /**\n * Performs a radix-4 implementation of a discrete Fourier transform on a given set of data.\n *\n * @param {Float64Array} out The output buffer for the transformed data.\n * @param {Float64Array} data The input buffer of data to be transformed.\n * @param {number} inv A scaling factor to apply to the transform.\n * @returns {void}\n */\n _transform4(out, data, inv) {\n // radix-4 implementation\n\n const size = this._csize;\n\n // Initial step (permute and transform)\n const width = this._width;\n let step = 1 << width;\n let len = (size / step) << 1;\n\n let outOff;\n let t;\n const bitrev = this._bitrev;\n if (len === 4) {\n for (outOff = 0, t = 0; outOff < size; outOff += len, ++t) {\n const off = bitrev[t];\n this._singleTransform2(data, out, outOff, off, step);\n }\n } else {\n // len === 8\n for (outOff = 0, t = 0; outOff < size; outOff += len, ++t) {\n const off = bitrev[t];\n this._singleTransform4(data, out, outOff, off, step, inv);\n }\n }\n\n // Loop through steps in decreasing order\n const table = this.table;\n for (step >>= 2; step >= 2; step >>= 2) {\n len = (size / step) << 1;\n const quarterLen = len >>> 2;\n\n // Loop through offsets in the data\n for (outOff = 0; outOff < size; outOff += len) {\n // Full case\n const limit = outOff + quarterLen - 1;\n for (let i = outOff, k = 0; i < limit; i += 2, k += step) {\n const A = i;\n const B = A + quarterLen;\n const C = B + quarterLen;\n const D = C + quarterLen;\n\n // Original values\n const Ar = out[A];\n const Ai = out[A + 1];\n const Br = out[B];\n const Bi = out[B + 1];\n const Cr = out[C];\n const Ci = out[C + 1];\n const Dr = out[D];\n const Di = out[D + 1];\n\n const tableBr = table[k];\n const tableBi = inv * table[k + 1];\n const MBr = Br * tableBr - Bi * tableBi;\n const MBi = Br * tableBi + Bi * tableBr;\n\n const tableCr = table[2 * k];\n const tableCi = inv * table[2 * k + 1];\n const MCr = Cr * tableCr - Ci * tableCi;\n const MCi = Cr * tableCi + Ci * tableCr;\n\n const tableDr = table[3 * k];\n const tableDi = inv * table[3 * k + 1];\n const MDr = Dr * tableDr - Di * tableDi;\n const MDi = Dr * tableDi + Di * tableDr;\n\n // Pre-Final values\n const T0r = Ar + MCr;\n const T0i = Ai + MCi;\n const T1r = Ar - MCr;\n const T1i = Ai - MCi;\n const T2r = MBr + MDr;\n const T2i = MBi + MDi;\n const T3r = inv * (MBr - MDr);\n const T3i = inv * (MBi - MDi);\n\n // Final values\n out[A] = T0r + T2r;\n out[A + 1] = T0i + T2i;\n out[B] = T1r + T3i;\n out[B + 1] = T1i - T3r;\n out[C] = T0r - T2r;\n out[C + 1] = T0i - T2i;\n out[D] = T1r - T3i;\n out[D + 1] = T1i + T3r;\n }\n }\n }\n }\n\n /**\n * Performs a radix-2 implementation of a discrete Fourier transform on a given set of data.\n *\n * @param {Float64Array} data The input buffer of data to be transformed.\n * @param {Float64Array} out The output buffer for the transformed data.\n * @param {number} outOff The offset at which to write the output data.\n * @param {number} off The offset at which to begin reading the input data.\n * @param {number} step The step size for indexing the input data.\n * @returns {void}\n */\n _singleTransform2(data, out, outOff, off, step) {\n // radix-2 implementation\n // NOTE: Only called for len=4\n\n const evenR = data[off];\n const evenI = data[off + 1];\n const oddR = data[off + step];\n const oddI = data[off + step + 1];\n\n out[outOff] = evenR + oddR;\n out[outOff + 1] = evenI + oddI;\n out[outOff + 2] = evenR - oddR;\n out[outOff + 3] = evenI - oddI;\n }\n\n /**\n * Performs radix-4 transformation on input data of length 8\n *\n * @param {Float64Array} data Input data array of length 8\n * @param {Float64Array} out Output data array of length 8\n * @param {number} outOff Index of output array to start writing from\n * @param {number} off Index of input array to start reading from\n * @param {number} step Step size between elements in input array\n * @param {number} inv Scaling factor for inverse transform\n * \n * @returns {void}\n */\n _singleTransform4(data, out, outOff, off, step, inv) {\n // radix-4\n // NOTE: Only called for len=8\n const step2 = step * 2;\n const step3 = step * 3;\n\n // Original values\n const Ar = data[off];\n const Ai = data[off + 1];\n const Br = data[off + step];\n const Bi = data[off + step + 1];\n const Cr = data[off + step2];\n const Ci = data[off + step2 + 1];\n const Dr = data[off + step3];\n const Di = data[off + step3 + 1];\n\n // Pre-Final values\n const T0r = Ar + Cr;\n const T0i = Ai + Ci;\n const T1r = Ar - Cr;\n const T1i = Ai - Ci;\n const T2r = Br + Dr;\n const T2i = Bi + Di;\n const T3r = inv * (Br - Dr);\n const T3i = inv * (Bi - Di);\n\n // Final values\n out[outOff] = T0r + T2r;\n out[outOff + 1] = T0i + T2i;\n out[outOff + 2] = T1r + T3i;\n out[outOff + 3] = T1i - T3r;\n out[outOff + 4] = T0r - T2r;\n out[outOff + 5] = T0i - T2i;\n out[outOff + 6] = T1r - T3i;\n out[outOff + 7] = T1i + T3r;\n }\n\n /**\n * Real input radix-4 implementation\n * @param {Float64Array} out Output array for the transformed data\n * @param {Float64Array} data Input array of real data to be transformed\n * @param {number} inv The scale factor used to normalize the inverse transform\n */\n _realTransform4(out, data, inv) {\n // Real input radix-4 implementation\n const size = this._csize;\n\n // Initial step (permute and transform)\n const width = this._width;\n let step = 1 << width;\n let len = (size / step) << 1;\n\n let outOff;\n let t;\n const bitrev = this._bitrev;\n if (len === 4) {\n for (outOff = 0, t = 0; outOff < size; outOff += len, ++t) {\n const off = bitrev[t];\n this._singleRealTransform2(data, out, outOff, off >>> 1, step >>> 1);\n }\n } else {\n // len === 8\n for (outOff = 0, t = 0; outOff < size; outOff += len, ++t) {\n const off = bitrev[t];\n this._singleRealTransform4(data, out, outOff, off >>> 1, step >>> 1, inv);\n }\n }\n\n // Loop through steps in decreasing order\n const table = this.table;\n for (step >>= 2; step >= 2; step >>= 2) {\n len = (size / step) << 1;\n const halfLen = len >>> 1;\n const quarterLen = halfLen >>> 1;\n const hquarterLen = quarterLen >>> 1;\n\n // Loop through offsets in the data\n for (outOff = 0; outOff < size; outOff += len) {\n for (let i = 0, k = 0; i <= hquarterLen; i += 2, k += step) {\n const A = outOff + i;\n const B = A + quarterLen;\n const C = B + quarterLen;\n const D = C + quarterLen;\n\n // Original values\n const Ar = out[A];\n const Ai = out[A + 1];\n const Br = out[B];\n const Bi = out[B + 1];\n const Cr = out[C];\n const Ci = out[C + 1];\n const Dr = out[D];\n const Di = out[D + 1];\n\n // Middle values\n const MAr = Ar;\n const MAi = Ai;\n\n const tableBr = table[k];\n const tableBi = inv * table[k + 1];\n const MBr = Br * tableBr - Bi * tableBi;\n const MBi = Br * tableBi + Bi * tableBr;\n\n const tableCr = table[2 * k];\n const tableCi = inv * table[2 * k + 1];\n const MCr = Cr * tableCr - Ci * tableCi;\n const MCi = Cr * tableCi + Ci * tableCr;\n\n const tableDr = table[3 * k];\n const tableDi = inv * table[3 * k + 1];\n const MDr = Dr * tableDr - Di * tableDi;\n const MDi = Dr * tableDi + Di * tableDr;\n\n // Pre-Final values\n const T0r = MAr + MCr;\n const T0i = MAi + MCi;\n const T1r = MAr - MCr;\n const T1i = MAi - MCi;\n const T2r = MBr + MDr;\n const T2i = MBi + MDi;\n const T3r = inv * (MBr - MDr);\n const T3i = inv * (MBi - MDi);\n\n // Final values\n out[A] = T0r + T2r;\n out[A + 1] = T0i + T2i;\n out[B] = T1r + T3i;\n out[B + 1] = T1i - T3r;\n\n // Output final middle point\n if (i === 0) {\n out[C] = T0r - T2r;\n out[C + 1] = T0i - T2i;\n continue;\n }\n\n // Do not overwrite ourselves\n if (i === hquarterLen)\n continue;\n\n const SA = outOff + quarterLen - i;\n const SB = outOff + halfLen - i;\n\n out[SA] = T1r - inv * T3i;\n out[SA + 1] = -T1i - inv * T3r;\n out[SB] = T0r - inv * T2r;\n out[SB + 1] = -T0i + inv * T2i;\n }\n }\n }\n\n // Complete the spectrum by adding its mirrored negative frequency components.\n const half = size >>> 1;\n for (let i = 2; i < half; i += 2) {\n out[size - i] = out[i];\n out[size - i + 1] = -out[i + 1];\n }\n }\n\n /**\n * Performs a single real input radix-2 transformation on the provided data\n * \n * @param {Float64Array} data The input data array\n * @param {Float64Array} out The output data array\n * @param {number} outOff The output offset\n * @param {number} off The input offset\n * @param {number} step The step\n * \n * @returns {void}\n */\n _singleRealTransform2(data, out, outOff, off, step) {\n // radix-2 implementation\n // NOTE: Only called for len=4\n\n const evenR = data[off];\n const oddR = data[off + step];\n\n out[outOff] = evenR + oddR;\n out[outOff + 1] = 0;\n out[outOff + 2] = evenR - oddR;\n out[outOff + 3] = 0;\n }\n\n /**\n * Computes a single real-valued transform using radix-4 algorithm.\n * This method is only called for len=8.\n *\n * @param {Float64Array} data The input data array.\n * @param {Float64Array} out The output data array.\n * @param {number} outOff The offset into the output array.\n * @param {number} off The offset into the input array.\n * @param {number} step The step size for the input array.\n * @param {number} inv The value of inverse.\n */\n _singleRealTransform4(data, out, outOff, off, step, inv) {\n // radix-4\n // NOTE: Only called for len=8\n const step2 = step * 2;\n const step3 = step * 3;\n\n // Original values\n const Ar = data[off];\n const Br = data[off + step];\n const Cr = data[off + step2];\n const Dr = data[off + step3];\n\n // Pre-Final values\n const T0r = Ar + Cr;\n const T1r = Ar - Cr;\n const T2r = Br + Dr;\n const T3r = inv * (Br - Dr);\n\n // Final values\n out[outOff] = T0r + T2r;\n out[outOff + 1] = 0;\n out[outOff + 2] = T1r;\n out[outOff + 3] = -T3r;\n out[outOff + 4] = T0r - T2r;\n out[outOff + 5] = 0;\n out[outOff + 6] = T1r;\n out[outOff + 7] = T3r;\n }\n}\n\n/**\n * NP2FFT class provides functionality for performing Fast Fourier Transform on arrays\n * which are not a power of two in length. In such cases, the chirp-z transform is used.\n * \n * For more information, see: https://math.stackexchange.com/questions/77118/non-power-of-2-ffts/77156#77156\n */\nclass NP2FFT {\n\n /**\n * Constructs a new NP2FFT object.\n * @param {number} fft_length The length of the FFT\n */\n constructor(fft_length) {\n // Helper variables\n const a = 2 * (fft_length - 1);\n const b = 2 * (2 * fft_length - 1);\n const nextP2 = 2 ** (Math.ceil(Math.log2(b)))\n this.bufferSize = nextP2;\n this._a = a;\n\n // Define buffers\n // Compute chirp for transform\n const chirp = new Float64Array(b);\n const ichirp = new Float64Array(nextP2);\n this._chirpBuffer = new Float64Array(nextP2);\n this._buffer1 = new Float64Array(nextP2);\n this._buffer2 = new Float64Array(nextP2);\n this._outBuffer1 = new Float64Array(nextP2);\n this._outBuffer2 = new Float64Array(nextP2);\n\n // Compute complex exponentiation\n const theta = -2 * Math.PI / fft_length;\n const baseR = Math.cos(theta);\n const baseI = Math.sin(theta);\n\n // Precompute helper for chirp-z transform\n for (let i = 0; i < b >> 1; ++i) {\n // Compute complex power:\n const e = (i + 1 - fft_length) ** 2 / 2.0;\n\n // Compute the modulus and argument of the result\n const result_mod = Math.sqrt(baseR ** 2 + baseI ** 2) ** e;\n const result_arg = e * Math.atan2(baseI, baseR);\n\n // Convert the result back to rectangular form\n // and assign to chirp and ichirp\n const i2 = 2 * i;\n chirp[i2] = result_mod * Math.cos(result_arg);\n chirp[i2 + 1] = result_mod * Math.sin(result_arg);\n\n // conjugate\n ichirp[i2] = chirp[i2];\n ichirp[i2 + 1] = - chirp[i2 + 1];\n }\n this._slicedChirpBuffer = chirp.subarray(a, b);\n\n // create object to perform Fast Fourier Transforms\n // with `nextP2` complex numbers\n this._f = new P2FFT(nextP2 >> 1);\n this._f.transform(this._chirpBuffer, ichirp);\n }\n\n _transform(output, input, real) {\n const ib1 = this._buffer1;\n const ib2 = this._buffer2;\n const ob2 = this._outBuffer1;\n const ob3 = this._outBuffer2;\n const cb = this._chirpBuffer;\n const sb = this._slicedChirpBuffer;\n const a = this._a;\n\n if (real) {\n // Real multiplication\n for (let j = 0; j < sb.length; j += 2) {\n const j2 = j + 1\n const j3 = j >> 1;\n\n const a_real = input[j3];\n ib1[j] = a_real * sb[j];\n ib1[j2] = a_real * sb[j2];\n }\n } else {\n // Complex multiplication\n for (let j = 0; j < sb.length; j += 2) {\n const j2 = j + 1\n ib1[j] = input[j] * sb[j] - input[j2] * sb[j2];\n ib1[j2] = input[j] * sb[j2] + input[j2] * sb[j];\n }\n }\n this._f.transform(ob2, ib1);\n\n for (let j = 0; j < cb.length; j += 2) {\n const j2 = j + 1;\n\n ib2[j] = ob2[j] * cb[j] - ob2[j2] * cb[j2];\n ib2[j2] = ob2[j] * cb[j2] + ob2[j2] * cb[j];\n }\n this._f.inverseTransform(ob3, ib2);\n\n for (let j = 0; j < ob3.length; j += 2) {\n const a_real = ob3[j + a];\n const a_imag = ob3[j + a + 1];\n const b_real = sb[j];\n const b_imag = sb[j + 1];\n\n output[j] = a_real * b_real - a_imag * b_imag;\n output[j + 1] = a_real * b_imag + a_imag * b_real;\n }\n }\n\n transform(output, input) {\n this._transform(output, input, false);\n }\n\n realTransform(output, input) {\n this._transform(output, input, true);\n }\n}\n\nexport class FFT {\n constructor(fft_length) {\n this.fft_length = fft_length;\n this.isPowerOfTwo = isPowerOfTwo(fft_length);\n if (this.isPowerOfTwo) {\n this.fft = new P2FFT(fft_length);\n this.outputBufferSize = 2 * fft_length;\n } else {\n this.fft = new NP2FFT(fft_length);\n this.outputBufferSize = this.fft.bufferSize;\n }\n }\n\n realTransform(out, input) {\n this.fft.realTransform(out, input);\n }\n\n transform(out, input) {\n this.fft.transform(out, input);\n }\n}\n\n\n/**\n * Performs median filter on the provided data. Padding is done by mirroring the data.\n * @param {AnyTypedArray} data The input array\n * @param {number} windowSize The window size\n */\nexport function medianFilter(data, windowSize) {\n\n if (windowSize % 2 === 0 || windowSize <= 0) {\n throw new Error('Window size must be a positive odd number');\n }\n\n // @ts-ignore\n const outputArray = new data.constructor(data.length);\n\n // @ts-ignore\n const buffer = new data.constructor(windowSize); // Reusable array for storing values\n\n const halfWindowSize = Math.floor(windowSize / 2);\n\n for (let i = 0; i < data.length; ++i) {\n let valuesIndex = 0;\n\n for (let j = -halfWindowSize; j <= halfWindowSize; ++j) {\n let index = i + j;\n if (index < 0) {\n index = Math.abs(index);\n } else if (index >= data.length) {\n index = 2 * (data.length - 1) - index;\n }\n\n buffer[valuesIndex++] = data[index];\n }\n\n buffer.sort();\n outputArray[i] = buffer[halfWindowSize];\n }\n\n return outputArray;\n}\n\n/**\n * Helper function to round a number to a given number of decimals\n * @param {number} num The number to round\n * @param {number} decimals The number of decimals\n * @returns {number} The rounded number\n */\nexport function round(num, decimals) {\n const pow = Math.pow(10, decimals);\n return Math.round(num * pow) / pow;\n}\n\n/**\n * Helper function to round a number to the nearest integer, with ties rounded to the nearest even number.\n * Also known as \"bankers' rounding\". This is the default rounding mode in python. For example:\n * 1.5 rounds to 2 and 2.5 rounds to 2.\n * \n * @param {number} x The number to round\n * @returns {number} The rounded number\n */\nexport function bankers_round(x) {\n const r = Math.round(x);\n const br = Math.abs(x) % 1 === 0.5 ? (r % 2 === 0 ? r : r - 1) : r;\n return br;\n}\n"],"names":["max"],"mappings":"AAiGO,SAAS,aAAa,OAAO,MAAM,MAAM;AAG5C,QAAM,QAAQ,IAAI,MAAM,KAAK,MAAM;AACnC,QAAM,SAAS,IAAI,MAAM,KAAK,MAAM;AAEpC,WAAS,IAAI,KAAK,SAAS,GAAG,IAAI,GAAG,KAAK,GAAG,EAAE,GAAG;AAC9C,WAAO,CAAC,IAAI;AACZ,UAAM,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;AACvB,SAAK,MAAM,CAAC;AAAA,EAChB;AAGA,QAAM,YAAY,KAAK,IAAI,CAAC,GAAG,MAAM,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC;AAI5D,QAAM,eAAe,IAAI,MAAM,YAAY,MAAM,MAAM;AAGvD,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,EAAE,GAAG;AACnC,QAAI,WAAW;AACf,aAAS,IAAI,KAAK,SAAS,GAAG,IAAI,GAAG,KAAK,GAAG,EAAE,GAAG;AAC9C,kBAAa,IAAI,KAAK,CAAC,IAAK,UAAU,CAAC;AACvC,UAAI,KAAK,MAAM,IAAI,KAAK,CAAC,CAAC;AAAA,IAC9B;AACA,iBAAa,QAAQ,IAAI,MAAM,CAAC;AAAA,EACpC;AAEA,SAAO,CAAC,cAAc,KAAK;AAC/B;AASO,SAAS,QAAQ,KAAK;AAEzB,QAAM,SAAS,IAAI,GAAG,EAAE,CAAC;AAGzB,QAAM,OAAO,IAAI,IAAI,OAAK,KAAK,IAAI,IAAI,MAAM,CAAC;AAI9C,QAAM,UAAU,KAAK,OAAO,CAAC,KAAK,QAAQ,MAAM,KAAK,CAAC;AAGtD,QAAM,aAAa,KAAK,IAAI,OAAK,IAAI,OAAO;AAE5C;AAAA;AAAA,IAAwB;AAAA;AAC5B;AAQO,SAAS,YAAY,KAAK;AAE7B,QAAM,aAAa,QAAQ,GAAG;AAG9B,QAAM,gBAAgB,WAAW,IAAI,OAAK,KAAK,IAAI,CAAC,CAAC;AAErD;AAAA;AAAA,IAAwB;AAAA;AAC5B;AAuBO,SAAS,YAAY,OAAO,QAAQ,GAAG;AAG1C,UAAQ,MAAM,KAAK,KAAK,EACnB,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EACpB,KAAK,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAE/B,MAAI,UAAU,QAAQ,QAAQ,GAAG;AAC7B,YAAQ,MAAM,MAAM,GAAG,KAAK;AAAA,EAChC;AAEA,SAAO;AACX;AA6DO,SAAS,IAAI,KAAK;AACrB,MAAI,IAAI,WAAW,EAAG,OAAM,MAAM,yBAAyB;AAC3D,MAAIA,OAAM,IAAI,CAAC;AACf,MAAI,aAAa;AACjB,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,EAAE,GAAG;AACjC,QAAI,IAAI,CAAC,IAAIA,MAAK;AACd,MAAAA,OAAM,IAAI,CAAC;AACX,mBAAa;AAAA,IACjB;AAAA,EACJ;AACA,SAAO,CAAC,OAAOA,IAAG,GAAG,UAAU;AACnC;AA4oBO,SAAS,aAAa,MAAM,YAAY;AAE3C,MAAI,aAAa,MAAM,KAAK,cAAc,GAAG;AACzC,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC/D;AAGA,QAAM,cAAc,IAAI,KAAK,YAAY,KAAK,MAAM;AAGpD,QAAM,SAAS,IAAI,KAAK,YAAY,UAAU;AAE9C,QAAM,iBAAiB,KAAK,MAAM,aAAa,CAAC;AAEhD,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,EAAE,GAAG;AAClC,QAAI,cAAc;AAElB,aAAS,IAAI,CAAC,gBAAgB,KAAK,gBAAgB,EAAE,GAAG;AACpD,UAAI,QAAQ,IAAI;AAChB,UAAI,QAAQ,GAAG;AACX,gBAAQ,KAAK,IAAI,KAAK;AAAA,MAC1B,WAAW,SAAS,KAAK,QAAQ;AAC7B,gBAAQ,KAAK,KAAK,SAAS,KAAK;AAAA,MACpC;AAEA,aAAO,aAAa,IAAI,KAAK,KAAK;AAAA,IACtC;AAEA,WAAO,KAAI;AACX,gBAAY,CAAC,IAAI,OAAO,cAAc;AAAA,EAC1C;AAEA,SAAO;AACX;","x_google_ignoreList":[0]}