@babylonjs/ktx2decoder 6.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Misc/dataReader.d.ts +65 -0
- package/Misc/dataReader.js +116 -0
- package/Misc/dataReader.js.map +1 -0
- package/Misc/index.d.ts +1 -0
- package/Misc/index.js +2 -0
- package/Misc/index.js.map +1 -0
- package/Transcoders/index.d.ts +8 -0
- package/Transcoders/index.js +9 -0
- package/Transcoders/index.js.map +1 -0
- package/Transcoders/liteTranscoder.d.ts +25 -0
- package/Transcoders/liteTranscoder.js +63 -0
- package/Transcoders/liteTranscoder.js.map +1 -0
- package/Transcoders/liteTranscoder_UASTC_ASTC.d.ts +19 -0
- package/Transcoders/liteTranscoder_UASTC_ASTC.js +29 -0
- package/Transcoders/liteTranscoder_UASTC_ASTC.js.map +1 -0
- package/Transcoders/liteTranscoder_UASTC_BC7.d.ts +19 -0
- package/Transcoders/liteTranscoder_UASTC_BC7.js +29 -0
- package/Transcoders/liteTranscoder_UASTC_BC7.js.map +1 -0
- package/Transcoders/liteTranscoder_UASTC_R8_UNORM.d.ts +21 -0
- package/Transcoders/liteTranscoder_UASTC_R8_UNORM.js +36 -0
- package/Transcoders/liteTranscoder_UASTC_R8_UNORM.js.map +1 -0
- package/Transcoders/liteTranscoder_UASTC_RG8_UNORM.d.ts +21 -0
- package/Transcoders/liteTranscoder_UASTC_RG8_UNORM.js +36 -0
- package/Transcoders/liteTranscoder_UASTC_RG8_UNORM.js.map +1 -0
- package/Transcoders/liteTranscoder_UASTC_RGBA_SRGB.d.ts +21 -0
- package/Transcoders/liteTranscoder_UASTC_RGBA_SRGB.js +36 -0
- package/Transcoders/liteTranscoder_UASTC_RGBA_SRGB.js.map +1 -0
- package/Transcoders/liteTranscoder_UASTC_RGBA_UNORM.d.ts +21 -0
- package/Transcoders/liteTranscoder_UASTC_RGBA_UNORM.js +36 -0
- package/Transcoders/liteTranscoder_UASTC_RGBA_UNORM.js.map +1 -0
- package/Transcoders/mscTranscoder.d.ts +32 -0
- package/Transcoders/mscTranscoder.js +128 -0
- package/Transcoders/mscTranscoder.js.map +1 -0
- package/index.d.ts +8 -0
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/ktx2Decoder.d.ts +22 -0
- package/ktx2Decoder.js +144 -0
- package/ktx2Decoder.js.map +1 -0
- package/ktx2FileReader.d.ts +109 -0
- package/ktx2FileReader.js +219 -0
- package/ktx2FileReader.js.map +1 -0
- package/legacy/legacy.d.ts +1 -0
- package/legacy/legacy.js +8 -0
- package/legacy/legacy.js.map +1 -0
- package/license.md +71 -0
- package/package.json +49 -0
- package/readme.md +1 -0
- package/transcodeDecisionTree.d.ts +18 -0
- package/transcodeDecisionTree.js +240 -0
- package/transcodeDecisionTree.js.map +1 -0
- package/transcoder.d.ts +17 -0
- package/transcoder.js +28 -0
- package/transcoder.js.map +1 -0
- package/transcoderManager.d.ts +13 -0
- package/transcoderManager.js +50 -0
- package/transcoderManager.js.map +1 -0
- package/wasm/license.md +361 -0
- package/wasm/msc_basis_transcoder.js +21 -0
- package/wasm/msc_basis_transcoder.wasm +0 -0
- package/wasm/uastc_astc.wasm +0 -0
- package/wasm/uastc_bc7.wasm +0 -0
- package/wasm/uastc_r8_unorm.wasm +0 -0
- package/wasm/uastc_rg8_unorm.wasm +0 -0
- package/wasm/uastc_rgba8_srgb_v2.wasm +0 -0
- package/wasm/uastc_rgba8_unorm_v2.wasm +0 -0
- package/wasmMemoryManager.d.ts +17 -0
- package/wasmMemoryManager.js +63 -0
- package/wasmMemoryManager.js.map +1 -0
- package/zstddec.d.ts +41 -0
- package/zstddec.js +95 -0
- package/zstddec.js.map +1 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"wasmMemoryManager.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/wasmMemoryManager.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAMnB,MAAM,CAAC,QAAQ,C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C;YACxC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC;SACnC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;;AAzEa,+CAA6B,GAAG,IAAI,CAAC;AACrC,oCAAkB,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW;AAExD,4BAAU,GAAG,CAAC,CAAC","sourcesContent":["declare function postMessage(message: any, transfer?: any[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class WASMMemoryManager {\r\n public static LoadBinariesFromCurrentThread = true;\r\n public static InitialMemoryPages = (1 * 1024 * 1024) >> 16; // 1 Mbytes\r\n\r\n private static _RequestId = 0;\r\n\r\n public static LoadWASM(path: string): Promise<ArrayBuffer> {\r\n if (this.LoadBinariesFromCurrentThread) {\r\n return new Promise((resolve, reject) => {\r\n fetch(path)\r\n .then((response) => {\r\n if (response.ok) {\r\n return response.arrayBuffer();\r\n }\r\n throw new Error(`Could not fetch the wasm component from \"${path}\": ${response.status} - ${response.statusText}`);\r\n })\r\n .then((wasmBinary) => resolve(wasmBinary))\r\n .catch((reason) => {\r\n reject(reason);\r\n });\r\n });\r\n }\r\n\r\n const id = this._RequestId++;\r\n\r\n return new Promise((resolve) => {\r\n const wasmLoadedHandler = (msg: any) => {\r\n if (msg.data.action === \"wasmLoaded\" && msg.data.id === id) {\r\n self.removeEventListener(\"message\", wasmLoadedHandler);\r\n resolve(msg.data.wasmBinary);\r\n }\r\n };\r\n\r\n self.addEventListener(\"message\", wasmLoadedHandler);\r\n\r\n postMessage({ action: \"loadWASM\", path: path, id: id });\r\n });\r\n }\r\n\r\n private _memory: WebAssembly.Memory;\r\n private _numPages: number;\r\n private _memoryView: Uint8Array;\r\n private _memoryViewByteLength: number;\r\n private _memoryViewOffset: number;\r\n\r\n constructor(initialMemoryPages: number = WASMMemoryManager.InitialMemoryPages) {\r\n this._numPages = initialMemoryPages;\r\n\r\n this._memory = new WebAssembly.Memory({ initial: this._numPages });\r\n this._memoryViewByteLength = this._numPages << 16;\r\n this._memoryViewOffset = 0;\r\n this._memoryView = new Uint8Array(this._memory.buffer, this._memoryViewOffset, this._memoryViewByteLength);\r\n }\r\n\r\n public get wasmMemory(): WebAssembly.Memory {\r\n return this._memory;\r\n }\r\n\r\n public getMemoryView(numPages: number, offset: number = 0, byteLength?: number): Uint8Array {\r\n byteLength = byteLength ?? numPages << 16;\r\n\r\n if (this._numPages < numPages) {\r\n this._memory.grow(numPages - this._numPages);\r\n this._numPages = numPages;\r\n this._memoryView = new Uint8Array(this._memory.buffer, offset, byteLength);\r\n this._memoryViewByteLength = byteLength;\r\n this._memoryViewOffset = offset;\r\n } else {\r\n this._memoryView = new Uint8Array(this._memory.buffer, offset, byteLength);\r\n this._memoryViewByteLength = byteLength;\r\n this._memoryViewOffset = offset;\r\n }\r\n\r\n return this._memoryView;\r\n }\r\n}\r\n"]}
|
package/zstddec.d.ts
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
/**
|
2
|
+
* ZSTD (Zstandard) decoder.
|
3
|
+
*/
|
4
|
+
export declare class ZSTDDecoder {
|
5
|
+
static WasmModuleURL: string;
|
6
|
+
init(): Promise<void>;
|
7
|
+
_init(result: WebAssembly.WebAssemblyInstantiatedSource): void;
|
8
|
+
decode(array: Uint8Array, uncompressedSize?: number): Uint8Array;
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* BSD License
|
12
|
+
*
|
13
|
+
* For Zstandard software
|
14
|
+
*
|
15
|
+
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.
|
16
|
+
*
|
17
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
18
|
+
* are permitted provided that the following conditions are met:
|
19
|
+
*
|
20
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
21
|
+
* list of conditions and the following disclaimer.
|
22
|
+
*
|
23
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
24
|
+
* this list of conditions and the following disclaimer in the documentation
|
25
|
+
* and/or other materials provided with the distribution.
|
26
|
+
*
|
27
|
+
* * Neither the name Facebook nor the names of its contributors may be used to
|
28
|
+
* endorse or promote products derived from this software without specific
|
29
|
+
* prior written permission.
|
30
|
+
*
|
31
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
32
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
33
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
34
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
35
|
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
36
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
37
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
38
|
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
39
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
40
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
41
|
+
*/
|
package/zstddec.js
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
2
|
+
import { Transcoder } from "./transcoder.js";
|
3
|
+
let init;
|
4
|
+
let instance;
|
5
|
+
let heap;
|
6
|
+
const IMPORT_OBJECT = {
|
7
|
+
env: {
|
8
|
+
emscripten_notify_memory_growth: function () {
|
9
|
+
heap = new Uint8Array(instance.exports.memory.buffer);
|
10
|
+
},
|
11
|
+
},
|
12
|
+
};
|
13
|
+
/**
|
14
|
+
* ZSTD (Zstandard) decoder.
|
15
|
+
*/
|
16
|
+
export class ZSTDDecoder {
|
17
|
+
init() {
|
18
|
+
if (init) {
|
19
|
+
return init;
|
20
|
+
}
|
21
|
+
if (typeof fetch !== "undefined") {
|
22
|
+
// Web.
|
23
|
+
init = fetch(Transcoder.GetWasmUrl(ZSTDDecoder.WasmModuleURL))
|
24
|
+
.then((response) => {
|
25
|
+
if (response.ok) {
|
26
|
+
return response.arrayBuffer();
|
27
|
+
}
|
28
|
+
throw new Error(`Could not fetch the wasm component for the Zstandard decompression lib: ${response.status} - ${response.statusText}`);
|
29
|
+
})
|
30
|
+
.then((arrayBuffer) => WebAssembly.instantiate(arrayBuffer, IMPORT_OBJECT))
|
31
|
+
.then(this._init);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
// Node.js.
|
35
|
+
init = WebAssembly.instantiateStreaming(fetch(ZSTDDecoder.WasmModuleURL), IMPORT_OBJECT).then(this._init);
|
36
|
+
}
|
37
|
+
return init;
|
38
|
+
}
|
39
|
+
_init(result) {
|
40
|
+
instance = result.instance;
|
41
|
+
IMPORT_OBJECT.env.emscripten_notify_memory_growth(); // initialize heap.
|
42
|
+
}
|
43
|
+
decode(array, uncompressedSize = 0) {
|
44
|
+
if (!instance) {
|
45
|
+
throw new Error(`ZSTDDecoder: Await .init() before decoding.`);
|
46
|
+
}
|
47
|
+
// Write compressed data into WASM memory.
|
48
|
+
const compressedSize = array.byteLength;
|
49
|
+
const compressedPtr = instance.exports.malloc(compressedSize);
|
50
|
+
heap.set(array, compressedPtr);
|
51
|
+
// Decompress into WASM memory.
|
52
|
+
uncompressedSize = uncompressedSize || Number(instance.exports.ZSTD_findDecompressedSize(compressedPtr, compressedSize));
|
53
|
+
const uncompressedPtr = instance.exports.malloc(uncompressedSize);
|
54
|
+
const actualSize = instance.exports.ZSTD_decompress(uncompressedPtr, uncompressedSize, compressedPtr, compressedSize);
|
55
|
+
// Read decompressed data and free WASM memory.
|
56
|
+
const dec = heap.slice(uncompressedPtr, uncompressedPtr + actualSize);
|
57
|
+
instance.exports.free(compressedPtr);
|
58
|
+
instance.exports.free(uncompressedPtr);
|
59
|
+
return dec;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
ZSTDDecoder.WasmModuleURL = "https://cdn.babylonjs.com/zstddec.wasm";
|
63
|
+
/**
|
64
|
+
* BSD License
|
65
|
+
*
|
66
|
+
* For Zstandard software
|
67
|
+
*
|
68
|
+
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.
|
69
|
+
*
|
70
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
71
|
+
* are permitted provided that the following conditions are met:
|
72
|
+
*
|
73
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
74
|
+
* list of conditions and the following disclaimer.
|
75
|
+
*
|
76
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
77
|
+
* this list of conditions and the following disclaimer in the documentation
|
78
|
+
* and/or other materials provided with the distribution.
|
79
|
+
*
|
80
|
+
* * Neither the name Facebook nor the names of its contributors may be used to
|
81
|
+
* endorse or promote products derived from this software without specific
|
82
|
+
* prior written permission.
|
83
|
+
*
|
84
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
85
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
86
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
87
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
88
|
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
89
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
90
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
91
|
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
92
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
93
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
94
|
+
*/
|
95
|
+
//# sourceMappingURL=zstddec.js.map
|
package/zstddec.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"zstddec.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/zstddec.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAc1C,IAAI,IAAmB,CAAC;AACxB,IAAI,QAAqC,CAAC;AAC1C,IAAI,IAAgB,CAAC;AAErB,MAAM,aAAa,GAAG;IAClB,GAAG,EAAE;QACD,+BAA+B,EAAE;YAC7B,IAAI,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1D,CAAC;KACJ;CACJ,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,WAAW;IAGpB,IAAI;QACA,IAAI,IAAI,EAAE;YACN,OAAO,IAAI,CAAC;SACf;QAED,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAC9B,OAAO;YAEP,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;iBACzD,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACf,IAAI,QAAQ,CAAC,EAAE,EAAE;oBACb,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;iBACjC;gBACD,MAAM,IAAI,KAAK,CAAC,2EAA2E,QAAQ,CAAC,MAAM,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YAC3I,CAAC,CAAC;iBACD,IA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AAC,KAAK,CAAC,eAAe,EAAE,eAAe,GAAG,UAAU,CAAC,CAAC;QACtE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACrC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAEvC,OAAO,GAAG,CAAC;IACf,CAAC;;AAvDa,yBAAa,GAAG,wCAAwC,CAAC;AA0D3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\n\r\nimport { Transcoder } from \"./transcoder\";\r\n\r\n/**\r\n * From https://github.com/donmccurdy/zstddec by Don McCurdy\r\n */\r\ninterface DecoderExports {\r\n memory: Uint8Array;\r\n\r\n ZSTD_findDecompressedSize: (compressedPtr: number, compressedSize: number) => number;\r\n ZSTD_decompress: (uncompressedPtr: number, uncompressedSize: number, compressedPtr: number, compressedSize: number) => number;\r\n malloc: (ptr: number) => number;\r\n free: (ptr: number) => void;\r\n}\r\n\r\nlet init: Promise<void>;\r\nlet instance: { exports: DecoderExports };\r\nlet heap: Uint8Array;\r\n\r\nconst IMPORT_OBJECT = {\r\n env: {\r\n emscripten_notify_memory_growth: function (): void {\r\n heap = new Uint8Array(instance.exports.memory.buffer);\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * ZSTD (Zstandard) decoder.\r\n */\r\nexport class ZSTDDecoder {\r\n public static WasmModuleURL = \"https://cdn.babylonjs.com/zstddec.wasm\";\r\n\r\n init(): Promise<void> {\r\n if (init) {\r\n return init;\r\n }\r\n\r\n if (typeof fetch !== \"undefined\") {\r\n // Web.\r\n\r\n init = fetch(Transcoder.GetWasmUrl(ZSTDDecoder.WasmModuleURL))\r\n .then((response) => {\r\n if (response.ok) {\r\n return response.arrayBuffer();\r\n }\r\n throw new Error(`Could not fetch the wasm component for the Zstandard decompression lib: ${response.status} - ${response.statusText}`);\r\n })\r\n .then((arrayBuffer) => WebAssembly.instantiate(arrayBuffer, IMPORT_OBJECT))\r\n .then(this._init);\r\n } else {\r\n // Node.js.\r\n\r\n init = WebAssembly.instantiateStreaming(fetch(ZSTDDecoder.WasmModuleURL), IMPORT_OBJECT).then(this._init);\r\n }\r\n\r\n return init;\r\n }\r\n\r\n _init(result: WebAssembly.WebAssemblyInstantiatedSource): void {\r\n instance = result.instance as unknown as { exports: DecoderExports };\r\n\r\n IMPORT_OBJECT.env.emscripten_notify_memory_growth(); // initialize heap.\r\n }\r\n\r\n decode(array: Uint8Array, uncompressedSize = 0): Uint8Array {\r\n if (!instance) {\r\n throw new Error(`ZSTDDecoder: Await .init() before decoding.`);\r\n }\r\n\r\n // Write compressed data into WASM memory.\r\n const compressedSize = array.byteLength;\r\n const compressedPtr = instance.exports.malloc(compressedSize);\r\n heap.set(array, compressedPtr);\r\n\r\n // Decompress into WASM memory.\r\n uncompressedSize = uncompressedSize || Number(instance.exports.ZSTD_findDecompressedSize(compressedPtr, compressedSize));\r\n const uncompressedPtr = instance.exports.malloc(uncompressedSize);\r\n const actualSize = instance.exports.ZSTD_decompress(uncompressedPtr, uncompressedSize, compressedPtr, compressedSize);\r\n\r\n // Read decompressed data and free WASM memory.\r\n const dec = heap.slice(uncompressedPtr, uncompressedPtr + actualSize);\r\n instance.exports.free(compressedPtr);\r\n instance.exports.free(uncompressedPtr);\r\n\r\n return dec;\r\n }\r\n}\r\n\r\n/**\r\n * BSD License\r\n *\r\n * For Zstandard software\r\n *\r\n * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.\r\n *\r\n * Redistribution and use in source and binary forms, with or without modification,\r\n * are permitted provided that the following conditions are met:\r\n *\r\n * * Redistributions of source code must retain the above copyright notice, this\r\n * list of conditions and the following disclaimer.\r\n *\r\n * * Redistributions in binary form must reproduce the above copyright notice,\r\n * this list of conditions and the following disclaimer in the documentation\r\n * and/or other materials provided with the distribution.\r\n *\r\n * * Neither the name Facebook nor the names of its contributors may be used to\r\n * endorse or promote products derived from this software without specific\r\n * prior written permission.\r\n *\r\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\r\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r\n * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\r\n * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r\n * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r\n * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r\n * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n */\r\n"]}
|