@ni/nimble-components 32.7.0 → 32.7.2

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.
@@ -1 +1 @@
1
- export declare const workerCode = "var MatrixRenderer = (function (exports) {\n 'use strict';\n\n /**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n const proxyMarker = Symbol(\"Comlink.proxy\");\n const createEndpoint = Symbol(\"Comlink.endpoint\");\n const releaseProxy = Symbol(\"Comlink.releaseProxy\");\n const finalizer = Symbol(\"Comlink.finalizer\");\n const throwMarker = Symbol(\"Comlink.thrown\");\n const isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n /**\n * Internal transfer handle to handle objects marked to proxy.\n */\n const proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n };\n /**\n * Internal transfer handler to handle thrown exceptions.\n */\n const throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n };\n /**\n * Allows customizing the serialization of certain values.\n */\n const transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n ]);\n function isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n }\n function expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n }\n function isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n }\n function closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n }\n function wrap(ep, target) {\n return createProxy(ep, [], target);\n }\n function throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n }\n function releaseEndpoint(ep) {\n return requestResponseMessage(ep, {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n }\n const proxyCounter = new WeakMap();\n const proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\n function registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n }\n function unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n }\n function createProxy(ep, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously \u00AF\\_(\u30C4)_/\u00AF\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn\u2019t happen.\n if (last === \"bind\") {\n return createProxy(ep, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n }\n function myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n }\n function processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n }\n const transferCache = new WeakMap();\n function transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n }\n function proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n }\n function toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n }\n function fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n }\n function requestResponseMessage(ep, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n ep.addEventListener(\"message\", function l(ev) {\n if (!ev.data || !ev.data.id || ev.data.id !== id) {\n return;\n }\n ep.removeEventListener(\"message\", l);\n resolve(ev.data);\n });\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n }\n function generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n }\n\n /**\n * MatrixRenderer class is meant to be used within a Web Worker context,\n * using Comlink to facilitate communication between the main thread and the worker.\n * The MatrixRenderer class manages a matrix of dies, once an instance of MatrixRenderer is created,\n * it is exposed to the main thread using Comlink's `expose` method.\n * This setup is used in the wafer-map component to perform heavy computational duties\n */\n class MatrixRenderer {\n constructor() {\n this.values = Float64Array.from([]);\n this.scaledColumnIndices = Float64Array.from([]);\n this.scaledRowIndices = Float64Array.from([]);\n this.columnIndicesPositions = Int32Array.from([]);\n this.colorIndices = Int32Array.from([]);\n this.colors = [];\n this.colorValues = Float64Array.from([]);\n this.outsideRangeDieColor = 'rgba(218,223,236,1)';\n this.fontSizeFactor = 0.8;\n this.renderConfig = {\n dieDimensions: {\n width: 0,\n height: 0\n },\n margin: {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n },\n verticalCoefficient: 1,\n horizontalCoefficient: 1,\n horizontalConstant: 0,\n verticalConstant: 0,\n gridMinX: 0,\n gridMaxX: 0,\n gridMinY: 0,\n gridMaxY: 0,\n labelsFontSize: 0,\n colorScale: [],\n dieLabelsSuffix: '',\n maxCharacters: 0\n };\n this.transformConfig = {\n transform: {\n k: 1,\n x: 0,\n y: 0\n },\n topLeftCanvasCorner: {\n x: 0,\n y: 0\n },\n bottomRightCanvasCorner: {\n x: 0,\n y: 0\n }\n };\n }\n setMatrixData(columnIndices, rowIndices, valuesBuffer) {\n const scaledColumnIndex = [];\n const columnPositions = [];\n const scaledRowIndices = [];\n const values = [];\n const colorIndices = [];\n let prevXIndex;\n let dieCount = 0;\n for (let i = 0; i < columnIndices.length; i++) {\n const xIndex = columnIndices[i];\n const yIndex = rowIndices[i];\n if (this.isDieInGrid(xIndex, yIndex)) {\n if (xIndex !== prevXIndex) {\n scaledColumnIndex.push(this.calculateHorizontalScaledIndices(xIndex));\n columnPositions.push(dieCount);\n prevXIndex = xIndex;\n }\n scaledRowIndices.push(this.calculateVerticalScaledIndices(yIndex));\n const value = valuesBuffer[i];\n values.push(value);\n colorIndices.push(this.findColorIndex(value));\n dieCount += 1;\n }\n }\n this.scaledColumnIndices = Float64Array.from(scaledColumnIndex);\n this.columnIndicesPositions = Int32Array.from(columnPositions);\n this.scaledRowIndices = Float64Array.from(scaledRowIndices);\n this.values = Float64Array.from(values);\n this.colorIndices = Int32Array.from(colorIndices);\n }\n setRenderConfig(renderConfig) {\n this.renderConfig = renderConfig;\n this.colors = renderConfig.colorScale.map(marker => marker.color);\n this.colorValues = Float64Array.from(renderConfig.colorScale.map(marker => marker.value));\n }\n setTransformConfig(transformData) {\n this.transformConfig = transformData;\n }\n setCanvas(canvas) {\n this.canvas = canvas;\n this.context = canvas.getContext('2d');\n }\n scaleCanvas() {\n this.context.translate(this.transformConfig.transform.x, this.transformConfig.transform.y);\n this.context.scale(this.transformConfig.transform.k, this.transformConfig.transform.k);\n }\n setCanvasDimensions(data) {\n this.canvas.width = data.width;\n this.canvas.height = data.height;\n }\n getCanvasDimensions() {\n return {\n width: this.canvas.width,\n height: this.canvas.height\n };\n }\n clearCanvas() {\n this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);\n }\n drawWafer() {\n this.context.restore();\n this.context.save();\n this.clearCanvas();\n this.scaleCanvas();\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\n const scaledX = this.scaledColumnIndices[i];\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\n continue;\n }\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\n ? this.columnIndicesPositions[i + 1]\n : this.scaledRowIndices.length;\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\n const scaledY = this.scaledRowIndices[columnStartIndex];\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\n continue;\n }\n // Fill style is temporary green for all dies, will be replaced with a color based on the value of the die in a future implementation\n this.context.fillStyle = this.colors[this.colorIndices[columnStartIndex]]\n ?? this.outsideRangeDieColor;\n this.context.fillRect(scaledX, scaledY, this.renderConfig.dieDimensions.width, this.renderConfig.dieDimensions.height);\n }\n }\n }\n drawText() {\n this.context.font = `${this.renderConfig.labelsFontSize.toString()}px sans-serif`;\n this.context.fillStyle = '#ffffff';\n this.context.textAlign = 'center';\n this.context.lineCap = 'butt';\n const approximateTextHeight = this.context.measureText('M');\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\n const scaledX = this.scaledColumnIndices[i];\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\n continue;\n }\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\n ? this.columnIndicesPositions[i + 1]\n : this.scaledRowIndices.length;\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\n const scaledY = this.scaledRowIndices[columnStartIndex];\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\n continue;\n }\n let label = `${this.values[columnStartIndex] || 'NaN'}${this.renderConfig.dieLabelsSuffix}`;\n if (label.length >= this.renderConfig.maxCharacters) {\n label = `${label.substring(0, this.renderConfig.maxCharacters)}\u2026`;\n }\n this.context.fillText(label, scaledX + this.renderConfig.dieDimensions.width / 2, scaledY\n + this.renderConfig.dieDimensions.height / 2\n + approximateTextHeight.width / 2, this.renderConfig.dieDimensions.width * this.fontSizeFactor);\n }\n }\n }\n isDieInGrid(x, y) {\n return (x >= this.renderConfig.gridMinX\n && x <= this.renderConfig.gridMaxX\n && y >= this.renderConfig.gridMinY\n && y <= this.renderConfig.gridMaxY);\n }\n calculateHorizontalScaledIndices(columnIndex) {\n return (this.renderConfig.horizontalCoefficient * columnIndex\n + this.renderConfig.horizontalConstant\n + this.renderConfig.margin.left);\n }\n calculateVerticalScaledIndices(rowIndex) {\n return (this.renderConfig.verticalCoefficient * rowIndex\n + this.renderConfig.verticalConstant\n + this.renderConfig.margin.top);\n }\n findColorIndex(value) {\n let index = -1;\n if (this.colorValues.length === 0 || this.colorValues[0] >= value) {\n return index;\n }\n for (let i = 0; i < this.colorValues.length; i++) {\n if (value <= this.colorValues[i]) {\n index = i;\n break;\n }\n }\n return index;\n }\n }\n expose(MatrixRenderer);\n\n exports.MatrixRenderer = MatrixRenderer;\n\n return exports;\n\n})({});\n";
1
+ export declare const workerCode = "var MatrixRenderer = (function (exports) {\n 'use strict';\n\n /**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n const proxyMarker = Symbol(\"Comlink.proxy\");\n const createEndpoint = Symbol(\"Comlink.endpoint\");\n const releaseProxy = Symbol(\"Comlink.releaseProxy\");\n const finalizer = Symbol(\"Comlink.finalizer\");\n const throwMarker = Symbol(\"Comlink.thrown\");\n const isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n /**\n * Internal transfer handle to handle objects marked to proxy.\n */\n const proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n };\n /**\n * Internal transfer handler to handle thrown exceptions.\n */\n const throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n };\n /**\n * Allows customizing the serialization of certain values.\n */\n const transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n ]);\n function isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n }\n function expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n }\n function isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n }\n function closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n }\n function wrap(ep, target) {\n const pendingListeners = new Map();\n ep.addEventListener(\"message\", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n }\n finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n }\n function throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n }\n function releaseEndpoint(ep) {\n return requestResponseMessage(ep, new Map(), {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n }\n const proxyCounter = new WeakMap();\n const proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\n function registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n }\n function unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n }\n function createProxy(ep, pendingListeners, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously \u00AF\\_(\u30C4)_/\u00AF\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn\u2019t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n }\n function myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n }\n function processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n }\n const transferCache = new WeakMap();\n function transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n }\n function proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n }\n function toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n }\n function fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n }\n function requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n }\n function generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n }\n\n /**\n * MatrixRenderer class is meant to be used within a Web Worker context,\n * using Comlink to facilitate communication between the main thread and the worker.\n * The MatrixRenderer class manages a matrix of dies, once an instance of MatrixRenderer is created,\n * it is exposed to the main thread using Comlink's `expose` method.\n * This setup is used in the wafer-map component to perform heavy computational duties\n */\n class MatrixRenderer {\n constructor() {\n this.values = Float64Array.from([]);\n this.scaledColumnIndices = Float64Array.from([]);\n this.scaledRowIndices = Float64Array.from([]);\n this.columnIndicesPositions = Int32Array.from([]);\n this.colorIndices = Int32Array.from([]);\n this.colors = [];\n this.colorValues = Float64Array.from([]);\n this.outsideRangeDieColor = 'rgba(218,223,236,1)';\n this.fontSizeFactor = 0.8;\n this.renderConfig = {\n dieDimensions: {\n width: 0,\n height: 0\n },\n margin: {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n },\n verticalCoefficient: 1,\n horizontalCoefficient: 1,\n horizontalConstant: 0,\n verticalConstant: 0,\n gridMinX: 0,\n gridMaxX: 0,\n gridMinY: 0,\n gridMaxY: 0,\n labelsFontSize: 0,\n colorScale: [],\n dieLabelsSuffix: '',\n maxCharacters: 0\n };\n this.transformConfig = {\n transform: {\n k: 1,\n x: 0,\n y: 0\n },\n topLeftCanvasCorner: {\n x: 0,\n y: 0\n },\n bottomRightCanvasCorner: {\n x: 0,\n y: 0\n }\n };\n }\n setMatrixData(columnIndices, rowIndices, valuesBuffer) {\n const scaledColumnIndex = [];\n const columnPositions = [];\n const scaledRowIndices = [];\n const values = [];\n const colorIndices = [];\n let prevXIndex;\n let dieCount = 0;\n for (let i = 0; i < columnIndices.length; i++) {\n const xIndex = columnIndices[i];\n const yIndex = rowIndices[i];\n if (this.isDieInGrid(xIndex, yIndex)) {\n if (xIndex !== prevXIndex) {\n scaledColumnIndex.push(this.calculateHorizontalScaledIndices(xIndex));\n columnPositions.push(dieCount);\n prevXIndex = xIndex;\n }\n scaledRowIndices.push(this.calculateVerticalScaledIndices(yIndex));\n const value = valuesBuffer[i];\n values.push(value);\n colorIndices.push(this.findColorIndex(value));\n dieCount += 1;\n }\n }\n this.scaledColumnIndices = Float64Array.from(scaledColumnIndex);\n this.columnIndicesPositions = Int32Array.from(columnPositions);\n this.scaledRowIndices = Float64Array.from(scaledRowIndices);\n this.values = Float64Array.from(values);\n this.colorIndices = Int32Array.from(colorIndices);\n }\n setRenderConfig(renderConfig) {\n this.renderConfig = renderConfig;\n this.colors = renderConfig.colorScale.map(marker => marker.color);\n this.colorValues = Float64Array.from(renderConfig.colorScale.map(marker => marker.value));\n }\n setTransformConfig(transformData) {\n this.transformConfig = transformData;\n }\n setCanvas(canvas) {\n this.canvas = canvas;\n this.context = canvas.getContext('2d');\n }\n scaleCanvas() {\n this.context.translate(this.transformConfig.transform.x, this.transformConfig.transform.y);\n this.context.scale(this.transformConfig.transform.k, this.transformConfig.transform.k);\n }\n setCanvasDimensions(data) {\n this.canvas.width = data.width;\n this.canvas.height = data.height;\n }\n getCanvasDimensions() {\n return {\n width: this.canvas.width,\n height: this.canvas.height\n };\n }\n clearCanvas() {\n this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);\n }\n drawWafer() {\n this.context.restore();\n this.context.save();\n this.clearCanvas();\n this.scaleCanvas();\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\n const scaledX = this.scaledColumnIndices[i];\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\n continue;\n }\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\n ? this.columnIndicesPositions[i + 1]\n : this.scaledRowIndices.length;\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\n const scaledY = this.scaledRowIndices[columnStartIndex];\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\n continue;\n }\n // Fill style is temporary green for all dies, will be replaced with a color based on the value of the die in a future implementation\n this.context.fillStyle = this.colors[this.colorIndices[columnStartIndex]]\n ?? this.outsideRangeDieColor;\n this.context.fillRect(scaledX, scaledY, this.renderConfig.dieDimensions.width, this.renderConfig.dieDimensions.height);\n }\n }\n }\n drawText() {\n this.context.font = `${this.renderConfig.labelsFontSize.toString()}px sans-serif`;\n this.context.fillStyle = '#ffffff';\n this.context.textAlign = 'center';\n this.context.lineCap = 'butt';\n const approximateTextHeight = this.context.measureText('M');\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\n const scaledX = this.scaledColumnIndices[i];\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\n continue;\n }\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\n ? this.columnIndicesPositions[i + 1]\n : this.scaledRowIndices.length;\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\n const scaledY = this.scaledRowIndices[columnStartIndex];\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\n continue;\n }\n let label = `${this.values[columnStartIndex] || 'NaN'}${this.renderConfig.dieLabelsSuffix}`;\n if (label.length >= this.renderConfig.maxCharacters) {\n label = `${label.substring(0, this.renderConfig.maxCharacters)}\u2026`;\n }\n this.context.fillText(label, scaledX + this.renderConfig.dieDimensions.width / 2, scaledY\n + this.renderConfig.dieDimensions.height / 2\n + approximateTextHeight.width / 2, this.renderConfig.dieDimensions.width * this.fontSizeFactor);\n }\n }\n }\n isDieInGrid(x, y) {\n return (x >= this.renderConfig.gridMinX\n && x <= this.renderConfig.gridMaxX\n && y >= this.renderConfig.gridMinY\n && y <= this.renderConfig.gridMaxY);\n }\n calculateHorizontalScaledIndices(columnIndex) {\n return (this.renderConfig.horizontalCoefficient * columnIndex\n + this.renderConfig.horizontalConstant\n + this.renderConfig.margin.left);\n }\n calculateVerticalScaledIndices(rowIndex) {\n return (this.renderConfig.verticalCoefficient * rowIndex\n + this.renderConfig.verticalConstant\n + this.renderConfig.margin.top);\n }\n findColorIndex(value) {\n let index = -1;\n if (this.colorValues.length === 0 || this.colorValues[0] >= value) {\n return index;\n }\n for (let i = 0; i < this.colorValues.length; i++) {\n if (value <= this.colorValues[i]) {\n index = i;\n break;\n }\n }\n return index;\n }\n }\n expose(MatrixRenderer);\n\n exports.MatrixRenderer = MatrixRenderer;\n\n return exports;\n\n})({});\n";
@@ -1,2 +1,2 @@
1
- export const workerCode = "var MatrixRenderer = (function (exports) {\n 'use strict';\n\n /**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n const proxyMarker = Symbol(\"Comlink.proxy\");\n const createEndpoint = Symbol(\"Comlink.endpoint\");\n const releaseProxy = Symbol(\"Comlink.releaseProxy\");\n const finalizer = Symbol(\"Comlink.finalizer\");\n const throwMarker = Symbol(\"Comlink.thrown\");\n const isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n /**\n * Internal transfer handle to handle objects marked to proxy.\n */\n const proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n };\n /**\n * Internal transfer handler to handle thrown exceptions.\n */\n const throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n };\n /**\n * Allows customizing the serialization of certain values.\n */\n const transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n ]);\n function isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n }\n function expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n }\n function isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n }\n function closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n }\n function wrap(ep, target) {\n return createProxy(ep, [], target);\n }\n function throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n }\n function releaseEndpoint(ep) {\n return requestResponseMessage(ep, {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n }\n const proxyCounter = new WeakMap();\n const proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\n function registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n }\n function unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n }\n function createProxy(ep, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n }\n function myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n }\n function processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n }\n const transferCache = new WeakMap();\n function transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n }\n function proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n }\n function toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n }\n function fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n }\n function requestResponseMessage(ep, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n ep.addEventListener(\"message\", function l(ev) {\n if (!ev.data || !ev.data.id || ev.data.id !== id) {\n return;\n }\n ep.removeEventListener(\"message\", l);\n resolve(ev.data);\n });\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n }\n function generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n }\n\n /**\n * MatrixRenderer class is meant to be used within a Web Worker context,\n * using Comlink to facilitate communication between the main thread and the worker.\n * The MatrixRenderer class manages a matrix of dies, once an instance of MatrixRenderer is created,\n * it is exposed to the main thread using Comlink's `expose` method.\n * This setup is used in the wafer-map component to perform heavy computational duties\n */\n class MatrixRenderer {\n constructor() {\n this.values = Float64Array.from([]);\n this.scaledColumnIndices = Float64Array.from([]);\n this.scaledRowIndices = Float64Array.from([]);\n this.columnIndicesPositions = Int32Array.from([]);\n this.colorIndices = Int32Array.from([]);\n this.colors = [];\n this.colorValues = Float64Array.from([]);\n this.outsideRangeDieColor = 'rgba(218,223,236,1)';\n this.fontSizeFactor = 0.8;\n this.renderConfig = {\n dieDimensions: {\n width: 0,\n height: 0\n },\n margin: {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n },\n verticalCoefficient: 1,\n horizontalCoefficient: 1,\n horizontalConstant: 0,\n verticalConstant: 0,\n gridMinX: 0,\n gridMaxX: 0,\n gridMinY: 0,\n gridMaxY: 0,\n labelsFontSize: 0,\n colorScale: [],\n dieLabelsSuffix: '',\n maxCharacters: 0\n };\n this.transformConfig = {\n transform: {\n k: 1,\n x: 0,\n y: 0\n },\n topLeftCanvasCorner: {\n x: 0,\n y: 0\n },\n bottomRightCanvasCorner: {\n x: 0,\n y: 0\n }\n };\n }\n setMatrixData(columnIndices, rowIndices, valuesBuffer) {\n const scaledColumnIndex = [];\n const columnPositions = [];\n const scaledRowIndices = [];\n const values = [];\n const colorIndices = [];\n let prevXIndex;\n let dieCount = 0;\n for (let i = 0; i < columnIndices.length; i++) {\n const xIndex = columnIndices[i];\n const yIndex = rowIndices[i];\n if (this.isDieInGrid(xIndex, yIndex)) {\n if (xIndex !== prevXIndex) {\n scaledColumnIndex.push(this.calculateHorizontalScaledIndices(xIndex));\n columnPositions.push(dieCount);\n prevXIndex = xIndex;\n }\n scaledRowIndices.push(this.calculateVerticalScaledIndices(yIndex));\n const value = valuesBuffer[i];\n values.push(value);\n colorIndices.push(this.findColorIndex(value));\n dieCount += 1;\n }\n }\n this.scaledColumnIndices = Float64Array.from(scaledColumnIndex);\n this.columnIndicesPositions = Int32Array.from(columnPositions);\n this.scaledRowIndices = Float64Array.from(scaledRowIndices);\n this.values = Float64Array.from(values);\n this.colorIndices = Int32Array.from(colorIndices);\n }\n setRenderConfig(renderConfig) {\n this.renderConfig = renderConfig;\n this.colors = renderConfig.colorScale.map(marker => marker.color);\n this.colorValues = Float64Array.from(renderConfig.colorScale.map(marker => marker.value));\n }\n setTransformConfig(transformData) {\n this.transformConfig = transformData;\n }\n setCanvas(canvas) {\n this.canvas = canvas;\n this.context = canvas.getContext('2d');\n }\n scaleCanvas() {\n this.context.translate(this.transformConfig.transform.x, this.transformConfig.transform.y);\n this.context.scale(this.transformConfig.transform.k, this.transformConfig.transform.k);\n }\n setCanvasDimensions(data) {\n this.canvas.width = data.width;\n this.canvas.height = data.height;\n }\n getCanvasDimensions() {\n return {\n width: this.canvas.width,\n height: this.canvas.height\n };\n }\n clearCanvas() {\n this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);\n }\n drawWafer() {\n this.context.restore();\n this.context.save();\n this.clearCanvas();\n this.scaleCanvas();\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\n const scaledX = this.scaledColumnIndices[i];\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\n continue;\n }\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\n ? this.columnIndicesPositions[i + 1]\n : this.scaledRowIndices.length;\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\n const scaledY = this.scaledRowIndices[columnStartIndex];\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\n continue;\n }\n // Fill style is temporary green for all dies, will be replaced with a color based on the value of the die in a future implementation\n this.context.fillStyle = this.colors[this.colorIndices[columnStartIndex]]\n ?? this.outsideRangeDieColor;\n this.context.fillRect(scaledX, scaledY, this.renderConfig.dieDimensions.width, this.renderConfig.dieDimensions.height);\n }\n }\n }\n drawText() {\n this.context.font = `${this.renderConfig.labelsFontSize.toString()}px sans-serif`;\n this.context.fillStyle = '#ffffff';\n this.context.textAlign = 'center';\n this.context.lineCap = 'butt';\n const approximateTextHeight = this.context.measureText('M');\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\n const scaledX = this.scaledColumnIndices[i];\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\n continue;\n }\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\n ? this.columnIndicesPositions[i + 1]\n : this.scaledRowIndices.length;\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\n const scaledY = this.scaledRowIndices[columnStartIndex];\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\n continue;\n }\n let label = `${this.values[columnStartIndex] || 'NaN'}${this.renderConfig.dieLabelsSuffix}`;\n if (label.length >= this.renderConfig.maxCharacters) {\n label = `${label.substring(0, this.renderConfig.maxCharacters)}…`;\n }\n this.context.fillText(label, scaledX + this.renderConfig.dieDimensions.width / 2, scaledY\n + this.renderConfig.dieDimensions.height / 2\n + approximateTextHeight.width / 2, this.renderConfig.dieDimensions.width * this.fontSizeFactor);\n }\n }\n }\n isDieInGrid(x, y) {\n return (x >= this.renderConfig.gridMinX\n && x <= this.renderConfig.gridMaxX\n && y >= this.renderConfig.gridMinY\n && y <= this.renderConfig.gridMaxY);\n }\n calculateHorizontalScaledIndices(columnIndex) {\n return (this.renderConfig.horizontalCoefficient * columnIndex\n + this.renderConfig.horizontalConstant\n + this.renderConfig.margin.left);\n }\n calculateVerticalScaledIndices(rowIndex) {\n return (this.renderConfig.verticalCoefficient * rowIndex\n + this.renderConfig.verticalConstant\n + this.renderConfig.margin.top);\n }\n findColorIndex(value) {\n let index = -1;\n if (this.colorValues.length === 0 || this.colorValues[0] >= value) {\n return index;\n }\n for (let i = 0; i < this.colorValues.length; i++) {\n if (value <= this.colorValues[i]) {\n index = i;\n break;\n }\n }\n return index;\n }\n }\n expose(MatrixRenderer);\n\n exports.MatrixRenderer = MatrixRenderer;\n\n return exports;\n\n})({});\n";
1
+ export const workerCode = "var MatrixRenderer = (function (exports) {\n 'use strict';\n\n /**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n const proxyMarker = Symbol(\"Comlink.proxy\");\n const createEndpoint = Symbol(\"Comlink.endpoint\");\n const releaseProxy = Symbol(\"Comlink.releaseProxy\");\n const finalizer = Symbol(\"Comlink.finalizer\");\n const throwMarker = Symbol(\"Comlink.thrown\");\n const isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n /**\n * Internal transfer handle to handle objects marked to proxy.\n */\n const proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n };\n /**\n * Internal transfer handler to handle thrown exceptions.\n */\n const throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n };\n /**\n * Allows customizing the serialization of certain values.\n */\n const transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n ]);\n function isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n }\n function expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n }\n function isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n }\n function closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n }\n function wrap(ep, target) {\n const pendingListeners = new Map();\n ep.addEventListener(\"message\", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n }\n finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n }\n function throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n }\n function releaseEndpoint(ep) {\n return requestResponseMessage(ep, new Map(), {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n }\n const proxyCounter = new WeakMap();\n const proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\n function registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n }\n function unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n }\n function createProxy(ep, pendingListeners, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n }\n function myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n }\n function processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n }\n const transferCache = new WeakMap();\n function transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n }\n function proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n }\n function toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n }\n function fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n }\n function requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n }\n function generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n }\n\n /**\n * MatrixRenderer class is meant to be used within a Web Worker context,\n * using Comlink to facilitate communication between the main thread and the worker.\n * The MatrixRenderer class manages a matrix of dies, once an instance of MatrixRenderer is created,\n * it is exposed to the main thread using Comlink's `expose` method.\n * This setup is used in the wafer-map component to perform heavy computational duties\n */\n class MatrixRenderer {\n constructor() {\n this.values = Float64Array.from([]);\n this.scaledColumnIndices = Float64Array.from([]);\n this.scaledRowIndices = Float64Array.from([]);\n this.columnIndicesPositions = Int32Array.from([]);\n this.colorIndices = Int32Array.from([]);\n this.colors = [];\n this.colorValues = Float64Array.from([]);\n this.outsideRangeDieColor = 'rgba(218,223,236,1)';\n this.fontSizeFactor = 0.8;\n this.renderConfig = {\n dieDimensions: {\n width: 0,\n height: 0\n },\n margin: {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n },\n verticalCoefficient: 1,\n horizontalCoefficient: 1,\n horizontalConstant: 0,\n verticalConstant: 0,\n gridMinX: 0,\n gridMaxX: 0,\n gridMinY: 0,\n gridMaxY: 0,\n labelsFontSize: 0,\n colorScale: [],\n dieLabelsSuffix: '',\n maxCharacters: 0\n };\n this.transformConfig = {\n transform: {\n k: 1,\n x: 0,\n y: 0\n },\n topLeftCanvasCorner: {\n x: 0,\n y: 0\n },\n bottomRightCanvasCorner: {\n x: 0,\n y: 0\n }\n };\n }\n setMatrixData(columnIndices, rowIndices, valuesBuffer) {\n const scaledColumnIndex = [];\n const columnPositions = [];\n const scaledRowIndices = [];\n const values = [];\n const colorIndices = [];\n let prevXIndex;\n let dieCount = 0;\n for (let i = 0; i < columnIndices.length; i++) {\n const xIndex = columnIndices[i];\n const yIndex = rowIndices[i];\n if (this.isDieInGrid(xIndex, yIndex)) {\n if (xIndex !== prevXIndex) {\n scaledColumnIndex.push(this.calculateHorizontalScaledIndices(xIndex));\n columnPositions.push(dieCount);\n prevXIndex = xIndex;\n }\n scaledRowIndices.push(this.calculateVerticalScaledIndices(yIndex));\n const value = valuesBuffer[i];\n values.push(value);\n colorIndices.push(this.findColorIndex(value));\n dieCount += 1;\n }\n }\n this.scaledColumnIndices = Float64Array.from(scaledColumnIndex);\n this.columnIndicesPositions = Int32Array.from(columnPositions);\n this.scaledRowIndices = Float64Array.from(scaledRowIndices);\n this.values = Float64Array.from(values);\n this.colorIndices = Int32Array.from(colorIndices);\n }\n setRenderConfig(renderConfig) {\n this.renderConfig = renderConfig;\n this.colors = renderConfig.colorScale.map(marker => marker.color);\n this.colorValues = Float64Array.from(renderConfig.colorScale.map(marker => marker.value));\n }\n setTransformConfig(transformData) {\n this.transformConfig = transformData;\n }\n setCanvas(canvas) {\n this.canvas = canvas;\n this.context = canvas.getContext('2d');\n }\n scaleCanvas() {\n this.context.translate(this.transformConfig.transform.x, this.transformConfig.transform.y);\n this.context.scale(this.transformConfig.transform.k, this.transformConfig.transform.k);\n }\n setCanvasDimensions(data) {\n this.canvas.width = data.width;\n this.canvas.height = data.height;\n }\n getCanvasDimensions() {\n return {\n width: this.canvas.width,\n height: this.canvas.height\n };\n }\n clearCanvas() {\n this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);\n }\n drawWafer() {\n this.context.restore();\n this.context.save();\n this.clearCanvas();\n this.scaleCanvas();\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\n const scaledX = this.scaledColumnIndices[i];\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\n continue;\n }\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\n ? this.columnIndicesPositions[i + 1]\n : this.scaledRowIndices.length;\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\n const scaledY = this.scaledRowIndices[columnStartIndex];\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\n continue;\n }\n // Fill style is temporary green for all dies, will be replaced with a color based on the value of the die in a future implementation\n this.context.fillStyle = this.colors[this.colorIndices[columnStartIndex]]\n ?? this.outsideRangeDieColor;\n this.context.fillRect(scaledX, scaledY, this.renderConfig.dieDimensions.width, this.renderConfig.dieDimensions.height);\n }\n }\n }\n drawText() {\n this.context.font = `${this.renderConfig.labelsFontSize.toString()}px sans-serif`;\n this.context.fillStyle = '#ffffff';\n this.context.textAlign = 'center';\n this.context.lineCap = 'butt';\n const approximateTextHeight = this.context.measureText('M');\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\n const scaledX = this.scaledColumnIndices[i];\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\n continue;\n }\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\n ? this.columnIndicesPositions[i + 1]\n : this.scaledRowIndices.length;\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\n const scaledY = this.scaledRowIndices[columnStartIndex];\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\n continue;\n }\n let label = `${this.values[columnStartIndex] || 'NaN'}${this.renderConfig.dieLabelsSuffix}`;\n if (label.length >= this.renderConfig.maxCharacters) {\n label = `${label.substring(0, this.renderConfig.maxCharacters)}…`;\n }\n this.context.fillText(label, scaledX + this.renderConfig.dieDimensions.width / 2, scaledY\n + this.renderConfig.dieDimensions.height / 2\n + approximateTextHeight.width / 2, this.renderConfig.dieDimensions.width * this.fontSizeFactor);\n }\n }\n }\n isDieInGrid(x, y) {\n return (x >= this.renderConfig.gridMinX\n && x <= this.renderConfig.gridMaxX\n && y >= this.renderConfig.gridMinY\n && y <= this.renderConfig.gridMaxY);\n }\n calculateHorizontalScaledIndices(columnIndex) {\n return (this.renderConfig.horizontalCoefficient * columnIndex\n + this.renderConfig.horizontalConstant\n + this.renderConfig.margin.left);\n }\n calculateVerticalScaledIndices(rowIndex) {\n return (this.renderConfig.verticalCoefficient * rowIndex\n + this.renderConfig.verticalConstant\n + this.renderConfig.margin.top);\n }\n findColorIndex(value) {\n let index = -1;\n if (this.colorValues.length === 0 || this.colorValues[0] >= value) {\n return index;\n }\n for (let i = 0; i < this.colorValues.length; i++) {\n if (value <= this.colorValues[i]) {\n index = i;\n break;\n }\n }\n return index;\n }\n }\n expose(MatrixRenderer);\n\n exports.MatrixRenderer = MatrixRenderer;\n\n return exports;\n\n})({});\n";
2
2
  //# sourceMappingURL=worker-code.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-code.js","sourceRoot":"","sources":["../../../../src/wafer-map/workers/worker-code.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,2qvBAA2qvB,CAAC","sourcesContent":["export const workerCode = \"var MatrixRenderer = (function (exports) {\\n 'use strict';\\n\\n /**\\n * @license\\n * Copyright 2019 Google LLC\\n * SPDX-License-Identifier: Apache-2.0\\n */\\n const proxyMarker = Symbol(\\\"Comlink.proxy\\\");\\n const createEndpoint = Symbol(\\\"Comlink.endpoint\\\");\\n const releaseProxy = Symbol(\\\"Comlink.releaseProxy\\\");\\n const finalizer = Symbol(\\\"Comlink.finalizer\\\");\\n const throwMarker = Symbol(\\\"Comlink.thrown\\\");\\n const isObject = (val) => (typeof val === \\\"object\\\" && val !== null) || typeof val === \\\"function\\\";\\n /**\\n * Internal transfer handle to handle objects marked to proxy.\\n */\\n const proxyTransferHandler = {\\n canHandle: (val) => isObject(val) && val[proxyMarker],\\n serialize(obj) {\\n const { port1, port2 } = new MessageChannel();\\n expose(obj, port1);\\n return [port2, [port2]];\\n },\\n deserialize(port) {\\n port.start();\\n return wrap(port);\\n },\\n };\\n /**\\n * Internal transfer handler to handle thrown exceptions.\\n */\\n const throwTransferHandler = {\\n canHandle: (value) => isObject(value) && throwMarker in value,\\n serialize({ value }) {\\n let serialized;\\n if (value instanceof Error) {\\n serialized = {\\n isError: true,\\n value: {\\n message: value.message,\\n name: value.name,\\n stack: value.stack,\\n },\\n };\\n }\\n else {\\n serialized = { isError: false, value };\\n }\\n return [serialized, []];\\n },\\n deserialize(serialized) {\\n if (serialized.isError) {\\n throw Object.assign(new Error(serialized.value.message), serialized.value);\\n }\\n throw serialized.value;\\n },\\n };\\n /**\\n * Allows customizing the serialization of certain values.\\n */\\n const transferHandlers = new Map([\\n [\\\"proxy\\\", proxyTransferHandler],\\n [\\\"throw\\\", throwTransferHandler],\\n ]);\\n function isAllowedOrigin(allowedOrigins, origin) {\\n for (const allowedOrigin of allowedOrigins) {\\n if (origin === allowedOrigin || allowedOrigin === \\\"*\\\") {\\n return true;\\n }\\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\\n return true;\\n }\\n }\\n return false;\\n }\\n function expose(obj, ep = globalThis, allowedOrigins = [\\\"*\\\"]) {\\n ep.addEventListener(\\\"message\\\", function callback(ev) {\\n if (!ev || !ev.data) {\\n return;\\n }\\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\\n return;\\n }\\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\\n let returnValue;\\n try {\\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\\n switch (type) {\\n case \\\"GET\\\" /* MessageType.GET */:\\n {\\n returnValue = rawValue;\\n }\\n break;\\n case \\\"SET\\\" /* MessageType.SET */:\\n {\\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\\n returnValue = true;\\n }\\n break;\\n case \\\"APPLY\\\" /* MessageType.APPLY */:\\n {\\n returnValue = rawValue.apply(parent, argumentList);\\n }\\n break;\\n case \\\"CONSTRUCT\\\" /* MessageType.CONSTRUCT */:\\n {\\n const value = new rawValue(...argumentList);\\n returnValue = proxy(value);\\n }\\n break;\\n case \\\"ENDPOINT\\\" /* MessageType.ENDPOINT */:\\n {\\n const { port1, port2 } = new MessageChannel();\\n expose(obj, port2);\\n returnValue = transfer(port1, [port1]);\\n }\\n break;\\n case \\\"RELEASE\\\" /* MessageType.RELEASE */:\\n {\\n returnValue = undefined;\\n }\\n break;\\n default:\\n return;\\n }\\n }\\n catch (value) {\\n returnValue = { value, [throwMarker]: 0 };\\n }\\n Promise.resolve(returnValue)\\n .catch((value) => {\\n return { value, [throwMarker]: 0 };\\n })\\n .then((returnValue) => {\\n const [wireValue, transferables] = toWireValue(returnValue);\\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\\n if (type === \\\"RELEASE\\\" /* MessageType.RELEASE */) {\\n // detach and deactive after sending release response above.\\n ep.removeEventListener(\\\"message\\\", callback);\\n closeEndPoint(ep);\\n if (finalizer in obj && typeof obj[finalizer] === \\\"function\\\") {\\n obj[finalizer]();\\n }\\n }\\n })\\n .catch((error) => {\\n // Send Serialization Error To Caller\\n const [wireValue, transferables] = toWireValue({\\n value: new TypeError(\\\"Unserializable return value\\\"),\\n [throwMarker]: 0,\\n });\\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\\n });\\n });\\n if (ep.start) {\\n ep.start();\\n }\\n }\\n function isMessagePort(endpoint) {\\n return endpoint.constructor.name === \\\"MessagePort\\\";\\n }\\n function closeEndPoint(endpoint) {\\n if (isMessagePort(endpoint))\\n endpoint.close();\\n }\\n function wrap(ep, target) {\\n return createProxy(ep, [], target);\\n }\\n function throwIfProxyReleased(isReleased) {\\n if (isReleased) {\\n throw new Error(\\\"Proxy has been released and is not useable\\\");\\n }\\n }\\n function releaseEndpoint(ep) {\\n return requestResponseMessage(ep, {\\n type: \\\"RELEASE\\\" /* MessageType.RELEASE */,\\n }).then(() => {\\n closeEndPoint(ep);\\n });\\n }\\n const proxyCounter = new WeakMap();\\n const proxyFinalizers = \\\"FinalizationRegistry\\\" in globalThis &&\\n new FinalizationRegistry((ep) => {\\n const newCount = (proxyCounter.get(ep) || 0) - 1;\\n proxyCounter.set(ep, newCount);\\n if (newCount === 0) {\\n releaseEndpoint(ep);\\n }\\n });\\n function registerProxy(proxy, ep) {\\n const newCount = (proxyCounter.get(ep) || 0) + 1;\\n proxyCounter.set(ep, newCount);\\n if (proxyFinalizers) {\\n proxyFinalizers.register(proxy, ep, proxy);\\n }\\n }\\n function unregisterProxy(proxy) {\\n if (proxyFinalizers) {\\n proxyFinalizers.unregister(proxy);\\n }\\n }\\n function createProxy(ep, path = [], target = function () { }) {\\n let isProxyReleased = false;\\n const proxy = new Proxy(target, {\\n get(_target, prop) {\\n throwIfProxyReleased(isProxyReleased);\\n if (prop === releaseProxy) {\\n return () => {\\n unregisterProxy(proxy);\\n releaseEndpoint(ep);\\n isProxyReleased = true;\\n };\\n }\\n if (prop === \\\"then\\\") {\\n if (path.length === 0) {\\n return { then: () => proxy };\\n }\\n const r = requestResponseMessage(ep, {\\n type: \\\"GET\\\" /* MessageType.GET */,\\n path: path.map((p) => p.toString()),\\n }).then(fromWireValue);\\n return r.then.bind(r);\\n }\\n return createProxy(ep, [...path, prop]);\\n },\\n set(_target, prop, rawValue) {\\n throwIfProxyReleased(isProxyReleased);\\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\\n // boolean. To show good will, we return true asynchronously ¯\\\\_(ツ)_/¯\\n const [value, transferables] = toWireValue(rawValue);\\n return requestResponseMessage(ep, {\\n type: \\\"SET\\\" /* MessageType.SET */,\\n path: [...path, prop].map((p) => p.toString()),\\n value,\\n }, transferables).then(fromWireValue);\\n },\\n apply(_target, _thisArg, rawArgumentList) {\\n throwIfProxyReleased(isProxyReleased);\\n const last = path[path.length - 1];\\n if (last === createEndpoint) {\\n return requestResponseMessage(ep, {\\n type: \\\"ENDPOINT\\\" /* MessageType.ENDPOINT */,\\n }).then(fromWireValue);\\n }\\n // We just pretend that `bind()` didn’t happen.\\n if (last === \\\"bind\\\") {\\n return createProxy(ep, path.slice(0, -1));\\n }\\n const [argumentList, transferables] = processArguments(rawArgumentList);\\n return requestResponseMessage(ep, {\\n type: \\\"APPLY\\\" /* MessageType.APPLY */,\\n path: path.map((p) => p.toString()),\\n argumentList,\\n }, transferables).then(fromWireValue);\\n },\\n construct(_target, rawArgumentList) {\\n throwIfProxyReleased(isProxyReleased);\\n const [argumentList, transferables] = processArguments(rawArgumentList);\\n return requestResponseMessage(ep, {\\n type: \\\"CONSTRUCT\\\" /* MessageType.CONSTRUCT */,\\n path: path.map((p) => p.toString()),\\n argumentList,\\n }, transferables).then(fromWireValue);\\n },\\n });\\n registerProxy(proxy, ep);\\n return proxy;\\n }\\n function myFlat(arr) {\\n return Array.prototype.concat.apply([], arr);\\n }\\n function processArguments(argumentList) {\\n const processed = argumentList.map(toWireValue);\\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\\n }\\n const transferCache = new WeakMap();\\n function transfer(obj, transfers) {\\n transferCache.set(obj, transfers);\\n return obj;\\n }\\n function proxy(obj) {\\n return Object.assign(obj, { [proxyMarker]: true });\\n }\\n function toWireValue(value) {\\n for (const [name, handler] of transferHandlers) {\\n if (handler.canHandle(value)) {\\n const [serializedValue, transferables] = handler.serialize(value);\\n return [\\n {\\n type: \\\"HANDLER\\\" /* WireValueType.HANDLER */,\\n name,\\n value: serializedValue,\\n },\\n transferables,\\n ];\\n }\\n }\\n return [\\n {\\n type: \\\"RAW\\\" /* WireValueType.RAW */,\\n value,\\n },\\n transferCache.get(value) || [],\\n ];\\n }\\n function fromWireValue(value) {\\n switch (value.type) {\\n case \\\"HANDLER\\\" /* WireValueType.HANDLER */:\\n return transferHandlers.get(value.name).deserialize(value.value);\\n case \\\"RAW\\\" /* WireValueType.RAW */:\\n return value.value;\\n }\\n }\\n function requestResponseMessage(ep, msg, transfers) {\\n return new Promise((resolve) => {\\n const id = generateUUID();\\n ep.addEventListener(\\\"message\\\", function l(ev) {\\n if (!ev.data || !ev.data.id || ev.data.id !== id) {\\n return;\\n }\\n ep.removeEventListener(\\\"message\\\", l);\\n resolve(ev.data);\\n });\\n if (ep.start) {\\n ep.start();\\n }\\n ep.postMessage(Object.assign({ id }, msg), transfers);\\n });\\n }\\n function generateUUID() {\\n return new Array(4)\\n .fill(0)\\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\\n .join(\\\"-\\\");\\n }\\n\\n /**\\n * MatrixRenderer class is meant to be used within a Web Worker context,\\n * using Comlink to facilitate communication between the main thread and the worker.\\n * The MatrixRenderer class manages a matrix of dies, once an instance of MatrixRenderer is created,\\n * it is exposed to the main thread using Comlink's `expose` method.\\n * This setup is used in the wafer-map component to perform heavy computational duties\\n */\\n class MatrixRenderer {\\n constructor() {\\n this.values = Float64Array.from([]);\\n this.scaledColumnIndices = Float64Array.from([]);\\n this.scaledRowIndices = Float64Array.from([]);\\n this.columnIndicesPositions = Int32Array.from([]);\\n this.colorIndices = Int32Array.from([]);\\n this.colors = [];\\n this.colorValues = Float64Array.from([]);\\n this.outsideRangeDieColor = 'rgba(218,223,236,1)';\\n this.fontSizeFactor = 0.8;\\n this.renderConfig = {\\n dieDimensions: {\\n width: 0,\\n height: 0\\n },\\n margin: {\\n top: 0,\\n right: 0,\\n bottom: 0,\\n left: 0\\n },\\n verticalCoefficient: 1,\\n horizontalCoefficient: 1,\\n horizontalConstant: 0,\\n verticalConstant: 0,\\n gridMinX: 0,\\n gridMaxX: 0,\\n gridMinY: 0,\\n gridMaxY: 0,\\n labelsFontSize: 0,\\n colorScale: [],\\n dieLabelsSuffix: '',\\n maxCharacters: 0\\n };\\n this.transformConfig = {\\n transform: {\\n k: 1,\\n x: 0,\\n y: 0\\n },\\n topLeftCanvasCorner: {\\n x: 0,\\n y: 0\\n },\\n bottomRightCanvasCorner: {\\n x: 0,\\n y: 0\\n }\\n };\\n }\\n setMatrixData(columnIndices, rowIndices, valuesBuffer) {\\n const scaledColumnIndex = [];\\n const columnPositions = [];\\n const scaledRowIndices = [];\\n const values = [];\\n const colorIndices = [];\\n let prevXIndex;\\n let dieCount = 0;\\n for (let i = 0; i < columnIndices.length; i++) {\\n const xIndex = columnIndices[i];\\n const yIndex = rowIndices[i];\\n if (this.isDieInGrid(xIndex, yIndex)) {\\n if (xIndex !== prevXIndex) {\\n scaledColumnIndex.push(this.calculateHorizontalScaledIndices(xIndex));\\n columnPositions.push(dieCount);\\n prevXIndex = xIndex;\\n }\\n scaledRowIndices.push(this.calculateVerticalScaledIndices(yIndex));\\n const value = valuesBuffer[i];\\n values.push(value);\\n colorIndices.push(this.findColorIndex(value));\\n dieCount += 1;\\n }\\n }\\n this.scaledColumnIndices = Float64Array.from(scaledColumnIndex);\\n this.columnIndicesPositions = Int32Array.from(columnPositions);\\n this.scaledRowIndices = Float64Array.from(scaledRowIndices);\\n this.values = Float64Array.from(values);\\n this.colorIndices = Int32Array.from(colorIndices);\\n }\\n setRenderConfig(renderConfig) {\\n this.renderConfig = renderConfig;\\n this.colors = renderConfig.colorScale.map(marker => marker.color);\\n this.colorValues = Float64Array.from(renderConfig.colorScale.map(marker => marker.value));\\n }\\n setTransformConfig(transformData) {\\n this.transformConfig = transformData;\\n }\\n setCanvas(canvas) {\\n this.canvas = canvas;\\n this.context = canvas.getContext('2d');\\n }\\n scaleCanvas() {\\n this.context.translate(this.transformConfig.transform.x, this.transformConfig.transform.y);\\n this.context.scale(this.transformConfig.transform.k, this.transformConfig.transform.k);\\n }\\n setCanvasDimensions(data) {\\n this.canvas.width = data.width;\\n this.canvas.height = data.height;\\n }\\n getCanvasDimensions() {\\n return {\\n width: this.canvas.width,\\n height: this.canvas.height\\n };\\n }\\n clearCanvas() {\\n this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);\\n }\\n drawWafer() {\\n this.context.restore();\\n this.context.save();\\n this.clearCanvas();\\n this.scaleCanvas();\\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\\n const scaledX = this.scaledColumnIndices[i];\\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\\n continue;\\n }\\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\\n ? this.columnIndicesPositions[i + 1]\\n : this.scaledRowIndices.length;\\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\\n const scaledY = this.scaledRowIndices[columnStartIndex];\\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\\n continue;\\n }\\n // Fill style is temporary green for all dies, will be replaced with a color based on the value of the die in a future implementation\\n this.context.fillStyle = this.colors[this.colorIndices[columnStartIndex]]\\n ?? this.outsideRangeDieColor;\\n this.context.fillRect(scaledX, scaledY, this.renderConfig.dieDimensions.width, this.renderConfig.dieDimensions.height);\\n }\\n }\\n }\\n drawText() {\\n this.context.font = `${this.renderConfig.labelsFontSize.toString()}px sans-serif`;\\n this.context.fillStyle = '#ffffff';\\n this.context.textAlign = 'center';\\n this.context.lineCap = 'butt';\\n const approximateTextHeight = this.context.measureText('M');\\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\\n const scaledX = this.scaledColumnIndices[i];\\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\\n continue;\\n }\\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\\n ? this.columnIndicesPositions[i + 1]\\n : this.scaledRowIndices.length;\\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\\n const scaledY = this.scaledRowIndices[columnStartIndex];\\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\\n continue;\\n }\\n let label = `${this.values[columnStartIndex] || 'NaN'}${this.renderConfig.dieLabelsSuffix}`;\\n if (label.length >= this.renderConfig.maxCharacters) {\\n label = `${label.substring(0, this.renderConfig.maxCharacters)}…`;\\n }\\n this.context.fillText(label, scaledX + this.renderConfig.dieDimensions.width / 2, scaledY\\n + this.renderConfig.dieDimensions.height / 2\\n + approximateTextHeight.width / 2, this.renderConfig.dieDimensions.width * this.fontSizeFactor);\\n }\\n }\\n }\\n isDieInGrid(x, y) {\\n return (x >= this.renderConfig.gridMinX\\n && x <= this.renderConfig.gridMaxX\\n && y >= this.renderConfig.gridMinY\\n && y <= this.renderConfig.gridMaxY);\\n }\\n calculateHorizontalScaledIndices(columnIndex) {\\n return (this.renderConfig.horizontalCoefficient * columnIndex\\n + this.renderConfig.horizontalConstant\\n + this.renderConfig.margin.left);\\n }\\n calculateVerticalScaledIndices(rowIndex) {\\n return (this.renderConfig.verticalCoefficient * rowIndex\\n + this.renderConfig.verticalConstant\\n + this.renderConfig.margin.top);\\n }\\n findColorIndex(value) {\\n let index = -1;\\n if (this.colorValues.length === 0 || this.colorValues[0] >= value) {\\n return index;\\n }\\n for (let i = 0; i < this.colorValues.length; i++) {\\n if (value <= this.colorValues[i]) {\\n index = i;\\n break;\\n }\\n }\\n return index;\\n }\\n }\\n expose(MatrixRenderer);\\n\\n exports.MatrixRenderer = MatrixRenderer;\\n\\n return exports;\\n\\n})({});\\n\";"]}
