UNPKG

@imgly/background-removal

Version:
4 lines 340 kB
{ "version": 3, "sources": ["../../../node_modules/iota-array/iota.js", "../../../node_modules/is-buffer/index.js", "../../../node_modules/ndarray/ndarray.js", "../../../node_modules/lodash-es/_freeGlobal.js", "../../../node_modules/lodash-es/_root.js", "../../../node_modules/lodash-es/_Symbol.js", "../../../node_modules/lodash-es/_getRawTag.js", "../../../node_modules/lodash-es/_objectToString.js", "../../../node_modules/lodash-es/_baseGetTag.js", "../../../node_modules/lodash-es/isObject.js", "../../../node_modules/lodash-es/isFunction.js", "../../../node_modules/lodash-es/_coreJsData.js", "../../../node_modules/lodash-es/_isMasked.js", "../../../node_modules/lodash-es/_toSource.js", "../../../node_modules/lodash-es/_baseIsNative.js", "../../../node_modules/lodash-es/_getValue.js", "../../../node_modules/lodash-es/_getNative.js", "../../../node_modules/lodash-es/_nativeCreate.js", "../../../node_modules/lodash-es/_hashClear.js", "../../../node_modules/lodash-es/_hashDelete.js", "../../../node_modules/lodash-es/_hashGet.js", "../../../node_modules/lodash-es/_hashHas.js", "../../../node_modules/lodash-es/_hashSet.js", "../../../node_modules/lodash-es/_Hash.js", "../../../node_modules/lodash-es/_listCacheClear.js", "../../../node_modules/lodash-es/eq.js", "../../../node_modules/lodash-es/_assocIndexOf.js", "../../../node_modules/lodash-es/_listCacheDelete.js", "../../../node_modules/lodash-es/_listCacheGet.js", "../../../node_modules/lodash-es/_listCacheHas.js", "../../../node_modules/lodash-es/_listCacheSet.js", "../../../node_modules/lodash-es/_ListCache.js", "../../../node_modules/lodash-es/_Map.js", "../../../node_modules/lodash-es/_mapCacheClear.js", "../../../node_modules/lodash-es/_isKeyable.js", "../../../node_modules/lodash-es/_getMapData.js", "../../../node_modules/lodash-es/_mapCacheDelete.js", "../../../node_modules/lodash-es/_mapCacheGet.js", "../../../node_modules/lodash-es/_mapCacheHas.js", "../../../node_modules/lodash-es/_mapCacheSet.js", "../../../node_modules/lodash-es/_MapCache.js", "../../../node_modules/lodash-es/memoize.js", "../src/utils.ts", "../src/MimeType.ts", "../src/codecs.ts", "../src/url.ts", "../src/onnx.ts", "../src/capabilities.js", "../src/resource.ts", "../../../node_modules/zod/lib/index.mjs", "../package.json", "../src/schema.ts", "../src/inference.ts", "../src/api/v1.ts"], "sourcesContent": ["\"use strict\"\n\nfunction iota(n) {\n var result = new Array(n)\n for(var i=0; i<n; ++i) {\n result[i] = i\n }\n return result\n}\n\nmodule.exports = iota", "/*!\n * Determine if an object is a Buffer\n *\n * @author Feross Aboukhadijeh <https://feross.org>\n * @license MIT\n */\n\n// The _isBuffer check is for Safari 5-7 support, because it's missing\n// Object.prototype.constructor. Remove this eventually\nmodule.exports = function (obj) {\n return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)\n}\n\nfunction isBuffer (obj) {\n return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)\n}\n\n// For Node v0.10 support. Remove this eventually.\nfunction isSlowBuffer (obj) {\n return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))\n}\n", "var iota = require(\"iota-array\")\nvar isBuffer = require(\"is-buffer\")\n\nvar hasTypedArrays = ((typeof Float64Array) !== \"undefined\")\n\nfunction compare1st(a, b) {\n return a[0] - b[0]\n}\n\nfunction order() {\n var stride = this.stride\n var terms = new Array(stride.length)\n var i\n for(i=0; i<terms.length; ++i) {\n terms[i] = [Math.abs(stride[i]), i]\n }\n terms.sort(compare1st)\n var result = new Array(terms.length)\n for(i=0; i<result.length; ++i) {\n result[i] = terms[i][1]\n }\n return result\n}\n\nfunction compileConstructor(dtype, dimension) {\n var className = [\"View\", dimension, \"d\", dtype].join(\"\")\n if(dimension < 0) {\n className = \"View_Nil\" + dtype\n }\n var useGetters = (dtype === \"generic\")\n\n if(dimension === -1) {\n //Special case for trivial arrays\n var code =\n \"function \"+className+\"(a){this.data=a;};\\\nvar proto=\"+className+\".prototype;\\\nproto.dtype='\"+dtype+\"';\\\nproto.index=function(){return -1};\\\nproto.size=0;\\\nproto.dimension=-1;\\\nproto.shape=proto.stride=proto.order=[];\\\nproto.lo=proto.hi=proto.transpose=proto.step=\\\nfunction(){return new \"+className+\"(this.data);};\\\nproto.get=proto.set=function(){};\\\nproto.pick=function(){return null};\\\nreturn function construct_\"+className+\"(a){return new \"+className+\"(a);}\"\n var procedure = new Function(code)\n return procedure()\n } else if(dimension === 0) {\n //Special case for 0d arrays\n var code =\n \"function \"+className+\"(a,d) {\\\nthis.data = a;\\\nthis.offset = d\\\n};\\\nvar proto=\"+className+\".prototype;\\\nproto.dtype='\"+dtype+\"';\\\nproto.index=function(){return this.offset};\\\nproto.dimension=0;\\\nproto.size=1;\\\nproto.shape=\\\nproto.stride=\\\nproto.order=[];\\\nproto.lo=\\\nproto.hi=\\\nproto.transpose=\\\nproto.step=function \"+className+\"_copy() {\\\nreturn new \"+className+\"(this.data,this.offset)\\\n};\\\nproto.pick=function \"+className+\"_pick(){\\\nreturn TrivialArray(this.data);\\\n};\\\nproto.valueOf=proto.get=function \"+className+\"_get(){\\\nreturn \"+(useGetters ? \"this.data.get(this.offset)\" : \"this.data[this.offset]\")+\n\"};\\\nproto.set=function \"+className+\"_set(v){\\\nreturn \"+(useGetters ? \"this.data.set(this.offset,v)\" : \"this.data[this.offset]=v\")+\"\\\n};\\\nreturn function construct_\"+className+\"(a,b,c,d){return new \"+className+\"(a,d)}\"\n var procedure = new Function(\"TrivialArray\", code)\n return procedure(CACHED_CONSTRUCTORS[dtype][0])\n }\n\n var code = [\"'use strict'\"]\n\n //Create constructor for view\n var indices = iota(dimension)\n var args = indices.map(function(i) { return \"i\"+i })\n var index_str = \"this.offset+\" + indices.map(function(i) {\n return \"this.stride[\" + i + \"]*i\" + i\n }).join(\"+\")\n var shapeArg = indices.map(function(i) {\n return \"b\"+i\n }).join(\",\")\n var strideArg = indices.map(function(i) {\n return \"c\"+i\n }).join(\",\")\n code.push(\n \"function \"+className+\"(a,\" + shapeArg + \",\" + strideArg + \",d){this.data=a\",\n \"this.shape=[\" + shapeArg + \"]\",\n \"this.stride=[\" + strideArg + \"]\",\n \"this.offset=d|0}\",\n \"var proto=\"+className+\".prototype\",\n \"proto.dtype='\"+dtype+\"'\",\n \"proto.dimension=\"+dimension)\n\n //view.size:\n code.push(\"Object.defineProperty(proto,'size',{get:function \"+className+\"_size(){\\\nreturn \"+indices.map(function(i) { return \"this.shape[\"+i+\"]\" }).join(\"*\"),\n\"}})\")\n\n //view.order:\n if(dimension === 1) {\n code.push(\"proto.order=[0]\")\n } else {\n code.push(\"Object.defineProperty(proto,'order',{get:\")\n if(dimension < 4) {\n code.push(\"function \"+className+\"_order(){\")\n if(dimension === 2) {\n code.push(\"return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}})\")\n } else if(dimension === 3) {\n code.push(\n\"var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);\\\nif(s0>s1){\\\nif(s1>s2){\\\nreturn [2,1,0];\\\n}else if(s0>s2){\\\nreturn [1,2,0];\\\n}else{\\\nreturn [1,0,2];\\\n}\\\n}else if(s0>s2){\\\nreturn [2,0,1];\\\n}else if(s2>s1){\\\nreturn [0,1,2];\\\n}else{\\\nreturn [0,2,1];\\\n}}})\")\n }\n } else {\n code.push(\"ORDER})\")\n }\n }\n\n //view.set(i0, ..., v):\n code.push(\n\"proto.set=function \"+className+\"_set(\"+args.join(\",\")+\",v){\")\n if(useGetters) {\n code.push(\"return this.data.set(\"+index_str+\",v)}\")\n } else {\n code.push(\"return this.data[\"+index_str+\"]=v}\")\n }\n\n //view.get(i0, ...):\n code.push(\"proto.get=function \"+className+\"_get(\"+args.join(\",\")+\"){\")\n if(useGetters) {\n code.push(\"return this.data.get(\"+index_str+\")}\")\n } else {\n code.push(\"return this.data[\"+index_str+\"]}\")\n }\n\n //view.index:\n code.push(\n \"proto.index=function \"+className+\"_index(\", args.join(), \"){return \"+index_str+\"}\")\n\n //view.hi():\n code.push(\"proto.hi=function \"+className+\"_hi(\"+args.join(\",\")+\"){return new \"+className+\"(this.data,\"+\n indices.map(function(i) {\n return [\"(typeof i\",i,\"!=='number'||i\",i,\"<0)?this.shape[\", i, \"]:i\", i,\"|0\"].join(\"\")\n }).join(\",\")+\",\"+\n indices.map(function(i) {\n return \"this.stride[\"+i + \"]\"\n }).join(\",\")+\",this.offset)}\")\n\n //view.lo():\n var a_vars = indices.map(function(i) { return \"a\"+i+\"=this.shape[\"+i+\"]\" })\n var c_vars = indices.map(function(i) { return \"c\"+i+\"=this.stride[\"+i+\"]\" })\n code.push(\"proto.lo=function \"+className+\"_lo(\"+args.join(\",\")+\"){var b=this.offset,d=0,\"+a_vars.join(\",\")+\",\"+c_vars.join(\",\"))\n for(var i=0; i<dimension; ++i) {\n code.push(\n\"if(typeof i\"+i+\"==='number'&&i\"+i+\">=0){\\\nd=i\"+i+\"|0;\\\nb+=c\"+i+\"*d;\\\na\"+i+\"-=d}\")\n }\n code.push(\"return new \"+className+\"(this.data,\"+\n indices.map(function(i) {\n return \"a\"+i\n }).join(\",\")+\",\"+\n indices.map(function(i) {\n return \"c\"+i\n }).join(\",\")+\",b)}\")\n\n //view.step():\n code.push(\"proto.step=function \"+className+\"_step(\"+args.join(\",\")+\"){var \"+\n indices.map(function(i) {\n return \"a\"+i+\"=this.shape[\"+i+\"]\"\n }).join(\",\")+\",\"+\n indices.map(function(i) {\n return \"b\"+i+\"=this.stride[\"+i+\"]\"\n }).join(\",\")+\",c=this.offset,d=0,ceil=Math.ceil\")\n for(var i=0; i<dimension; ++i) {\n code.push(\n\"if(typeof i\"+i+\"==='number'){\\\nd=i\"+i+\"|0;\\\nif(d<0){\\\nc+=b\"+i+\"*(a\"+i+\"-1);\\\na\"+i+\"=ceil(-a\"+i+\"/d)\\\n}else{\\\na\"+i+\"=ceil(a\"+i+\"/d)\\\n}\\\nb\"+i+\"*=d\\\n}\")\n }\n code.push(\"return new \"+className+\"(this.data,\"+\n indices.map(function(i) {\n return \"a\" + i\n }).join(\",\")+\",\"+\n indices.map(function(i) {\n return \"b\" + i\n }).join(\",\")+\",c)}\")\n\n //view.transpose():\n var tShape = new Array(dimension)\n var tStride = new Array(dimension)\n for(var i=0; i<dimension; ++i) {\n tShape[i] = \"a[i\"+i+\"]\"\n tStride[i] = \"b[i\"+i+\"]\"\n }\n code.push(\"proto.transpose=function \"+className+\"_transpose(\"+args+\"){\"+\n args.map(function(n,idx) { return n + \"=(\" + n + \"===undefined?\" + idx + \":\" + n + \"|0)\"}).join(\";\"),\n \"var a=this.shape,b=this.stride;return new \"+className+\"(this.data,\"+tShape.join(\",\")+\",\"+tStride.join(\",\")+\",this.offset)}\")\n\n //view.pick():\n code.push(\"proto.pick=function \"+className+\"_pick(\"+args+\"){var a=[],b=[],c=this.offset\")\n for(var i=0; i<dimension; ++i) {\n code.push(\"if(typeof i\"+i+\"==='number'&&i\"+i+\">=0){c=(c+this.stride[\"+i+\"]*i\"+i+\")|0}else{a.push(this.shape[\"+i+\"]);b.push(this.stride[\"+i+\"])}\")\n }\n code.push(\"var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}\")\n\n //Add return statement\n code.push(\"return function construct_\"+className+\"(data,shape,stride,offset){return new \"+className+\"(data,\"+\n indices.map(function(i) {\n return \"shape[\"+i+\"]\"\n }).join(\",\")+\",\"+\n indices.map(function(i) {\n return \"stride[\"+i+\"]\"\n }).join(\",\")+\",offset)}\")\n\n //Compile procedure\n var procedure = new Function(\"CTOR_LIST\", \"ORDER\", code.join(\"\\n\"))\n return procedure(CACHED_CONSTRUCTORS[dtype], order)\n}\n\nfunction arrayDType(data) {\n if(isBuffer(data)) {\n return \"buffer\"\n }\n if(hasTypedArrays) {\n switch(Object.prototype.toString.call(data)) {\n case \"[object Float64Array]\":\n return \"float64\"\n case \"[object Float32Array]\":\n return \"float32\"\n case \"[object Int8Array]\":\n return \"int8\"\n case \"[object Int16Array]\":\n return \"int16\"\n case \"[object Int32Array]\":\n return \"int32\"\n case \"[object Uint8Array]\":\n return \"uint8\"\n case \"[object Uint16Array]\":\n return \"uint16\"\n case \"[object Uint32Array]\":\n return \"uint32\"\n case \"[object Uint8ClampedArray]\":\n return \"uint8_clamped\"\n case \"[object BigInt64Array]\":\n return \"bigint64\"\n case \"[object BigUint64Array]\":\n return \"biguint64\"\n }\n }\n if(Array.isArray(data)) {\n return \"array\"\n }\n return \"generic\"\n}\n\nvar CACHED_CONSTRUCTORS = {\n \"float32\":[],\n \"float64\":[],\n \"int8\":[],\n \"int16\":[],\n \"int32\":[],\n \"uint8\":[],\n \"uint16\":[],\n \"uint32\":[],\n \"array\":[],\n \"uint8_clamped\":[],\n \"bigint64\": [],\n \"biguint64\": [],\n \"buffer\":[],\n \"generic\":[]\n}\n\n;(function() {\n for(var id in CACHED_CONSTRUCTORS) {\n CACHED_CONSTRUCTORS[id].push(compileConstructor(id, -1))\n }\n});\n\nfunction wrappedNDArrayCtor(data, shape, stride, offset) {\n if(data === undefined) {\n var ctor = CACHED_CONSTRUCTORS.array[0]\n return ctor([])\n } else if(typeof data === \"number\") {\n data = [data]\n }\n if(shape === undefined) {\n shape = [ data.length ]\n }\n var d = shape.length\n if(stride === undefined) {\n stride = new Array(d)\n for(var i=d-1, sz=1; i>=0; --i) {\n stride[i] = sz\n sz *= shape[i]\n }\n }\n if(offset === undefined) {\n offset = 0\n for(var i=0; i<d; ++i) {\n if(stride[i] < 0) {\n offset -= (shape[i]-1)*stride[i]\n }\n }\n }\n var dtype = arrayDType(data)\n var ctor_list = CACHED_CONSTRUCTORS[dtype]\n while(ctor_list.length <= d+1) {\n ctor_list.push(compileConstructor(dtype, ctor_list.length-1))\n }\n var ctor = ctor_list[d+1]\n return ctor(data, shape, stride, offset)\n}\n\nmodule.exports = wrappedNDArrayCtor\n", "/** Detect free variable `global` from Node.js. */\nvar freeGlobal = typeof global == 'object' && global && global.Object === Object && global;\n\nexport default freeGlobal;\n", "import freeGlobal from './_freeGlobal.js';\n\n/** Detect free variable `self`. */\nvar freeSelf = typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\nexport default root;\n", "import root from './_root.js';\n\n/** Built-in value references. */\nvar Symbol = root.Symbol;\n\nexport default Symbol;\n", "import Symbol from './_Symbol.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar nativeObjectToString = objectProto.toString;\n\n/** Built-in value references. */\nvar symToStringTag = Symbol ? Symbol.toStringTag : undefined;\n\n/**\n * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.\n *\n * @private\n * @param {*} value The value to query.\n * @returns {string} Returns the raw `toStringTag`.\n */\nfunction getRawTag(value) {\n var isOwn = hasOwnProperty.call(value, symToStringTag),\n tag = value[symToStringTag];\n\n try {\n value[symToStringTag] = undefined;\n var unmasked = true;\n } catch (e) {}\n\n var result = nativeObjectToString.call(value);\n if (unmasked) {\n if (isOwn) {\n value[symToStringTag] = tag;\n } else {\n delete value[symToStringTag];\n }\n }\n return result;\n}\n\nexport default getRawTag;\n", "/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar nativeObjectToString = objectProto.toString;\n\n/**\n * Converts `value` to a string using `Object.prototype.toString`.\n *\n * @private\n * @param {*} value The value to convert.\n * @returns {string} Returns the converted string.\n */\nfunction objectToString(value) {\n return nativeObjectToString.call(value);\n}\n\nexport default objectToString;\n", "import Symbol from './_Symbol.js';\nimport getRawTag from './_getRawTag.js';\nimport objectToString from './_objectToString.js';\n\n/** `Object#toString` result references. */\nvar nullTag = '[object Null]',\n undefinedTag = '[object Undefined]';\n\n/** Built-in value references. */\nvar symToStringTag = Symbol ? Symbol.toStringTag : undefined;\n\n/**\n * The base implementation of `getTag` without fallbacks for buggy environments.\n *\n * @private\n * @param {*} value The value to query.\n * @returns {string} Returns the `toStringTag`.\n */\nfunction baseGetTag(value) {\n if (value == null) {\n return value === undefined ? undefinedTag : nullTag;\n }\n return (symToStringTag && symToStringTag in Object(value))\n ? getRawTag(value)\n : objectToString(value);\n}\n\nexport default baseGetTag;\n", "/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return value != null && (type == 'object' || type == 'function');\n}\n\nexport default isObject;\n", "import baseGetTag from './_baseGetTag.js';\nimport isObject from './isObject.js';\n\n/** `Object#toString` result references. */\nvar asyncTag = '[object AsyncFunction]',\n funcTag = '[object Function]',\n genTag = '[object GeneratorFunction]',\n proxyTag = '[object Proxy]';\n\n/**\n * Checks if `value` is classified as a `Function` object.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a function, else `false`.\n * @example\n *\n * _.isFunction(_);\n * // => true\n *\n * _.isFunction(/abc/);\n * // => false\n */\nfunction isFunction(value) {\n if (!isObject(value)) {\n return false;\n }\n // The use of `Object#toString` avoids issues with the `typeof` operator\n // in Safari 9 which returns 'object' for typed arrays and other constructors.\n var tag = baseGetTag(value);\n return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;\n}\n\nexport default isFunction;\n", "import root from './_root.js';\n\n/** Used to detect overreaching core-js shims. */\nvar coreJsData = root['__core-js_shared__'];\n\nexport default coreJsData;\n", "import coreJsData from './_coreJsData.js';\n\n/** Used to detect methods masquerading as native. */\nvar maskSrcKey = (function() {\n var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');\n return uid ? ('Symbol(src)_1.' + uid) : '';\n}());\n\n/**\n * Checks if `func` has its source masked.\n *\n * @private\n * @param {Function} func The function to check.\n * @returns {boolean} Returns `true` if `func` is masked, else `false`.\n */\nfunction isMasked(func) {\n return !!maskSrcKey && (maskSrcKey in func);\n}\n\nexport default isMasked;\n", "/** Used for built-in method references. */\nvar funcProto = Function.prototype;\n\n/** Used to resolve the decompiled source of functions. */\nvar funcToString = funcProto.toString;\n\n/**\n * Converts `func` to its source code.\n *\n * @private\n * @param {Function} func The function to convert.\n * @returns {string} Returns the source code.\n */\nfunction toSource(func) {\n if (func != null) {\n try {\n return funcToString.call(func);\n } catch (e) {}\n try {\n return (func + '');\n } catch (e) {}\n }\n return '';\n}\n\nexport default toSource;\n", "import isFunction from './isFunction.js';\nimport isMasked from './_isMasked.js';\nimport isObject from './isObject.js';\nimport toSource from './_toSource.js';\n\n/**\n * Used to match `RegExp`\n * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).\n */\nvar reRegExpChar = /[\\\\^$.*+?()[\\]{}|]/g;\n\n/** Used to detect host constructors (Safari). */\nvar reIsHostCtor = /^\\[object .+?Constructor\\]$/;\n\n/** Used for built-in method references. */\nvar funcProto = Function.prototype,\n objectProto = Object.prototype;\n\n/** Used to resolve the decompiled source of functions. */\nvar funcToString = funcProto.toString;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/** Used to detect if a method is native. */\nvar reIsNative = RegExp('^' +\n funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\\\$&')\n .replace(/hasOwnProperty|(function).*?(?=\\\\\\()| for .+?(?=\\\\\\])/g, '$1.*?') + '$'\n);\n\n/**\n * The base implementation of `_.isNative` without bad shim checks.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a native function,\n * else `false`.\n */\nfunction baseIsNative(value) {\n if (!isObject(value) || isMasked(value)) {\n return false;\n }\n var pattern = isFunction(value) ? reIsNative : reIsHostCtor;\n return pattern.test(toSource(value));\n}\n\nexport default baseIsNative;\n", "/**\n * Gets the value at `key` of `object`.\n *\n * @private\n * @param {Object} [object] The object to query.\n * @param {string} key The key of the property to get.\n * @returns {*} Returns the property value.\n */\nfunction getValue(object, key) {\n return object == null ? undefined : object[key];\n}\n\nexport default getValue;\n", "import baseIsNative from './_baseIsNative.js';\nimport getValue from './_getValue.js';\n\n/**\n * Gets the native function at `key` of `object`.\n *\n * @private\n * @param {Object} object The object to query.\n * @param {string} key The key of the method to get.\n * @returns {*} Returns the function if it's native, else `undefined`.\n */\nfunction getNative(object, key) {\n var value = getValue(object, key);\n return baseIsNative(value) ? value : undefined;\n}\n\nexport default getNative;\n", "import getNative from './_getNative.js';\n\n/* Built-in method references that are verified to be native. */\nvar nativeCreate = getNative(Object, 'create');\n\nexport default nativeCreate;\n", "import nativeCreate from './_nativeCreate.js';\n\n/**\n * Removes all key-value entries from the hash.\n *\n * @private\n * @name clear\n * @memberOf Hash\n */\nfunction hashClear() {\n this.__data__ = nativeCreate ? nativeCreate(null) : {};\n this.size = 0;\n}\n\nexport default hashClear;\n", "/**\n * Removes `key` and its value from the hash.\n *\n * @private\n * @name delete\n * @memberOf Hash\n * @param {Object} hash The hash to modify.\n * @param {string} key The key of the value to remove.\n * @returns {boolean} Returns `true` if the entry was removed, else `false`.\n */\nfunction hashDelete(key) {\n var result = this.has(key) && delete this.__data__[key];\n this.size -= result ? 1 : 0;\n return result;\n}\n\nexport default hashDelete;\n", "import nativeCreate from './_nativeCreate.js';\n\n/** Used to stand-in for `undefined` hash values. */\nvar HASH_UNDEFINED = '__lodash_hash_undefined__';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Gets the hash value for `key`.\n *\n * @private\n * @name get\n * @memberOf Hash\n * @param {string} key The key of the value to get.\n * @returns {*} Returns the entry value.\n */\nfunction hashGet(key) {\n var data = this.__data__;\n if (nativeCreate) {\n var result = data[key];\n return result === HASH_UNDEFINED ? undefined : result;\n }\n return hasOwnProperty.call(data, key) ? data[key] : undefined;\n}\n\nexport default hashGet;\n", "import nativeCreate from './_nativeCreate.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Checks if a hash value for `key` exists.\n *\n * @private\n * @name has\n * @memberOf Hash\n * @param {string} key The key of the entry to check.\n * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.\n */\nfunction hashHas(key) {\n var data = this.__data__;\n return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);\n}\n\nexport default hashHas;\n", "import nativeCreate from './_nativeCreate.js';\n\n/** Used to stand-in for `undefined` hash values. */\nvar HASH_UNDEFINED = '__lodash_hash_undefined__';\n\n/**\n * Sets the hash `key` to `value`.\n *\n * @private\n * @name set\n * @memberOf Hash\n * @param {string} key The key of the value to set.\n * @param {*} value The value to set.\n * @returns {Object} Returns the hash instance.\n */\nfunction hashSet(key, value) {\n var data = this.__data__;\n this.size += this.has(key) ? 0 : 1;\n data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;\n return this;\n}\n\nexport default hashSet;\n", "import hashClear from './_hashClear.js';\nimport hashDelete from './_hashDelete.js';\nimport hashGet from './_hashGet.js';\nimport hashHas from './_hashHas.js';\nimport hashSet from './_hashSet.js';\n\n/**\n * Creates a hash object.\n *\n * @private\n * @constructor\n * @param {Array} [entries] The key-value pairs to cache.\n */\nfunction Hash(entries) {\n var index = -1,\n length = entries == null ? 0 : entries.length;\n\n this.clear();\n while (++index < length) {\n var entry = entries[index];\n this.set(entry[0], entry[1]);\n }\n}\n\n// Add methods to `Hash`.\nHash.prototype.clear = hashClear;\nHash.prototype['delete'] = hashDelete;\nHash.prototype.get = hashGet;\nHash.prototype.has = hashHas;\nHash.prototype.set = hashSet;\n\nexport default Hash;\n", "/**\n * Removes all key-value entries from the list cache.\n *\n * @private\n * @name clear\n * @memberOf ListCache\n */\nfunction listCacheClear() {\n this.__data__ = [];\n this.size = 0;\n}\n\nexport default listCacheClear;\n", "/**\n * Performs a\n * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)\n * comparison between two values to determine if they are equivalent.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to compare.\n * @param {*} other The other value to compare.\n * @returns {boolean} Returns `true` if the values are equivalent, else `false`.\n * @example\n *\n * var object = { 'a': 1 };\n * var other = { 'a': 1 };\n *\n * _.eq(object, object);\n * // => true\n *\n * _.eq(object, other);\n * // => false\n *\n * _.eq('a', 'a');\n * // => true\n *\n * _.eq('a', Object('a'));\n * // => false\n *\n * _.eq(NaN, NaN);\n * // => true\n */\nfunction eq(value, other) {\n return value === other || (value !== value && other !== other);\n}\n\nexport default eq;\n", "import eq from './eq.js';\n\n/**\n * Gets the index at which the `key` is found in `array` of key-value pairs.\n *\n * @private\n * @param {Array} array The array to inspect.\n * @param {*} key The key to search for.\n * @returns {number} Returns the index of the matched value, else `-1`.\n */\nfunction assocIndexOf(array, key) {\n var length = array.length;\n while (length--) {\n if (eq(array[length][0], key)) {\n return length;\n }\n }\n return -1;\n}\n\nexport default assocIndexOf;\n", "import assocIndexOf from './_assocIndexOf.js';\n\n/** Used for built-in method references. */\nvar arrayProto = Array.prototype;\n\n/** Built-in value references. */\nvar splice = arrayProto.splice;\n\n/**\n * Removes `key` and its value from the list cache.\n *\n * @private\n * @name delete\n * @memberOf ListCache\n * @param {string} key The key of the value to remove.\n * @returns {boolean} Returns `true` if the entry was removed, else `false`.\n */\nfunction listCacheDelete(key) {\n var data = this.__data__,\n index = assocIndexOf(data, key);\n\n if (index < 0) {\n return false;\n }\n var lastIndex = data.length - 1;\n if (index == lastIndex) {\n data.pop();\n } else {\n splice.call(data, index, 1);\n }\n --this.size;\n return true;\n}\n\nexport default listCacheDelete;\n", "import assocIndexOf from './_assocIndexOf.js';\n\n/**\n * Gets the list cache value for `key`.\n *\n * @private\n * @name get\n * @memberOf ListCache\n * @param {string} key The key of the value to get.\n * @returns {*} Returns the entry value.\n */\nfunction listCacheGet(key) {\n var data = this.__data__,\n index = assocIndexOf(data, key);\n\n return index < 0 ? undefined : data[index][1];\n}\n\nexport default listCacheGet;\n", "import assocIndexOf from './_assocIndexOf.js';\n\n/**\n * Checks if a list cache value for `key` exists.\n *\n * @private\n * @name has\n * @memberOf ListCache\n * @param {string} key The key of the entry to check.\n * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.\n */\nfunction listCacheHas(key) {\n return assocIndexOf(this.__data__, key) > -1;\n}\n\nexport default listCacheHas;\n", "import assocIndexOf from './_assocIndexOf.js';\n\n/**\n * Sets the list cache `key` to `value`.\n *\n * @private\n * @name set\n * @memberOf ListCache\n * @param {string} key The key of the value to set.\n * @param {*} value The value to set.\n * @returns {Object} Returns the list cache instance.\n */\nfunction listCacheSet(key, value) {\n var data = this.__data__,\n index = assocIndexOf(data, key);\n\n if (index < 0) {\n ++this.size;\n data.push([key, value]);\n } else {\n data[index][1] = value;\n }\n return this;\n}\n\nexport default listCacheSet;\n", "import listCacheClear from './_listCacheClear.js';\nimport listCacheDelete from './_listCacheDelete.js';\nimport listCacheGet from './_listCacheGet.js';\nimport listCacheHas from './_listCacheHas.js';\nimport listCacheSet from './_listCacheSet.js';\n\n/**\n * Creates an list cache object.\n *\n * @private\n * @constructor\n * @param {Array} [entries] The key-value pairs to cache.\n */\nfunction ListCache(entries) {\n var index = -1,\n length = entries == null ? 0 : entries.length;\n\n this.clear();\n while (++index < length) {\n var entry = entries[index];\n this.set(entry[0], entry[1]);\n }\n}\n\n// Add methods to `ListCache`.\nListCache.prototype.clear = listCacheClear;\nListCache.prototype['delete'] = listCacheDelete;\nListCache.prototype.get = listCacheGet;\nListCache.prototype.has = listCacheHas;\nListCache.prototype.set = listCacheSet;\n\nexport default ListCache;\n", "import getNative from './_getNative.js';\nimport root from './_root.js';\n\n/* Built-in method references that are verified to be native. */\nvar Map = getNative(root, 'Map');\n\nexport default Map;\n", "import Hash from './_Hash.js';\nimport ListCache from './_ListCache.js';\nimport Map from './_Map.js';\n\n/**\n * Removes all key-value entries from the map.\n *\n * @private\n * @name clear\n * @memberOf MapCache\n */\nfunction mapCacheClear() {\n this.size = 0;\n this.__data__ = {\n 'hash': new Hash,\n 'map': new (Map || ListCache),\n 'string': new Hash\n };\n}\n\nexport default mapCacheClear;\n", "/**\n * Checks if `value` is suitable for use as unique object key.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is suitable, else `false`.\n */\nfunction isKeyable(value) {\n var type = typeof value;\n return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')\n ? (value !== '__proto__')\n : (value === null);\n}\n\nexport default isKeyable;\n", "import isKeyable from './_isKeyable.js';\n\n/**\n * Gets the data for `map`.\n *\n * @private\n * @param {Object} map The map to query.\n * @param {string} key The reference key.\n * @returns {*} Returns the map data.\n */\nfunction getMapData(map, key) {\n var data = map.__data__;\n return isKeyable(key)\n ? data[typeof key == 'string' ? 'string' : 'hash']\n : data.map;\n}\n\nexport default getMapData;\n", "import getMapData from './_getMapData.js';\n\n/**\n * Removes `key` and its value from the map.\n *\n * @private\n * @name delete\n * @memberOf MapCache\n * @param {string} key The key of the value to remove.\n * @returns {boolean} Returns `true` if the entry was removed, else `false`.\n */\nfunction mapCacheDelete(key) {\n var result = getMapData(this, key)['delete'](key);\n this.size -= result ? 1 : 0;\n return result;\n}\n\nexport default mapCacheDelete;\n", "import getMapData from './_getMapData.js';\n\n/**\n * Gets the map value for `key`.\n *\n * @private\n * @name get\n * @memberOf MapCache\n * @param {string} key The key of the value to get.\n * @returns {*} Returns the entry value.\n */\nfunction mapCacheGet(key) {\n return getMapData(this, key).get(key);\n}\n\nexport default mapCacheGet;\n", "import getMapData from './_getMapData.js';\n\n/**\n * Checks if a map value for `key` exists.\n *\n * @private\n * @name has\n * @memberOf MapCache\n * @param {string} key The key of the entry to check.\n * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.\n */\nfunction mapCacheHas(key) {\n return getMapData(this, key).has(key);\n}\n\nexport default mapCacheHas;\n", "import getMapData from './_getMapData.js';\n\n/**\n * Sets the map `key` to `value`.\n *\n * @private\n * @name set\n * @memberOf MapCache\n * @param {string} key The key of the value to set.\n * @param {*} value The value to set.\n * @returns {Object} Returns the map cache instance.\n */\nfunction mapCacheSet(key, value) {\n var data = getMapData(this, key),\n size = data.size;\n\n data.set(key, value);\n this.size += data.size == size ? 0 : 1;\n return this;\n}\n\nexport default mapCacheSet;\n", "import mapCacheClear from './_mapCacheClear.js';\nimport mapCacheDelete from './_mapCacheDelete.js';\nimport mapCacheGet from './_mapCacheGet.js';\nimport mapCacheHas from './_mapCacheHas.js';\nimport mapCacheSet from './_mapCacheSet.js';\n\n/**\n * Creates a map cache object to store key-value pairs.\n *\n * @private\n * @constructor\n * @param {Array} [entries] The key-value pairs to cache.\n */\nfunction MapCache(entries) {\n var index = -1,\n length = entries == null ? 0 : entries.length;\n\n this.clear();\n while (++index < length) {\n var entry = entries[index];\n this.set(entry[0], entry[1]);\n }\n}\n\n// Add methods to `MapCache`.\nMapCache.prototype.clear = mapCacheClear;\nMapCache.prototype['delete'] = mapCacheDelete;\nMapCache.prototype.get = mapCacheGet;\nMapCache.prototype.has = mapCacheHas;\nMapCache.prototype.set = mapCacheSet;\n\nexport default MapCache;\n", "import MapCache from './_MapCache.js';\n\n/** Error message constants. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/**\n * Creates a function that memoizes the result of `func`. If `resolver` is\n * provided, it determines the cache key for storing the result based on the\n * arguments provided to the memoized function. By default, the first argument\n * provided to the memoized function is used as the map cache key. The `func`\n * is invoked with the `this` binding of the memoized function.\n *\n * **Note:** The cache is exposed as the `cache` property on the memoized\n * function. Its creation may be customized by replacing the `_.memoize.Cache`\n * constructor with one whose instances implement the\n * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)\n * method interface of `clear`, `delete`, `get`, `has`, and `set`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to have its output memoized.\n * @param {Function} [resolver] The function to resolve the cache key.\n * @returns {Function} Returns the new memoized function.\n * @example\n *\n * var object = { 'a': 1, 'b': 2 };\n * var other = { 'c': 3, 'd': 4 };\n *\n * var values = _.memoize(_.values);\n * values(object);\n * // => [1, 2]\n *\n * values(other);\n * // => [3, 4]\n *\n * object.a = 2;\n * values(object);\n * // => [1, 2]\n *\n * // Modify the result cache.\n * values.cache.set(object, ['a', 'b']);\n * values(object);\n * // => ['a', 'b']\n *\n * // Replace `_.memoize.Cache`.\n * _.memoize.Cache = WeakMap;\n */\nfunction memoize(func, resolver) {\n if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n var memoized = function() {\n var args = arguments,\n key = resolver ? resolver.apply(this, args) : args[0],\n cache = memoized.cache;\n\n if (cache.has(key)) {\n return cache.get(key);\n }\n var result = func.apply(this, args);\n memoized.cache = cache.set(key, result) || cache;\n return result;\n };\n memoized.cache = new (memoize.Cache || MapCache);\n return memoized;\n}\n\n// Expose `MapCache`.\nmemoize.Cache = MapCache;\n\nexport default memoize;\n", "export {\n imageDecode,\n imageEncode,\n tensorResizeBilinear,\n tensorHWCtoBCHW,\n imageBitmapToImageData,\n imageSourceToImageData,\n type ImageSource,\n createCanvas\n};\n\nimport ndarray, { NdArray, TypedArray } from 'ndarray';\nimport { imageDecode, imageEncode } from './codecs';\nimport { ensureAbsoluteURI } from './url';\nimport { Config } from './schema';\n\ntype ImageSource =\n | ImageData\n | ArrayBuffer\n | Uint8Array\n | Blob\n | URL\n | string\n | NdArray<Uint8Array>;\n\nfunction imageBitmapToImageData(imageBitmap: ImageBitmap): ImageData {\n var canvas = createCanvas(imageBitmap.width, imageBitmap.height);\n var ctx = canvas.getContext('2d')!;\n ctx.drawImage(imageBitmap, 0, 0);\n return ctx.getImageData(0, 0, canvas.width, canvas.height);\n}\n\nfunction createTypeArray<T extends TypedArray>(length: number) {\n if (typeof Uint8Array !== 'undefined') {\n return new Uint8Array(length) as T;\n } else if (typeof Uint8ClampedArray !== 'undefined') {\n return new Uint8ClampedArray(length) as T;\n } else if (typeof Uint16Array !== 'undefined') {\n return new Uint16Array(length) as T;\n } else if (typeof Uint32Array !== 'undefined') {\n return new Uint32Array(length) as T;\n } else if (typeof Float32Array !== 'undefined') {\n return new Float32Array(length) as T;\n } else if (typeof Float64Array !== 'undefined') {\n return new Float64Array(length) as T;\n } else {\n throw new Error('TypedArray not supported');\n }\n}\nfunction tensorResizeBilinear<T extends TypedArray>(\n imageTensor: NdArray<T>,\n newWidth: number,\n newHeight: number,\n proportional: boolean = false\n): NdArray<T> {\n const [srcHeight, srcWidth, srcChannels] = imageTensor.shape;\n\n let scaleX = srcWidth / newWidth;\n let scaleY = srcHeight / newHeight;\n\n if (proportional) {\n const downscaling = Math.max(scaleX, scaleY) > 1.0;\n scaleX = scaleY = downscaling\n ? Math.max(scaleX, scaleY)\n : Math.min(scaleX, scaleY);\n }\n\n // Create a new NdArray to store the resized image\n const resizedImageData = ndarray(\n createTypeArray<T>(srcChannels * newWidth * newHeight),\n [newHeight, newWidth, srcChannels]\n );\n // Perform interpolation to fill the resized NdArray\n for (let y = 0; y < newHeight; y++) {\n for (let x = 0; x < newWidth; x++) {\n const srcX = x * scaleX;\n const srcY = y * scaleY;\n const x1 = Math.max(Math.floor(srcX), 0);\n const x2 = Math.min(Math.ceil(srcX), srcWidth - 1);\n const y1 = Math.max(Math.floor(srcY), 0);\n const y2 = Math.min(Math.ceil(srcY), srcHeight - 1);\n\n const dx = srcX - x1;\n const dy = srcY - y1;\n\n for (let c = 0; c < srcChannels; c++) {\n const p1 = imageTensor.get(y1, x1, c);\n const p2 = imageTensor.get(y1, x2, c);\n const p3 = imageTensor.get(y2, x1, c);\n const p4 = imageTensor.get(y2, x2, c);\n\n // Perform bilinear interpolation\n const interpolatedValue =\n (1 - dx) * (1 - dy) * p1 +\n dx * (1 - dy) * p2 +\n (1 - dx) * dy * p3 +\n dx * dy * p4;\n // console.log(interpolatedValue);\n resizedImageData.set(y, x, c, interpolatedValue);\n }\n }\n }\n\n return resizedImageData;\n}\n\nfunction tensorHWCtoBCHW(\n imageTensor: NdArray<Uint8Array>,\n mean: number[] = [128, 128, 128],\n std: number[] = [256, 256, 256]\n): NdArray<Float32Array> {\n var imageBufferData = imageTensor.data;\n const [srcHeight, srcWidth, srcChannels] = imageTensor.shape;\n const stride = srcHeight * srcWidth;\n const float32Data = new Float32Array(3 * stride);\n\n // r_0, r_1, .... g_0,g_1, .... b_0\n for (let i = 0, j = 0; i < imageBufferData.length; i += 4, j += 1) {\n float32Data[j] = (imageBufferData[i] - mean[0]) / std[0];\n float32Data[j + stride] = (imageBufferData[i + 1] - mean[1]) / std[1];\n float32Data[j + stride + stride] =\n (imageBufferData[i + 2] - mean[2]) / std[2];\n }\n\n return ndarray(float32Data, [1, 3, srcHeight, srcWidth]);\n}\n\nasync function imageSourceToImageData(\n image: ImageSource,\n config: Config\n): Promise<NdArray<Uint8Array>> {\n if (typeof image === 'string') {\n image = ensureAbsoluteURI(image, config.publicPath);\n image = new URL(image);\n }\n if (image instanceof URL) {\n const response = await fetch(image, {});\n image = await response.blob();\n }\n if (image instanceof ArrayBuffer || ArrayBuffer.isView(image)) {\n image = new Blob([image]);\n }\n if (image instanceof Blob) {\n image = await imageDecode(image);\n }\n\n return image as NdArray<Uint8Array>;\n}\nexport function convertFloat32ToUint8(\n float32Array: NdArray<Float32Array>\n): NdArray<Uint8Array> {\n const uint8Array = new Uint8Array(float32Array.data.length);\n for (let i = 0; i < float32Array.data.length; i++) {\n uint8Array[i] = float32Array.data[i] * 255;\n }\n return ndarray(uint8Array, float32Array.shape);\n}\n\nfunction createCanvas(width, height) {\n let canvas = undefined;\n if (typeof OffscreenCanvas !== 'undefined') {\n canvas = new OffscreenCanvas(width, height);\n } else {\n canvas = document.createElement('canvas');\n }\n\n if (!canvas) {\n throw new Error(\n `Canvas nor OffscreenCanvas are available in the current context.`\n );\n }\n return canvas;\n}\n", "export class MimeType {\n type: string = 'application/octet-stream';\n params: Record<string, string> = {};\n\n private constructor(type: string, params: Record<string, string>) {\n this.type = type;\n this.params = params;\n }\n\n toString(): string {\n const paramsStr = [];\n for (const key in this.params) {\n const value = this.params[key];\n paramsStr.push(`${key}=${value}`);\n }\n return [this.type, ...paramsStr].join(';');\n }\n\n static create(type, params: Record<string, string>): MimeType {\n return new MimeType(type, params);\n }\n\n isIdentical(other: MimeType): Boolean {\n return this.type === other.type && this.params === other.params;\n }\n\n isEqual(other: MimeType): Boolean {\n return this.type === other.type;\n }\n\n static fromString(mimeType: string): MimeType {\n const [type, ...paramsArr] = mimeType.split(';');\n const params: Record<string, string> = {};\n\n for (const param of paramsArr) {\n const [key, value] = param.split('=');\n params[key.trim()] = value.trim();\n }\n return new MimeType(type, params);\n }\n}\n", "export { imageEncode, imageDecode, MimeType };\nimport { MimeType } from './MimeType';\nimport { imageBitmapToImageData, createCanvas } from './utils';\nimport ndarray, { NdArray } from 'ndarray';\n\nasync function imageDecode(blob: Blob): Promise<NdArray<Uint8Array>> {\n const mime = MimeType.fromString(blob.type);\n\n switch (mime.type) {\n case 'image/x-alpha8': {\n const width = parseInt(mime.params['width']);\n const height = parseInt(mime.params['height']);\n return ndarray(new Uint8Array(await blob.arrayBuffer()), [\n height,\n width,\n 1\n ]);\n }\n case 'image/x-rgba8': {\n const width = parseInt(mime.params['width']);\n const height = parseInt(mime.params['height']);\n return ndarray(new Uint8Array(await blob.arrayBuffer()), [\n height,\n width,\n 4\n ]);\n }\n case 'application/octet-stream': // this is an unknwon type\n case `image/png`:\n case `image/jpeg`:\n case `image/jpg`:\n case `image/webp`: {\n const imageBitmap = await createImageBitmap(blob);\n const imageData = imageBitmapToImageData(imageBitmap);\n return ndarray(new Uint8Array(imageData.data), [\n imageData.height,\n imageData.width,\n 4\n ]);\n }\n default:\n throw new Error(\n `Invalid format: ${mime.type} with params: ${mime.params}`\n );\n }\n}\n\nasync function imageEncode(\n imageTensor: NdArray<Uint8Array>,\n quality: number = 0.8,\n format: string = 'image/png'\n): Promise<Blob> {\n const [height, width, channels] = imageTensor.shape;\n\n switch (format) {\n case 'image/x-alpha8':\n case 'image/x-rgba8': {\n const mime = MimeType.create(format, {\n width: width.toString(),\n height: height.toString()\n });\n return new Blob([imageTensor.data], { type: mime.toString() });\n }\n case `image/png`:\n case `image/jpeg`:\n case `image/webp`: {\n const imageData = new ImageData(\n new Uint8ClampedArray(imageTensor.data),\n width,\n height\n );\n var canvas = createCanvas(imageData.width, imageData.height);\n var ctx = canvas.getContext('2d')!;\n ctx.putImageData(imageData, 0, 0);\n return canvas.convertToBlob({ quality, type: format });\n }\n default:\n throw new Error(`Invalid format: ${format}`);\n }\n}\n", "export { isAbsoluteURI, ensureAbsoluteURI };\n\nfunction isAbsoluteURI(url: string): boolean {\n const regExp = new RegExp('^(?:[a-z+]+:)?//', 'i');\n return regExp.test(url); // true - regular http absolute URL\n}\n\nconst isNode = typeof window === 'undefined';\nconst isBrowser = typeof window !== 'undefined';\n\nfunction ensureAbsoluteURI(url: string, baseUrl: string): string {\n if (isAbsoluteURI(url)) {\n return url;\n } else {\n return new URL(url, baseUrl).href;\n }\n}\n", "export { createOnnxSession, runOnnxSession };\n\nimport ndarray, { NdArray } from 'ndarray';\nimport { InferenceSession, Tensor } from 'onnxruntime-web';\nimport * as caps from './capabilities';\nimport { loadAsUrl } from './resource';\nimport { Config } from './schema';\n\ntype ORT = typeof import('onnxruntime-web');\n// use a dynamic import to avoid bundling the entire onnxruntime-web package\nlet ort: ORT | null = null;\nconst getOrt = async (useWebGPU: boolean): Promise<ORT> => {\n if (ort !== null) {\n return ort;\n }\n if (useWebGPU) {\n ort = (await import('onnxruntime-web/webgpu')).default;\n } else {\n ort = (await import('onnxruntime-web')).default;\n }\n return ort;\n};\n\nasync function createOnnxSession(model: any, config: Config) {\n const useWebGPU = config.device === 'gpu' && (await caps.webgpu());\n // BUG: proxyToWorker is not working for WASM/CPU Backend for now\n const proxyToWorker = useWebGPU && config.proxyToWorker;\n const executionProviders = [useWebGPU ? 'webgpu' : 'wasm'];\n const ort = await getOrt(useWebGPU);\n\n if (config.debug) {\n console.debug('\\tUsing WebGPU:', useWebGPU);\n console.debug('\\tProxy to Worker:', proxyToWorker);\n\n ort.env.debug = true;\n ort.env.logLevel = 'verbose';\n }\n\n ort.env.wasm.numThreads = caps.maxNumThreads();\n ort.env.wasm.proxy = proxyToWorker;\n\n // The path inside the resource bundle\n const baseFilePath = useWebGPU\n ? '/onnxruntime-web/ort-wasm-simd-threaded.jsep'\n : '/onnxruntime-web/ort-wasm-simd-threaded';\n\n const wasmPath = await loadAsUrl(`${baseFilePath}.wasm`, config);\n const mjsPath = await loadAsUrl(`${baseFilePath}.mjs`, config);\n\n ort.env.wasm.wasmPaths = {\n mjs: mjsPath,\n wasm: wasmPath\n };\n\n if (config.debug) {\n console.debug('ort.env.wasm:', ort.env.wasm);\n }\n\n const ortConfig: InferenceSession.SessionOptions = {\n executionProviders: executionProviders,\n graphOptimizationLevel: 'all',\n executionMode: 'parallel',\n enableCpuMemArena: true\n };\n\n const session = await ort.InferenceSession.create(model, ortConfig).catch(\n (e: any) => {\n throw new Error(\n `Failed to create session: \"${e}\". Please check if the publicPath is set correctly.`\n );\n }\n );\n return session;\n}\n\nasync function runOnnxSession(\n session: any,\n inputs: [string, NdArray<Float32Array>][],\n outputs: [string],\n config: Config\n) {\n const useWebGPU = config.device === 'gpu' && (await caps.webgpu());\n const ort = await getOrt(useWebGPU);\n\n const feeds: Record<string, any> = {};\n for (const [key, tensor] of inputs) {\n feeds[key] = new ort.Tensor(\n 'float32',\n new Float32Array(tensor.data),\n tensor.shape\n );\n }\n const outputData = await session.run(feeds, {});\n const outputKVPairs: NdArray<Float32Array>[] = [];\n for (const