squoosh_png.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.encode = encode;
  6. exports.decode = decode;
  7. exports.cleanup = cleanup;
  8. exports.default = void 0;
  9. let wasm;
  10. let cachedTextDecoder = new TextDecoder("utf-8", {
  11. ignoreBOM: true,
  12. fatal: true
  13. });
  14. cachedTextDecoder.decode();
  15. let cachegetUint8Memory0 = null;
  16. function getUint8Memory0() {
  17. if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
  18. cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
  19. }
  20. return cachegetUint8Memory0;
  21. }
  22. function getStringFromWasm0(ptr, len) {
  23. return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
  24. }
  25. let cachegetUint8ClampedMemory0 = null;
  26. function getUint8ClampedMemory0() {
  27. if (cachegetUint8ClampedMemory0 === null || cachegetUint8ClampedMemory0.buffer !== wasm.memory.buffer) {
  28. cachegetUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
  29. }
  30. return cachegetUint8ClampedMemory0;
  31. }
  32. function getClampedArrayU8FromWasm0(ptr, len) {
  33. return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len);
  34. }
  35. const heap = new Array(32).fill(undefined);
  36. heap.push(undefined, null, true, false);
  37. let heap_next = heap.length;
  38. function addHeapObject(obj) {
  39. if (heap_next === heap.length) heap.push(heap.length + 1);
  40. const idx = heap_next;
  41. heap_next = heap[idx];
  42. heap[idx] = obj;
  43. return idx;
  44. }
  45. let WASM_VECTOR_LEN = 0;
  46. function passArray8ToWasm0(arg, malloc) {
  47. const ptr = malloc(arg.length * 1);
  48. getUint8Memory0().set(arg, ptr / 1);
  49. WASM_VECTOR_LEN = arg.length;
  50. return ptr;
  51. }
  52. let cachegetInt32Memory0 = null;
  53. function getInt32Memory0() {
  54. if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
  55. cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
  56. }
  57. return cachegetInt32Memory0;
  58. }
  59. function getArrayU8FromWasm0(ptr, len) {
  60. return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
  61. }
  62. function encode(data, width, height) {
  63. try {
  64. const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
  65. var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
  66. var len0 = WASM_VECTOR_LEN;
  67. wasm.encode(retptr, ptr0, len0, width, height);
  68. var r0 = getInt32Memory0()[retptr / 4 + 0];
  69. var r1 = getInt32Memory0()[retptr / 4 + 1];
  70. var v1 = getArrayU8FromWasm0(r0, r1).slice();
  71. wasm.__wbindgen_free(r0, r1 * 1);
  72. return v1;
  73. } finally{
  74. wasm.__wbindgen_add_to_stack_pointer(16);
  75. }
  76. }
  77. function getObject(idx) {
  78. return heap[idx];
  79. }
  80. function dropObject(idx) {
  81. if (idx < 36) return;
  82. heap[idx] = heap_next;
  83. heap_next = idx;
  84. }
  85. function takeObject(idx) {
  86. const ret = getObject(idx);
  87. dropObject(idx);
  88. return ret;
  89. }
  90. function decode(data) {
  91. var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
  92. var len0 = WASM_VECTOR_LEN;
  93. var ret = wasm.decode(ptr0, len0);
  94. return takeObject(ret);
  95. }
  96. async function load(module, imports) {
  97. if (typeof Response === "function" && module instanceof Response) {
  98. if (typeof WebAssembly.instantiateStreaming === "function") {
  99. return await WebAssembly.instantiateStreaming(module, imports);
  100. }
  101. const bytes = await module.arrayBuffer();
  102. return await WebAssembly.instantiate(bytes, imports);
  103. } else {
  104. const instance = await WebAssembly.instantiate(module, imports);
  105. if (instance instanceof WebAssembly.Instance) {
  106. return {
  107. instance,
  108. module
  109. };
  110. } else {
  111. return instance;
  112. }
  113. }
  114. }
  115. async function init(input) {
  116. const imports = {};
  117. imports.wbg = {};
  118. imports.wbg.__wbg_newwithownedu8clampedarrayandsh_787b2db8ea6bfd62 = function(arg0, arg1, arg2, arg3) {
  119. var v0 = getClampedArrayU8FromWasm0(arg0, arg1).slice();
  120. wasm.__wbindgen_free(arg0, arg1 * 1);
  121. var ret = new ImageData(v0, arg2 >>> 0, arg3 >>> 0);
  122. return addHeapObject(ret);
  123. };
  124. imports.wbg.__wbindgen_throw = function(arg0, arg1) {
  125. throw new Error(getStringFromWasm0(arg0, arg1));
  126. };
  127. if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
  128. input = fetch(input);
  129. }
  130. const { instance , module } = await load(await input, imports);
  131. wasm = instance.exports;
  132. init.__wbindgen_wasm_module = module;
  133. return wasm;
  134. }
  135. var _default = init;
  136. exports.default = _default;
  137. function cleanup() {
  138. wasm = null;
  139. cachegetUint8ClampedMemory0 = null;
  140. cachegetUint8Memory0 = null;
  141. cachegetInt32Memory0 = null;
  142. }
  143. //# sourceMappingURL=squoosh_png.js.map