1
+ {"version":3,"file":"worker-code.js","sourceRoot":"","sources":["../../../../src/wafer-map/workers/worker-code.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,4rwBAA4rwB,CAAC","sourcesContent":["export const workerCode = \"var MatrixRenderer = (function (exports) {\\n 'use strict';\\n\\n /**\\n * @license\\n * Copyright 2019 Google LLC\\n * SPDX-License-Identifier: Apache-2.0\\n */\\n const proxyMarker = Symbol(\\\"Comlink.proxy\\\");\\n const createEndpoint = Symbol(\\\"Comlink.endpoint\\\");\\n const releaseProxy = Symbol(\\\"Comlink.releaseProxy\\\");\\n const finalizer = Symbol(\\\"Comlink.finalizer\\\");\\n const throwMarker = Symbol(\\\"Comlink.thrown\\\");\\n const isObject = (val) => (typeof val === \\\"object\\\" && val !== null) || typeof val === \\\"function\\\";\\n /**\\n * Internal transfer handle to handle objects marked to proxy.\\n */\\n const proxyTransferHandler = {\\n canHandle: (val) => isObject(val) && val[proxyMarker],\\n serialize(obj) {\\n const { port1, port2 } = new MessageChannel();\\n expose(obj, port1);\\n return [port2, [port2]];\\n },\\n deserialize(port) {\\n port.start();\\n return wrap(port);\\n },\\n };\\n /**\\n * Internal transfer handler to handle thrown exceptions.\\n */\\n const throwTransferHandler = {\\n canHandle: (value) => isObject(value) && throwMarker in value,\\n serialize({ value }) {\\n let serialized;\\n if (value instanceof Error) {\\n serialized = {\\n isError: true,\\n value: {\\n message: value.message,\\n name: value.name,\\n stack: value.stack,\\n },\\n };\\n }\\n else {\\n serialized = { isError: false, value };\\n }\\n return [serialized, []];\\n },\\n deserialize(serialized) {\\n if (serialized.isError) {\\n throw Object.assign(new Error(serialized.value.message), serialized.value);\\n }\\n throw serialized.value;\\n },\\n };\\n /**\\n * Allows customizing the serialization of certain values.\\n */\\n const transferHandlers = new Map([\\n [\\\"proxy\\\", proxyTransferHandler],\\n [\\\"throw\\\", throwTransferHandler],\\n ]);\\n function isAllowedOrigin(allowedOrigins, origin) {\\n for (const allowedOrigin of allowedOrigins) {\\n if (origin === allowedOrigin || allowedOrigin === \\\"*\\\") {\\n return true;\\n }\\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\\n return true;\\n }\\n }\\n return false;\\n }\\n function expose(obj, ep = globalThis, allowedOrigins = [\\\"*\\\"]) {\\n ep.addEventListener(\\\"message\\\", function callback(ev) {\\n if (!ev || !ev.data) {\\n return;\\n }\\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\\n return;\\n }\\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\\n let returnValue;\\n try {\\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\\n switch (type) {\\n case \\\"GET\\\" /* MessageType.GET */:\\n {\\n returnValue = rawValue;\\n }\\n break;\\n case \\\"SET\\\" /* MessageType.SET */:\\n {\\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\\n returnValue = true;\\n }\\n break;\\n case \\\"APPLY\\\" /* MessageType.APPLY */:\\n {\\n returnValue = rawValue.apply(parent, argumentList);\\n }\\n break;\\n case \\\"CONSTRUCT\\\" /* MessageType.CONSTRUCT */:\\n {\\n const value = new rawValue(...argumentList);\\n returnValue = proxy(value);\\n }\\n break;\\n case \\\"ENDPOINT\\\" /* MessageType.ENDPOINT */:\\n {\\n const { port1, port2 } = new MessageChannel();\\n expose(obj, port2);\\n returnValue = transfer(port1, [port1]);\\n }\\n break;\\n case \\\"RELEASE\\\" /* MessageType.RELEASE */:\\n {\\n returnValue = undefined;\\n }\\n break;\\n default:\\n return;\\n }\\n }\\n catch (value) {\\n returnValue = { value, [throwMarker]: 0 };\\n }\\n Promise.resolve(returnValue)\\n .catch((value) => {\\n return { value, [throwMarker]: 0 };\\n })\\n .then((returnValue) => {\\n const [wireValue, transferables] = toWireValue(returnValue);\\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\\n if (type === \\\"RELEASE\\\" /* MessageType.RELEASE */) {\\n // detach and deactive after sending release response above.\\n ep.removeEventListener(\\\"message\\\", callback);\\n closeEndPoint(ep);\\n if (finalizer in obj && typeof obj[finalizer] === \\\"function\\\") {\\n obj[finalizer]();\\n }\\n }\\n })\\n .catch((error) => {\\n // Send Serialization Error To Caller\\n const [wireValue, transferables] = toWireValue({\\n value: new TypeError(\\\"Unserializable return value\\\"),\\n [throwMarker]: 0,\\n });\\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\\n });\\n });\\n if (ep.start) {\\n ep.start();\\n }\\n }\\n function isMessagePort(endpoint) {\\n return endpoint.constructor.name === \\\"MessagePort\\\";\\n }\\n function closeEndPoint(endpoint) {\\n if (isMessagePort(endpoint))\\n endpoint.close();\\n }\\n function wrap(ep, target) {\\n const pendingListeners = new Map();\\n ep.addEventListener(\\\"message\\\", function handleMessage(ev) {\\n const { data } = ev;\\n if (!data || !data.id) {\\n return;\\n }\\n const resolver = pendingListeners.get(data.id);\\n if (!resolver) {\\n return;\\n }\\n try {\\n resolver(data);\\n }\\n finally {\\n pendingListeners.delete(data.id);\\n }\\n });\\n return createProxy(ep, pendingListeners, [], target);\\n }\\n function throwIfProxyReleased(isReleased) {\\n if (isReleased) {\\n throw new Error(\\\"Proxy has been released and is not useable\\\");\\n }\\n }\\n function releaseEndpoint(ep) {\\n return requestResponseMessage(ep, new Map(), {\\n type: \\\"RELEASE\\\" /* MessageType.RELEASE */,\\n }).then(() => {\\n closeEndPoint(ep);\\n });\\n }\\n const proxyCounter = new WeakMap();\\n const proxyFinalizers = \\\"FinalizationRegistry\\\" in globalThis &&\\n new FinalizationRegistry((ep) => {\\n const newCount = (proxyCounter.get(ep) || 0) - 1;\\n proxyCounter.set(ep, newCount);\\n if (newCount === 0) {\\n releaseEndpoint(ep);\\n }\\n });\\n function registerProxy(proxy, ep) {\\n const newCount = (proxyCounter.get(ep) || 0) + 1;\\n proxyCounter.set(ep, newCount);\\n if (proxyFinalizers) {\\n proxyFinalizers.register(proxy, ep, proxy);\\n }\\n }\\n function unregisterProxy(proxy) {\\n if (proxyFinalizers) {\\n proxyFinalizers.unregister(proxy);\\n }\\n }\\n function createProxy(ep, pendingListeners, path = [], target = function () { }) {\\n let isProxyReleased = false;\\n const proxy = new Proxy(target, {\\n get(_target, prop) {\\n throwIfProxyReleased(isProxyReleased);\\n if (prop === releaseProxy) {\\n return () => {\\n unregisterProxy(proxy);\\n releaseEndpoint(ep);\\n pendingListeners.clear();\\n isProxyReleased = true;\\n };\\n }\\n if (prop === \\\"then\\\") {\\n if (path.length === 0) {\\n return { then: () => proxy };\\n }\\n const r = requestResponseMessage(ep, pendingListeners, {\\n type: \\\"GET\\\" /* MessageType.GET */,\\n path: path.map((p) => p.toString()),\\n }).then(fromWireValue);\\n return r.then.bind(r);\\n }\\n return createProxy(ep, pendingListeners, [...path, prop]);\\n },\\n set(_target, prop, rawValue) {\\n throwIfProxyReleased(isProxyReleased);\\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\\n // boolean. To show good will, we return true asynchronously ¯\\\\_(ツ)_/¯\\n const [value, transferables] = toWireValue(rawValue);\\n return requestResponseMessage(ep, pendingListeners, {\\n type: \\\"SET\\\" /* MessageType.SET */,\\n path: [...path, prop].map((p) => p.toString()),\\n value,\\n }, transferables).then(fromWireValue);\\n },\\n apply(_target, _thisArg, rawArgumentList) {\\n throwIfProxyReleased(isProxyReleased);\\n const last = path[path.length - 1];\\n if (last === createEndpoint) {\\n return requestResponseMessage(ep, pendingListeners, {\\n type: \\\"ENDPOINT\\\" /* MessageType.ENDPOINT */,\\n }).then(fromWireValue);\\n }\\n // We just pretend that `bind()` didn’t happen.\\n if (last === \\\"bind\\\") {\\n return createProxy(ep, pendingListeners, path.slice(0, -1));\\n }\\n const [argumentList, transferables] = processArguments(rawArgumentList);\\n return requestResponseMessage(ep, pendingListeners, {\\n type: \\\"APPLY\\\" /* MessageType.APPLY */,\\n path: path.map((p) => p.toString()),\\n argumentList,\\n }, transferables).then(fromWireValue);\\n },\\n construct(_target, rawArgumentList) {\\n throwIfProxyReleased(isProxyReleased);\\n const [argumentList, transferables] = processArguments(rawArgumentList);\\n return requestResponseMessage(ep, pendingListeners, {\\n type: \\\"CONSTRUCT\\\" /* MessageType.CONSTRUCT */,\\n path: path.map((p) => p.toString()),\\n argumentList,\\n }, transferables).then(fromWireValue);\\n },\\n });\\n registerProxy(proxy, ep);\\n return proxy;\\n }\\n function myFlat(arr) {\\n return Array.prototype.concat.apply([], arr);\\n }\\n function processArguments(argumentList) {\\n const processed = argumentList.map(toWireValue);\\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\\n }\\n const transferCache = new WeakMap();\\n function transfer(obj, transfers) {\\n transferCache.set(obj, transfers);\\n return obj;\\n }\\n function proxy(obj) {\\n return Object.assign(obj, { [proxyMarker]: true });\\n }\\n function toWireValue(value) {\\n for (const [name, handler] of transferHandlers) {\\n if (handler.canHandle(value)) {\\n const [serializedValue, transferables] = handler.serialize(value);\\n return [\\n {\\n type: \\\"HANDLER\\\" /* WireValueType.HANDLER */,\\n name,\\n value: serializedValue,\\n },\\n transferables,\\n ];\\n }\\n }\\n return [\\n {\\n type: \\\"RAW\\\" /* WireValueType.RAW */,\\n value,\\n },\\n transferCache.get(value) || [],\\n ];\\n }\\n function fromWireValue(value) {\\n switch (value.type) {\\n case \\\"HANDLER\\\" /* WireValueType.HANDLER */:\\n return transferHandlers.get(value.name).deserialize(value.value);\\n case \\\"RAW\\\" /* WireValueType.RAW */:\\n return value.value;\\n }\\n }\\n function requestResponseMessage(ep, pendingListeners, msg, transfers) {\\n return new Promise((resolve) => {\\n const id = generateUUID();\\n pendingListeners.set(id, resolve);\\n if (ep.start) {\\n ep.start();\\n }\\n ep.postMessage(Object.assign({ id }, msg), transfers);\\n });\\n }\\n function generateUUID() {\\n return new Array(4)\\n .fill(0)\\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\\n .join(\\\"-\\\");\\n }\\n\\n /**\\n * MatrixRenderer class is meant to be used within a Web Worker context,\\n * using Comlink to facilitate communication between the main thread and the worker.\\n * The MatrixRenderer class manages a matrix of dies, once an instance of MatrixRenderer is created,\\n * it is exposed to the main thread using Comlink's `expose` method.\\n * This setup is used in the wafer-map component to perform heavy computational duties\\n */\\n class MatrixRenderer {\\n constructor() {\\n this.values = Float64Array.from([]);\\n this.scaledColumnIndices = Float64Array.from([]);\\n this.scaledRowIndices = Float64Array.from([]);\\n this.columnIndicesPositions = Int32Array.from([]);\\n this.colorIndices = Int32Array.from([]);\\n this.colors = [];\\n this.colorValues = Float64Array.from([]);\\n this.outsideRangeDieColor = 'rgba(218,223,236,1)';\\n this.fontSizeFactor = 0.8;\\n this.renderConfig = {\\n dieDimensions: {\\n width: 0,\\n height: 0\\n },\\n margin: {\\n top: 0,\\n right: 0,\\n bottom: 0,\\n left: 0\\n },\\n verticalCoefficient: 1,\\n horizontalCoefficient: 1,\\n horizontalConstant: 0,\\n verticalConstant: 0,\\n gridMinX: 0,\\n gridMaxX: 0,\\n gridMinY: 0,\\n gridMaxY: 0,\\n labelsFontSize: 0,\\n colorScale: [],\\n dieLabelsSuffix: '',\\n maxCharacters: 0\\n };\\n this.transformConfig = {\\n transform: {\\n k: 1,\\n x: 0,\\n y: 0\\n },\\n topLeftCanvasCorner: {\\n x: 0,\\n y: 0\\n },\\n bottomRightCanvasCorner: {\\n x: 0,\\n y: 0\\n }\\n };\\n }\\n setMatrixData(columnIndices, rowIndices, valuesBuffer) {\\n const scaledColumnIndex = [];\\n const columnPositions = [];\\n const scaledRowIndices = [];\\n const values = [];\\n const colorIndices = [];\\n let prevXIndex;\\n let dieCount = 0;\\n for (let i = 0; i < columnIndices.length; i++) {\\n const xIndex = columnIndices[i];\\n const yIndex = rowIndices[i];\\n if (this.isDieInGrid(xIndex, yIndex)) {\\n if (xIndex !== prevXIndex) {\\n scaledColumnIndex.push(this.calculateHorizontalScaledIndices(xIndex));\\n columnPositions.push(dieCount);\\n prevXIndex = xIndex;\\n }\\n scaledRowIndices.push(this.calculateVerticalScaledIndices(yIndex));\\n const value = valuesBuffer[i];\\n values.push(value);\\n colorIndices.push(this.findColorIndex(value));\\n dieCount += 1;\\n }\\n }\\n this.scaledColumnIndices = Float64Array.from(scaledColumnIndex);\\n this.columnIndicesPositions = Int32Array.from(columnPositions);\\n this.scaledRowIndices = Float64Array.from(scaledRowIndices);\\n this.values = Float64Array.from(values);\\n this.colorIndices = Int32Array.from(colorIndices);\\n }\\n setRenderConfig(renderConfig) {\\n this.renderConfig = renderConfig;\\n this.colors = renderConfig.colorScale.map(marker => marker.color);\\n this.colorValues = Float64Array.from(renderConfig.colorScale.map(marker => marker.value));\\n }\\n setTransformConfig(transformData) {\\n this.transformConfig = transformData;\\n }\\n setCanvas(canvas) {\\n this.canvas = canvas;\\n this.context = canvas.getContext('2d');\\n }\\n scaleCanvas() {\\n this.context.translate(this.transformConfig.transform.x, this.transformConfig.transform.y);\\n this.context.scale(this.transformConfig.transform.k, this.transformConfig.transform.k);\\n }\\n setCanvasDimensions(data) {\\n this.canvas.width = data.width;\\n this.canvas.height = data.height;\\n }\\n getCanvasDimensions() {\\n return {\\n width: this.canvas.width,\\n height: this.canvas.height\\n };\\n }\\n clearCanvas() {\\n this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);\\n }\\n drawWafer() {\\n this.context.restore();\\n this.context.save();\\n this.clearCanvas();\\n this.scaleCanvas();\\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\\n const scaledX = this.scaledColumnIndices[i];\\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\\n continue;\\n }\\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\\n ? this.columnIndicesPositions[i + 1]\\n : this.scaledRowIndices.length;\\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\\n const scaledY = this.scaledRowIndices[columnStartIndex];\\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\\n continue;\\n }\\n // Fill style is temporary green for all dies, will be replaced with a color based on the value of the die in a future implementation\\n this.context.fillStyle = this.colors[this.colorIndices[columnStartIndex]]\\n ?? this.outsideRangeDieColor;\\n this.context.fillRect(scaledX, scaledY, this.renderConfig.dieDimensions.width, this.renderConfig.dieDimensions.height);\\n }\\n }\\n }\\n drawText() {\\n this.context.font = `${this.renderConfig.labelsFontSize.toString()}px sans-serif`;\\n this.context.fillStyle = '#ffffff';\\n this.context.textAlign = 'center';\\n this.context.lineCap = 'butt';\\n const approximateTextHeight = this.context.measureText('M');\\n for (let i = 0; i < this.scaledColumnIndices.length; i++) {\\n const scaledX = this.scaledColumnIndices[i];\\n if (!(scaledX >= this.transformConfig.topLeftCanvasCorner.x\\n && scaledX < this.transformConfig.bottomRightCanvasCorner.x)) {\\n continue;\\n }\\n // columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]\\n // This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on\\n // scaledRowIndices is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndices is 13\\n const columnEndIndex = this.columnIndicesPositions[i + 1] !== undefined\\n ? this.columnIndicesPositions[i + 1]\\n : this.scaledRowIndices.length;\\n for (let columnStartIndex = this.columnIndicesPositions[i]; columnStartIndex < columnEndIndex; columnStartIndex++) {\\n const scaledY = this.scaledRowIndices[columnStartIndex];\\n if (!(scaledY >= this.transformConfig.topLeftCanvasCorner.y\\n && scaledY < this.transformConfig.bottomRightCanvasCorner.y)) {\\n continue;\\n }\\n let label = `${this.values[columnStartIndex] || 'NaN'}${this.renderConfig.dieLabelsSuffix}`;\\n if (label.length >= this.renderConfig.maxCharacters) {\\n label = `${label.substring(0, this.renderConfig.maxCharacters)}…`;\\n }\\n this.context.fillText(label, scaledX + this.renderConfig.dieDimensions.width / 2, scaledY\\n + this.renderConfig.dieDimensions.height / 2\\n + approximateTextHeight.width / 2, this.renderConfig.dieDimensions.width * this.fontSizeFactor);\\n }\\n }\\n }\\n isDieInGrid(x, y) {\\n return (x >= this.renderConfig.gridMinX\\n && x <= this.renderConfig.gridMaxX\\n && y >= this.renderConfig.gridMinY\\n && y <= this.renderConfig.gridMaxY);\\n }\\n calculateHorizontalScaledIndices(columnIndex) {\\n return (this.renderConfig.horizontalCoefficient * columnIndex\\n + this.renderConfig.horizontalConstant\\n + this.renderConfig.margin.left);\\n }\\n calculateVerticalScaledIndices(rowIndex) {\\n return (this.renderConfig.verticalCoefficient * rowIndex\\n + this.renderConfig.verticalConstant\\n + this.renderConfig.margin.top);\\n }\\n findColorIndex(value) {\\n let index = -1;\\n if (this.colorValues.length === 0 || this.colorValues[0] >= value) {\\n return index;\\n }\\n for (let i = 0; i < this.colorValues.length; i++) {\\n if (value <= this.colorValues[i]) {\\n index = i;\\n break;\\n }\\n }\\n return index;\\n }\\n }\\n expose(MatrixRenderer);\\n\\n exports.MatrixRenderer = MatrixRenderer;\\n\\n return exports;\\n\\n})({});\\n\";"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ni/nimble-components",
3
- "version": "32.7.0",
3
+ "version": "32.7.2",
4
4
  "description": "Styled web components for the NI Nimble Design System",
5
5
  "scripts": {
6
6
  "build": "npm run generate-icons && npm run generate-workers && npm run build-components && npm run bundle-components && npm run generate-scss",
@@ -85,8 +85,8 @@
85
85
  "@types/d3-scale": "^4.0.2",
86
86
  "@types/d3-selection": "^3.0.0",
87
87
  "@types/d3-zoom": "^3.0.0",
88
- "@types/markdown-it": "^13.0.8",
89
- "comlink": "4.4.1",
88
+ "@types/markdown-it": "^14.1.2",
89
+ "comlink": "4.4.2",
90
90
  "d3-array": "^3.2.2",
91
91
  "d3-random": "^3.0.1",
92
92
  "d3-scale": "^4.0.2",
@@ -98,7 +98,7 @@
98
98
  "tslib": "^2.2.0"
99
99
  },
100
100
  "peerDependencies": {
101
- "apache-arrow": "16.1.0"
101
+ "apache-arrow": "18.0.0"
102
102
  },
103
103
  "devDependencies": {
104
104
  "@ni-private/eslint-config-nimble": "*",