@myoc/element 0.19.544 → 0.19.545
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/dist/dev/gif.worker.js +321 -0
- package/dist/dev/gif.worker.js.map +7 -0
- package/dist/dev/index.js +334 -500
- package/dist/dev/index.js.map +4 -4
- package/dist/dev/squoosh_gif_bg.wasm +0 -0
- package/dist/prod/gif.worker.js +1 -0
- package/dist/prod/index.js +16 -16
- package/dist/prod/squoosh_gif_bg.wasm +0 -0
- package/dist/types/element/src/gif.worker.d.ts +1 -0
- package/package.json +6 -6
package/dist/dev/index.js
CHANGED
|
@@ -1284,8 +1284,8 @@ var require_react_development = __commonJS({
|
|
|
1284
1284
|
exports.useOptimistic = function(passthrough, reducer) {
|
|
1285
1285
|
return resolveDispatcher().useOptimistic(passthrough, reducer);
|
|
1286
1286
|
};
|
|
1287
|
-
exports.useReducer = function(reducer, initialArg,
|
|
1288
|
-
return resolveDispatcher().useReducer(reducer, initialArg,
|
|
1287
|
+
exports.useReducer = function(reducer, initialArg, init2) {
|
|
1288
|
+
return resolveDispatcher().useReducer(reducer, initialArg, init2);
|
|
1289
1289
|
};
|
|
1290
1290
|
exports.useRef = function(initialValue) {
|
|
1291
1291
|
return resolveDispatcher().useRef(initialValue);
|
|
@@ -14696,511 +14696,301 @@ function thumbHashToApproximateAspectRatio(hash) {
|
|
|
14696
14696
|
// src/gif.ts
|
|
14697
14697
|
init_define_import_meta_env();
|
|
14698
14698
|
|
|
14699
|
-
// ../../node_modules/
|
|
14699
|
+
// ../../node_modules/@discourse/gif/index.js
|
|
14700
14700
|
init_define_import_meta_env();
|
|
14701
|
-
|
|
14702
|
-
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14706
|
-
|
|
14707
|
-
var
|
|
14708
|
-
|
|
14709
|
-
|
|
14710
|
-
|
|
14711
|
-
|
|
14712
|
-
|
|
14713
|
-
|
|
14714
|
-
|
|
14715
|
-
|
|
14716
|
-
|
|
14717
|
-
|
|
14718
|
-
|
|
14719
|
-
|
|
14720
|
-
|
|
14721
|
-
|
|
14722
|
-
|
|
14723
|
-
function resovleSource(source, output, options) {
|
|
14724
|
-
let buffer;
|
|
14725
|
-
if (ArrayBuffer.isView(source)) {
|
|
14726
|
-
buffer = source.buffer;
|
|
14727
|
-
} else if (source instanceof ArrayBuffer) {
|
|
14728
|
-
buffer = source;
|
|
14729
|
-
} else {
|
|
14730
|
-
const canvas = document.createElement("canvas");
|
|
14731
|
-
const { width, height } = options || {};
|
|
14732
|
-
const context2d = canvas.getContext("2d");
|
|
14733
|
-
if (!context2d) {
|
|
14734
|
-
throw new Error("Failed to create canvas context2d");
|
|
14735
|
-
}
|
|
14736
|
-
canvas.width = width ?? ("width" in source ? typeof source.width === "number" ? source.width : source.width.baseVal.value : 0);
|
|
14737
|
-
canvas.height = height ?? ("height" in source ? typeof source.height === "number" ? source.height : source.height.baseVal.value : 0);
|
|
14738
|
-
context2d.drawImage(source, 0, 0, canvas.width, canvas.height);
|
|
14739
|
-
buffer = context2d.getImageData(0, 0, canvas.width, canvas.height).data.buffer;
|
|
14740
|
-
}
|
|
14741
|
-
switch (output) {
|
|
14742
|
-
case "uint8Array":
|
|
14743
|
-
return new Uint8Array(buffer);
|
|
14744
|
-
case "uint8ClampedArray":
|
|
14745
|
-
return new Uint8ClampedArray(buffer);
|
|
14746
|
-
case "dataView":
|
|
14747
|
-
return new DataView(buffer);
|
|
14748
|
-
default:
|
|
14749
|
-
throw new Error("Unsupported output format");
|
|
14701
|
+
|
|
14702
|
+
// ../../node_modules/@discourse/gif/decode.js
|
|
14703
|
+
init_define_import_meta_env();
|
|
14704
|
+
|
|
14705
|
+
// ../../node_modules/@discourse/gif/codec/pkg/squoosh_gif.js
|
|
14706
|
+
init_define_import_meta_env();
|
|
14707
|
+
var GIFFrame = class _GIFFrame {
|
|
14708
|
+
static __wrap(ptr) {
|
|
14709
|
+
const obj = Object.create(_GIFFrame.prototype);
|
|
14710
|
+
obj.__wbg_ptr = ptr;
|
|
14711
|
+
GIFFrameFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
14712
|
+
return obj;
|
|
14713
|
+
}
|
|
14714
|
+
__destroy_into_raw() {
|
|
14715
|
+
const ptr = this.__wbg_ptr;
|
|
14716
|
+
this.__wbg_ptr = 0;
|
|
14717
|
+
GIFFrameFinalization.unregister(this);
|
|
14718
|
+
return ptr;
|
|
14719
|
+
}
|
|
14720
|
+
free() {
|
|
14721
|
+
const ptr = this.__destroy_into_raw();
|
|
14722
|
+
wasm.__wbg_gifframe_free(ptr, 0);
|
|
14750
14723
|
}
|
|
14751
|
-
|
|
14752
|
-
|
|
14753
|
-
|
|
14754
|
-
|
|
14755
|
-
|
|
14756
|
-
|
|
14724
|
+
/**
|
|
14725
|
+
* @returns {number}
|
|
14726
|
+
*/
|
|
14727
|
+
get duration() {
|
|
14728
|
+
const ret = wasm.gifframe_duration(this.__wbg_ptr);
|
|
14729
|
+
return ret >>> 0;
|
|
14757
14730
|
}
|
|
14758
|
-
|
|
14759
|
-
|
|
14731
|
+
/**
|
|
14732
|
+
* @returns {ImageData}
|
|
14733
|
+
*/
|
|
14734
|
+
get imageData() {
|
|
14735
|
+
const ret = wasm.gifframe_imageData(this.__wbg_ptr);
|
|
14736
|
+
return takeObject(ret);
|
|
14760
14737
|
}
|
|
14761
|
-
|
|
14762
|
-
|
|
14738
|
+
};
|
|
14739
|
+
if (Symbol.dispose)
|
|
14740
|
+
GIFFrame.prototype[Symbol.dispose] = GIFFrame.prototype.free;
|
|
14741
|
+
function decodeAnimated(data) {
|
|
14742
|
+
try {
|
|
14743
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
14744
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
14745
|
+
const len0 = WASM_VECTOR_LEN;
|
|
14746
|
+
wasm.decodeAnimated(retptr, ptr0, len0);
|
|
14747
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
14748
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
14749
|
+
var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
14750
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
14751
|
+
return v2;
|
|
14752
|
+
} finally {
|
|
14753
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
14763
14754
|
}
|
|
14764
|
-
|
|
14765
|
-
|
|
14755
|
+
}
|
|
14756
|
+
function __wbg_get_imports() {
|
|
14757
|
+
const import0 = {
|
|
14758
|
+
__proto__: null,
|
|
14759
|
+
__wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {
|
|
14760
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
14761
|
+
},
|
|
14762
|
+
__wbg_gifframe_new: function(arg0) {
|
|
14763
|
+
const ret = GIFFrame.__wrap(arg0);
|
|
14764
|
+
return addHeapObject(ret);
|
|
14765
|
+
},
|
|
14766
|
+
__wbg_new_with_owned_u8_clamped_array_and_sh_9b06742b45807291: function(arg0, arg1, arg2, arg3) {
|
|
14767
|
+
var v0 = getClampedArrayU8FromWasm0(arg0, arg1).slice();
|
|
14768
|
+
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
|
|
14769
|
+
const ret = new ImageData(v0, arg2 >>> 0, arg3 >>> 0);
|
|
14770
|
+
return addHeapObject(ret);
|
|
14771
|
+
},
|
|
14772
|
+
__wbindgen_object_clone_ref: function(arg0) {
|
|
14773
|
+
const ret = getObject(arg0);
|
|
14774
|
+
return addHeapObject(ret);
|
|
14775
|
+
},
|
|
14776
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
14777
|
+
takeObject(arg0);
|
|
14778
|
+
}
|
|
14779
|
+
};
|
|
14780
|
+
return {
|
|
14781
|
+
__proto__: null,
|
|
14782
|
+
"./squoosh_gif_bg.js": import0
|
|
14783
|
+
};
|
|
14784
|
+
}
|
|
14785
|
+
var GIFFrameFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
14786
|
+
}, unregister: () => {
|
|
14787
|
+
} } : new FinalizationRegistry((ptr) => wasm.__wbg_gifframe_free(ptr, 1));
|
|
14788
|
+
function addHeapObject(obj) {
|
|
14789
|
+
if (heap_next === heap.length)
|
|
14790
|
+
heap.push(heap.length + 1);
|
|
14791
|
+
const idx = heap_next;
|
|
14792
|
+
heap_next = heap[idx];
|
|
14793
|
+
heap[idx] = obj;
|
|
14794
|
+
return idx;
|
|
14795
|
+
}
|
|
14796
|
+
function dropObject(idx) {
|
|
14797
|
+
if (idx < 1028)
|
|
14798
|
+
return;
|
|
14799
|
+
heap[idx] = heap_next;
|
|
14800
|
+
heap_next = idx;
|
|
14801
|
+
}
|
|
14802
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
14803
|
+
ptr = ptr >>> 0;
|
|
14804
|
+
const mem = getDataViewMemory0();
|
|
14805
|
+
const result = [];
|
|
14806
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
14807
|
+
result.push(takeObject(mem.getUint32(i, true)));
|
|
14766
14808
|
}
|
|
14767
|
-
|
|
14768
|
-
|
|
14809
|
+
return result;
|
|
14810
|
+
}
|
|
14811
|
+
function getClampedArrayU8FromWasm0(ptr, len) {
|
|
14812
|
+
ptr = ptr >>> 0;
|
|
14813
|
+
return getUint8ClampedArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
14814
|
+
}
|
|
14815
|
+
var cachedDataViewMemory0 = null;
|
|
14816
|
+
function getDataViewMemory0() {
|
|
14817
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
|
|
14818
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
14769
14819
|
}
|
|
14770
|
-
|
|
14771
|
-
|
|
14820
|
+
return cachedDataViewMemory0;
|
|
14821
|
+
}
|
|
14822
|
+
function getStringFromWasm0(ptr, len) {
|
|
14823
|
+
return decodeText(ptr >>> 0, len);
|
|
14824
|
+
}
|
|
14825
|
+
var cachedUint8ArrayMemory0 = null;
|
|
14826
|
+
function getUint8ArrayMemory0() {
|
|
14827
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
14828
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
14772
14829
|
}
|
|
14773
|
-
|
|
14774
|
-
|
|
14830
|
+
return cachedUint8ArrayMemory0;
|
|
14831
|
+
}
|
|
14832
|
+
var cachedUint8ClampedArrayMemory0 = null;
|
|
14833
|
+
function getUint8ClampedArrayMemory0() {
|
|
14834
|
+
if (cachedUint8ClampedArrayMemory0 === null || cachedUint8ClampedArrayMemory0.byteLength === 0) {
|
|
14835
|
+
cachedUint8ClampedArrayMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
|
|
14775
14836
|
}
|
|
14776
|
-
|
|
14777
|
-
|
|
14778
|
-
|
|
14779
|
-
|
|
14780
|
-
|
|
14781
|
-
|
|
14782
|
-
|
|
14783
|
-
|
|
14784
|
-
|
|
14785
|
-
|
|
14786
|
-
|
|
14787
|
-
|
|
14788
|
-
|
|
14789
|
-
|
|
14790
|
-
|
|
14791
|
-
const
|
|
14792
|
-
|
|
14793
|
-
|
|
14794
|
-
|
|
14795
|
-
|
|
14796
|
-
|
|
14797
|
-
|
|
14798
|
-
|
|
14799
|
-
|
|
14800
|
-
|
|
14801
|
-
|
|
14802
|
-
|
|
14803
|
-
|
|
14804
|
-
|
|
14805
|
-
|
|
14806
|
-
|
|
14807
|
-
|
|
14808
|
-
|
|
14809
|
-
|
|
14810
|
-
|
|
14811
|
-
|
|
14812
|
-
|
|
14813
|
-
|
|
14814
|
-
|
|
14815
|
-
|
|
14816
|
-
|
|
14817
|
-
|
|
14818
|
-
|
|
14819
|
-
|
|
14820
|
-
|
|
14821
|
-
|
|
14822
|
-
|
|
14823
|
-
|
|
14824
|
-
|
|
14825
|
-
|
|
14826
|
-
|
|
14827
|
-
|
|
14828
|
-
|
|
14829
|
-
|
|
14830
|
-
|
|
14831
|
-
|
|
14832
|
-
frame.colorTableSize = 2 ** (colorTableSize2 + 1);
|
|
14833
|
-
if (frame.localColorTable) {
|
|
14834
|
-
frame.colorTable = reader.readColorTable(frame.colorTableSize);
|
|
14835
|
-
}
|
|
14836
|
-
frame.lzwMinCodeSize = reader.readByte();
|
|
14837
|
-
frame.dataPositions = [];
|
|
14838
|
-
while (true) {
|
|
14839
|
-
const length = reader.readByte();
|
|
14840
|
-
if (length === 0)
|
|
14841
|
-
break;
|
|
14842
|
-
const offset = reader.offset;
|
|
14843
|
-
frame.dataPositions.push([offset, length]);
|
|
14844
|
-
reader.offset = offset + length;
|
|
14845
|
-
}
|
|
14846
|
-
gif.frames.push(frame);
|
|
14847
|
-
frame = createFrame();
|
|
14848
|
-
frame.index = gif.frames.length;
|
|
14849
|
-
continue;
|
|
14850
|
-
}
|
|
14851
|
-
if (flag === EXTENSION) {
|
|
14852
|
-
const extensionFlag = reader.readByte();
|
|
14853
|
-
extensionFlags.push(extensionFlag);
|
|
14854
|
-
if (extensionFlag === EXTENSION_APPLICATION) {
|
|
14855
|
-
if (reader.readByte() !== EXTENSION_APPLICATION_BLOCK_SIZE)
|
|
14856
|
-
continue;
|
|
14857
|
-
const application = {
|
|
14858
|
-
identifier: reader.readString(8),
|
|
14859
|
-
code: reader.readString(3),
|
|
14860
|
-
data: []
|
|
14861
|
-
};
|
|
14862
|
-
if (`${application.identifier}${application.code}` === "NETSCAPE2.0") {
|
|
14863
|
-
if (reader.readByte() === 3) {
|
|
14864
|
-
gif.looped = Boolean(reader.readByte());
|
|
14865
|
-
gif.loopCount = reader.readUnsigned();
|
|
14866
|
-
}
|
|
14837
|
+
return cachedUint8ClampedArrayMemory0;
|
|
14838
|
+
}
|
|
14839
|
+
function getObject(idx) {
|
|
14840
|
+
return heap[idx];
|
|
14841
|
+
}
|
|
14842
|
+
var heap = new Array(1024).fill(void 0);
|
|
14843
|
+
heap.push(void 0, null, true, false);
|
|
14844
|
+
var heap_next = heap.length;
|
|
14845
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
14846
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
14847
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
14848
|
+
WASM_VECTOR_LEN = arg.length;
|
|
14849
|
+
return ptr;
|
|
14850
|
+
}
|
|
14851
|
+
function takeObject(idx) {
|
|
14852
|
+
const ret = getObject(idx);
|
|
14853
|
+
dropObject(idx);
|
|
14854
|
+
return ret;
|
|
14855
|
+
}
|
|
14856
|
+
var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
14857
|
+
cachedTextDecoder.decode();
|
|
14858
|
+
var MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
14859
|
+
var numBytesDecoded = 0;
|
|
14860
|
+
function decodeText(ptr, len) {
|
|
14861
|
+
numBytesDecoded += len;
|
|
14862
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
14863
|
+
cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
14864
|
+
cachedTextDecoder.decode();
|
|
14865
|
+
numBytesDecoded = len;
|
|
14866
|
+
}
|
|
14867
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
14868
|
+
}
|
|
14869
|
+
var WASM_VECTOR_LEN = 0;
|
|
14870
|
+
var wasmModule;
|
|
14871
|
+
var wasmInstance;
|
|
14872
|
+
var wasm;
|
|
14873
|
+
function __wbg_finalize_init(instance, module) {
|
|
14874
|
+
wasmInstance = instance;
|
|
14875
|
+
wasm = instance.exports;
|
|
14876
|
+
wasmModule = module;
|
|
14877
|
+
cachedDataViewMemory0 = null;
|
|
14878
|
+
cachedUint8ArrayMemory0 = null;
|
|
14879
|
+
cachedUint8ClampedArrayMemory0 = null;
|
|
14880
|
+
return wasm;
|
|
14881
|
+
}
|
|
14882
|
+
async function __wbg_load(module, imports) {
|
|
14883
|
+
if (typeof Response === "function" && module instanceof Response) {
|
|
14884
|
+
if (typeof WebAssembly.instantiateStreaming === "function") {
|
|
14885
|
+
try {
|
|
14886
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
14887
|
+
} catch (e) {
|
|
14888
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
14889
|
+
if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
|
|
14890
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
14891
|
+
} else {
|
|
14892
|
+
throw e;
|
|
14867
14893
|
}
|
|
14868
|
-
application.data = reader.readSubBlock();
|
|
14869
|
-
frame.application = application;
|
|
14870
|
-
continue;
|
|
14871
|
-
}
|
|
14872
|
-
if (extensionFlag === EXTENSION_COMMENT) {
|
|
14873
|
-
frame.comment = reader.readSubBlock().map((val) => String.fromCharCode(val)).join("");
|
|
14874
|
-
continue;
|
|
14875
|
-
}
|
|
14876
|
-
if (extensionFlag === EXTENSION_GRAPHIC_CONTROL) {
|
|
14877
|
-
if (reader.readByte() !== EXTENSION_GRAPHIC_CONTROL_BLOCK_SIZE)
|
|
14878
|
-
continue;
|
|
14879
|
-
const bits2 = reader.readBits();
|
|
14880
|
-
const graphicControl = {
|
|
14881
|
-
// ↓ <Packed Fields>
|
|
14882
|
-
reserved: Number.parseInt(bits2.slice(0, 3).join(""), 2),
|
|
14883
|
-
disposal: Number.parseInt(bits2.slice(3, 6).join(""), 2),
|
|
14884
|
-
userInput: Boolean(bits2[6]),
|
|
14885
|
-
transparent: Boolean(bits2[7]),
|
|
14886
|
-
// ↑ <Packed Fields>
|
|
14887
|
-
delayTime: reader.readUnsigned(),
|
|
14888
|
-
transparentIndex: reader.readByte()
|
|
14889
|
-
};
|
|
14890
|
-
reader.readSubBlock();
|
|
14891
|
-
frame.graphicControl = graphicControl;
|
|
14892
|
-
frame.disposal = graphicControl.disposal;
|
|
14893
|
-
frame.delay = (graphicControl.delayTime || 10) * 10;
|
|
14894
|
-
continue;
|
|
14895
14894
|
}
|
|
14896
|
-
if (extensionFlag === EXTENSION_PLAIN_TEXT) {
|
|
14897
|
-
if (reader.readByte() !== EXTENSION_PLAIN_TEXT_BLOCK_SIZE)
|
|
14898
|
-
continue;
|
|
14899
|
-
frame.plainText = {
|
|
14900
|
-
left: reader.readUnsigned(),
|
|
14901
|
-
top: reader.readUnsigned(),
|
|
14902
|
-
width: reader.readUnsigned(),
|
|
14903
|
-
height: reader.readUnsigned(),
|
|
14904
|
-
cellWidth: reader.readByte(),
|
|
14905
|
-
cellHeight: reader.readByte(),
|
|
14906
|
-
colorIndex: reader.readByte(),
|
|
14907
|
-
backgroundColorIndex: reader.readByte(),
|
|
14908
|
-
data: reader.readSubBlock()
|
|
14909
|
-
};
|
|
14910
|
-
continue;
|
|
14911
|
-
}
|
|
14912
|
-
console.warn(
|
|
14913
|
-
`Unknown extension block: 0x${extensionFlag.toString(16)}`,
|
|
14914
|
-
flags.slice(0, flags.length - 1).map((val) => `0x${val.toString(16)}`),
|
|
14915
|
-
extensionFlags.slice(0, extensionFlags.length - 1).map((val) => `0x${val.toString(16)}`)
|
|
14916
|
-
);
|
|
14917
|
-
continue;
|
|
14918
14895
|
}
|
|
14919
|
-
|
|
14920
|
-
|
|
14921
|
-
|
|
14922
|
-
|
|
14923
|
-
|
|
14924
|
-
|
|
14925
|
-
|
|
14896
|
+
const bytes = await module.arrayBuffer();
|
|
14897
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
14898
|
+
} else {
|
|
14899
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
14900
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
14901
|
+
return { instance, module };
|
|
14902
|
+
} else {
|
|
14903
|
+
return instance;
|
|
14904
|
+
}
|
|
14926
14905
|
}
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
const workers = [...Array.from({ length: workerUrl ? workerNumber : 0 })].map(() => {
|
|
14934
|
-
try {
|
|
14935
|
-
const worker = new Worker(workerUrl);
|
|
14936
|
-
worker.onmessage = onMessage;
|
|
14937
|
-
return worker;
|
|
14938
|
-
} catch (err) {
|
|
14939
|
-
console.warn(err);
|
|
14940
|
-
return null;
|
|
14906
|
+
function expectedResponseType(type) {
|
|
14907
|
+
switch (type) {
|
|
14908
|
+
case "basic":
|
|
14909
|
+
case "cors":
|
|
14910
|
+
case "default":
|
|
14911
|
+
return true;
|
|
14941
14912
|
}
|
|
14942
|
-
|
|
14943
|
-
|
|
14944
|
-
function onMessage(event) {
|
|
14945
|
-
const { id, data } = event.data;
|
|
14946
|
-
callbacks.get(id)?.(data);
|
|
14947
|
-
callbacks.delete(id);
|
|
14948
|
-
}
|
|
14949
|
-
const getWorker = /* @__PURE__ */ function() {
|
|
14950
|
-
let id = 0;
|
|
14951
|
-
return (index) => workers[(index ?? id++) % workerNumber];
|
|
14952
|
-
}();
|
|
14953
|
-
const call = /* @__PURE__ */ function() {
|
|
14954
|
-
let id = 0;
|
|
14955
|
-
return (type, data, transfer, index) => {
|
|
14956
|
-
return new Promise((resolve) => {
|
|
14957
|
-
const worker = getWorker(index);
|
|
14958
|
-
if (!worker)
|
|
14959
|
-
return resolve(void 0);
|
|
14960
|
-
callbacks.set(id, resolve);
|
|
14961
|
-
worker.postMessage({ id: id++, type, data }, { transfer });
|
|
14962
|
-
});
|
|
14963
|
-
};
|
|
14964
|
-
}();
|
|
14965
|
-
return {
|
|
14966
|
-
call
|
|
14967
|
-
};
|
|
14913
|
+
return false;
|
|
14914
|
+
}
|
|
14968
14915
|
}
|
|
14969
|
-
function
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
newPixels.splice.apply(
|
|
14978
|
-
newPixels,
|
|
14979
|
-
[toRow * width, width].concat(
|
|
14980
|
-
pixels.slice(fromRow * width, (fromRow + 1) * width)
|
|
14981
|
-
)
|
|
14982
|
-
);
|
|
14983
|
-
fromRow++;
|
|
14916
|
+
async function __wbg_init(module_or_path) {
|
|
14917
|
+
if (wasm !== void 0)
|
|
14918
|
+
return wasm;
|
|
14919
|
+
if (module_or_path !== void 0) {
|
|
14920
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
14921
|
+
({ module_or_path } = module_or_path);
|
|
14922
|
+
} else {
|
|
14923
|
+
console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
14984
14924
|
}
|
|
14985
14925
|
}
|
|
14986
|
-
|
|
14926
|
+
if (module_or_path === void 0) {
|
|
14927
|
+
module_or_path = new URL("squoosh_gif_bg.wasm", import.meta.url);
|
|
14928
|
+
}
|
|
14929
|
+
const imports = __wbg_get_imports();
|
|
14930
|
+
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
|
|
14931
|
+
module_or_path = fetch(module_or_path);
|
|
14932
|
+
}
|
|
14933
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
14934
|
+
return __wbg_finalize_init(instance, module);
|
|
14987
14935
|
}
|
|
14988
|
-
|
|
14989
|
-
|
|
14990
|
-
|
|
14991
|
-
|
|
14992
|
-
|
|
14993
|
-
|
|
14994
|
-
|
|
14995
|
-
|
|
14996
|
-
|
|
14997
|
-
|
|
14998
|
-
const clear = 1 << dataSize;
|
|
14999
|
-
const endOfInformation = clear + 1;
|
|
15000
|
-
available = clear + 2;
|
|
15001
|
-
oldCode = nullCode;
|
|
15002
|
-
codeSize = dataSize + 1;
|
|
15003
|
-
codeMask = (1 << codeSize) - 1;
|
|
15004
|
-
for (code = 0; code < clear; code++) {
|
|
15005
|
-
prefix[code] = 0;
|
|
15006
|
-
suffix[code] = code;
|
|
15007
|
-
}
|
|
15008
|
-
let datum, bits, first, top, pi, bi;
|
|
15009
|
-
datum = bits = first = top = pi = bi = 0;
|
|
15010
|
-
for (i = 0; i < npix; ) {
|
|
15011
|
-
if (top === 0) {
|
|
15012
|
-
if (bits < codeSize) {
|
|
15013
|
-
datum += data[bi] << bits;
|
|
15014
|
-
bits += 8;
|
|
15015
|
-
bi++;
|
|
15016
|
-
continue;
|
|
15017
|
-
}
|
|
15018
|
-
code = datum & codeMask;
|
|
15019
|
-
datum >>= codeSize;
|
|
15020
|
-
bits -= codeSize;
|
|
15021
|
-
if (code > available || code === endOfInformation) {
|
|
15022
|
-
break;
|
|
14936
|
+
var isServiceWorker = globalThis.ServiceWorkerGlobalScope !== void 0;
|
|
14937
|
+
var isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== "undefined" && globalThis.caches && globalThis.caches.default !== void 0;
|
|
14938
|
+
var isRunningInNode = typeof process === "object" && process.release && process.release.name === "node";
|
|
14939
|
+
if (isRunningInCloudFlareWorkers || isRunningInNode) {
|
|
14940
|
+
if (!globalThis.ImageData) {
|
|
14941
|
+
globalThis.ImageData = class ImageData {
|
|
14942
|
+
constructor(data, width, height) {
|
|
14943
|
+
this.data = data;
|
|
14944
|
+
this.width = width;
|
|
14945
|
+
this.height = height;
|
|
15023
14946
|
}
|
|
15024
|
-
|
|
15025
|
-
|
|
15026
|
-
|
|
15027
|
-
|
|
15028
|
-
oldCode = nullCode;
|
|
15029
|
-
continue;
|
|
15030
|
-
}
|
|
15031
|
-
if (oldCode === nullCode) {
|
|
15032
|
-
pixelStack[top++] = suffix[code];
|
|
15033
|
-
oldCode = code;
|
|
15034
|
-
first = code;
|
|
15035
|
-
continue;
|
|
15036
|
-
}
|
|
15037
|
-
inCode = code;
|
|
15038
|
-
if (code === available) {
|
|
15039
|
-
pixelStack[top++] = first;
|
|
15040
|
-
code = oldCode;
|
|
15041
|
-
}
|
|
15042
|
-
while (code > clear) {
|
|
15043
|
-
pixelStack[top++] = suffix[code];
|
|
15044
|
-
code = prefix[code];
|
|
15045
|
-
}
|
|
15046
|
-
first = suffix[code] & 255;
|
|
15047
|
-
pixelStack[top++] = first;
|
|
15048
|
-
if (available < MAX_STACK_SIZE) {
|
|
15049
|
-
prefix[available] = oldCode;
|
|
15050
|
-
suffix[available] = first;
|
|
15051
|
-
available++;
|
|
15052
|
-
if ((available & codeMask) === 0 && available < MAX_STACK_SIZE) {
|
|
15053
|
-
codeSize++;
|
|
15054
|
-
codeMask += available;
|
|
15055
|
-
}
|
|
15056
|
-
}
|
|
15057
|
-
oldCode = inCode;
|
|
15058
|
-
}
|
|
15059
|
-
top--;
|
|
15060
|
-
dstPixels[pi++] = pixelStack[top];
|
|
15061
|
-
i++;
|
|
14947
|
+
};
|
|
14948
|
+
}
|
|
14949
|
+
if (import.meta.url === void 0) {
|
|
14950
|
+
import.meta.url = "https://localhost";
|
|
15062
14951
|
}
|
|
15063
|
-
|
|
15064
|
-
|
|
14952
|
+
if (typeof self !== "undefined" && self.location === void 0) {
|
|
14953
|
+
self.location = { href: "" };
|
|
15065
14954
|
}
|
|
15066
|
-
return dstPixels;
|
|
15067
14955
|
}
|
|
15068
|
-
|
|
15069
|
-
|
|
15070
|
-
|
|
15071
|
-
|
|
15072
|
-
|
|
15073
|
-
|
|
15074
|
-
|
|
15075
|
-
);
|
|
14956
|
+
|
|
14957
|
+
// ../../node_modules/@discourse/gif/decode.js
|
|
14958
|
+
var gifModule;
|
|
14959
|
+
function validateGif(buffer) {
|
|
14960
|
+
const header = new Uint8Array(buffer, 0, 6);
|
|
14961
|
+
const sig = String.fromCharCode(...header);
|
|
14962
|
+
if (sig !== "GIF87a" && sig !== "GIF89a") {
|
|
14963
|
+
throw new Error(`Not a valid GIF file (expected GIF87a/GIF89a header, got "${sig.replace(/[^\x20-\x7E]/g, "?")}")`);
|
|
15076
14964
|
}
|
|
15077
|
-
const {
|
|
15078
|
-
gif = decode(source),
|
|
15079
|
-
range
|
|
15080
|
-
} = options ?? {};
|
|
15081
|
-
const {
|
|
15082
|
-
width: globalWidth,
|
|
15083
|
-
height: globalHeight,
|
|
15084
|
-
colorTable: globalColorTable,
|
|
15085
|
-
frames: globalFrames
|
|
15086
|
-
} = gif;
|
|
15087
|
-
const frames2 = range ? globalFrames.slice(range[0], range[1] + 1) : globalFrames;
|
|
15088
|
-
const hasDisposal3 = frames2.some((frame) => frame.disposal === 3);
|
|
15089
|
-
let pixels = new Uint8ClampedArray(globalWidth * globalHeight * 4);
|
|
15090
|
-
let previousFrame;
|
|
15091
|
-
let previousPixels = pixels.slice();
|
|
15092
|
-
return frames2.map((frame) => {
|
|
15093
|
-
const {
|
|
15094
|
-
left,
|
|
15095
|
-
top,
|
|
15096
|
-
width,
|
|
15097
|
-
height,
|
|
15098
|
-
interlaced,
|
|
15099
|
-
localColorTable,
|
|
15100
|
-
colorTable,
|
|
15101
|
-
lzwMinCodeSize,
|
|
15102
|
-
dataPositions,
|
|
15103
|
-
graphicControl,
|
|
15104
|
-
delay,
|
|
15105
|
-
disposal
|
|
15106
|
-
} = frame;
|
|
15107
|
-
const previousDisposal = previousFrame?.disposal;
|
|
15108
|
-
const bottom = top + height;
|
|
15109
|
-
const {
|
|
15110
|
-
transparent,
|
|
15111
|
-
transparentIndex: localTransparentIndex
|
|
15112
|
-
} = graphicControl ?? {};
|
|
15113
|
-
const palette2 = localColorTable ? colorTable : globalColorTable;
|
|
15114
|
-
const transparentIndex = transparent ? localTransparentIndex : -1;
|
|
15115
|
-
const compressedData = mergeBuffers(
|
|
15116
|
-
dataPositions.map(
|
|
15117
|
-
([begin, length]) => array.subarray(begin, begin + length)
|
|
15118
|
-
)
|
|
15119
|
-
);
|
|
15120
|
-
let colorIndexes = lzwDecode(lzwMinCodeSize, compressedData, width * height);
|
|
15121
|
-
if (interlaced) {
|
|
15122
|
-
colorIndexes = deinterlace(colorIndexes, width);
|
|
15123
|
-
}
|
|
15124
|
-
if (previousDisposal === 3) {
|
|
15125
|
-
pixels = previousPixels.slice();
|
|
15126
|
-
} else if (previousDisposal === 2) {
|
|
15127
|
-
const { left: left2, top: top2, width: width2, height: height2 } = previousFrame;
|
|
15128
|
-
const bottom2 = top2 + height2;
|
|
15129
|
-
for (let y = top2; y < bottom2; y++) {
|
|
15130
|
-
const globalOffset = y * globalWidth + left2;
|
|
15131
|
-
for (let x = 0; x < width2; x++) {
|
|
15132
|
-
const index = (globalOffset + x) * 4;
|
|
15133
|
-
pixels[index] = pixels[index + 1] = pixels[index + 2] = pixels[index + 3] = 0;
|
|
15134
|
-
}
|
|
15135
|
-
}
|
|
15136
|
-
}
|
|
15137
|
-
for (let y = top; y < bottom; y++) {
|
|
15138
|
-
const globalOffset = y * globalWidth + left;
|
|
15139
|
-
const localOffset = (y - top) * width;
|
|
15140
|
-
for (let x = 0; x < width; x++) {
|
|
15141
|
-
const colorIndex = colorIndexes[localOffset + x];
|
|
15142
|
-
const index = (globalOffset + x) * 4;
|
|
15143
|
-
if (colorIndex !== transparentIndex) {
|
|
15144
|
-
const [r, g, b2] = palette2?.[colorIndex] ?? [0, 0, 0];
|
|
15145
|
-
pixels[index] = r;
|
|
15146
|
-
pixels[index + 1] = g;
|
|
15147
|
-
pixels[index + 2] = b2;
|
|
15148
|
-
pixels[index + 3] = 255;
|
|
15149
|
-
}
|
|
15150
|
-
}
|
|
15151
|
-
}
|
|
15152
|
-
if (hasDisposal3 && disposal !== 1 && disposal !== 3) {
|
|
15153
|
-
previousPixels = pixels.slice();
|
|
15154
|
-
}
|
|
15155
|
-
previousFrame = frame;
|
|
15156
|
-
return {
|
|
15157
|
-
width: globalWidth,
|
|
15158
|
-
height: globalHeight,
|
|
15159
|
-
delay,
|
|
15160
|
-
data: pixels.slice()
|
|
15161
|
-
};
|
|
15162
|
-
});
|
|
15163
14965
|
}
|
|
15164
|
-
|
|
15165
|
-
|
|
15166
|
-
|
|
15167
|
-
|
|
15168
|
-
|
|
15169
|
-
|
|
15170
|
-
|
|
15171
|
-
|
|
15172
|
-
|
|
15173
|
-
|
|
15174
|
-
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
|
|
15178
|
-
],
|
|
15179
|
-
"stucki": [
|
|
15180
|
-
[8 / 42, 1, 0],
|
|
15181
|
-
[4 / 42, 2, 0],
|
|
15182
|
-
[2 / 42, -2, 1],
|
|
15183
|
-
[4 / 42, -1, 1],
|
|
15184
|
-
[8 / 42, 0, 1],
|
|
15185
|
-
[4 / 42, 1, 1],
|
|
15186
|
-
[2 / 42, 2, 1],
|
|
15187
|
-
[1 / 42, -2, 2],
|
|
15188
|
-
[2 / 42, -1, 2],
|
|
15189
|
-
[4 / 42, 0, 2],
|
|
15190
|
-
[2 / 42, 1, 2],
|
|
15191
|
-
[1 / 42, 2, 2]
|
|
15192
|
-
]
|
|
15193
|
-
};
|
|
14966
|
+
async function init(moduleOrPath) {
|
|
14967
|
+
if (!gifModule) {
|
|
14968
|
+
gifModule = __wbg_init(moduleOrPath);
|
|
14969
|
+
}
|
|
14970
|
+
return gifModule;
|
|
14971
|
+
}
|
|
14972
|
+
async function decodeAnimated2(buffer) {
|
|
14973
|
+
validateGif(buffer);
|
|
14974
|
+
await init();
|
|
14975
|
+
const result = decodeAnimated(new Uint8Array(buffer));
|
|
14976
|
+
if (!result)
|
|
14977
|
+
throw new Error("Decoding error");
|
|
14978
|
+
return result;
|
|
14979
|
+
}
|
|
15194
14980
|
|
|
15195
14981
|
// src/gif.ts
|
|
15196
14982
|
var MAX_CONCURRENT_GIF_DECODES = 5;
|
|
14983
|
+
var GIF_WORKER_FILENAME = "gif.worker.js";
|
|
15197
14984
|
var logGifDecodeMode = (mode, context) => {
|
|
15198
14985
|
console.debug("[excalidraw][gif-decode]", {
|
|
15199
14986
|
mode,
|
|
15200
14987
|
...context
|
|
15201
14988
|
});
|
|
15202
14989
|
};
|
|
15203
|
-
var gifWorkerUrl
|
|
14990
|
+
var gifWorkerUrl = new URL(
|
|
14991
|
+
GIF_WORKER_FILENAME,
|
|
14992
|
+
import.meta.url
|
|
14993
|
+
).toString();
|
|
15204
14994
|
var configureGifWorkerUrl = (workerUrl) => {
|
|
15205
14995
|
gifWorkerUrl = workerUrl;
|
|
15206
14996
|
};
|
|
@@ -15214,54 +15004,98 @@ var dataURLToArrayBuffer = (dataURL) => {
|
|
|
15214
15004
|
}
|
|
15215
15005
|
return buffer;
|
|
15216
15006
|
};
|
|
15217
|
-
var
|
|
15218
|
-
|
|
15219
|
-
|
|
15220
|
-
|
|
15221
|
-
|
|
15222
|
-
|
|
15223
|
-
|
|
15224
|
-
|
|
15007
|
+
var getGifDimensions = (buffer) => {
|
|
15008
|
+
if (buffer.byteLength < 10) {
|
|
15009
|
+
return null;
|
|
15010
|
+
}
|
|
15011
|
+
const data = new DataView(buffer);
|
|
15012
|
+
return {
|
|
15013
|
+
width: data.getUint16(6, true),
|
|
15014
|
+
height: data.getUint16(8, true)
|
|
15225
15015
|
};
|
|
15016
|
+
};
|
|
15017
|
+
var decodeGifOnMainThread = async (buffer) => {
|
|
15018
|
+
const dimensions = getGifDimensions(buffer);
|
|
15019
|
+
const gifFrames = await decodeAnimated2(buffer);
|
|
15226
15020
|
try {
|
|
15227
|
-
return
|
|
15021
|
+
return {
|
|
15022
|
+
width: dimensions?.width ?? gifFrames[0]?.imageData.width ?? 0,
|
|
15023
|
+
height: dimensions?.height ?? gifFrames[0]?.imageData.height ?? 0,
|
|
15024
|
+
frames: gifFrames.map((frame) => {
|
|
15025
|
+
const imageData = frame.imageData;
|
|
15026
|
+
return {
|
|
15027
|
+
width: imageData.width,
|
|
15028
|
+
height: imageData.height,
|
|
15029
|
+
delay: frame.duration,
|
|
15030
|
+
data: imageData.data.buffer
|
|
15031
|
+
};
|
|
15032
|
+
})
|
|
15033
|
+
};
|
|
15228
15034
|
} finally {
|
|
15229
|
-
|
|
15035
|
+
gifFrames.forEach((frame) => frame.free());
|
|
15230
15036
|
}
|
|
15231
15037
|
};
|
|
15038
|
+
var decodeGifInWorker = (buffer) => new Promise((resolve, reject) => {
|
|
15039
|
+
const worker = new Worker(gifWorkerUrl, { type: "module" });
|
|
15040
|
+
let settled = false;
|
|
15041
|
+
const finish = () => {
|
|
15042
|
+
if (!settled) {
|
|
15043
|
+
settled = true;
|
|
15044
|
+
worker.terminate();
|
|
15045
|
+
}
|
|
15046
|
+
};
|
|
15047
|
+
worker.onmessage = (event) => {
|
|
15048
|
+
finish();
|
|
15049
|
+
if (event.data.type === "error") {
|
|
15050
|
+
reject(new Error(event.data.message));
|
|
15051
|
+
} else {
|
|
15052
|
+
resolve({
|
|
15053
|
+
frames: event.data.frames,
|
|
15054
|
+
width: event.data.width,
|
|
15055
|
+
height: event.data.height
|
|
15056
|
+
});
|
|
15057
|
+
}
|
|
15058
|
+
};
|
|
15059
|
+
worker.onerror = (event) => {
|
|
15060
|
+
finish();
|
|
15061
|
+
reject(new Error(event.message || "GIF worker failed"));
|
|
15062
|
+
};
|
|
15063
|
+
worker.onmessageerror = () => {
|
|
15064
|
+
finish();
|
|
15065
|
+
reject(new Error("GIF worker returned an unreadable response"));
|
|
15066
|
+
};
|
|
15067
|
+
try {
|
|
15068
|
+
worker.postMessage(buffer, [buffer]);
|
|
15069
|
+
} catch (error) {
|
|
15070
|
+
finish();
|
|
15071
|
+
reject(error);
|
|
15072
|
+
}
|
|
15073
|
+
});
|
|
15232
15074
|
var decodeGifFrames = async (dataURL) => {
|
|
15233
15075
|
const buffer = dataURLToArrayBuffer(dataURL);
|
|
15234
|
-
const
|
|
15235
|
-
logGifDecodeMode(
|
|
15076
|
+
const useWorker = Boolean(gifWorkerUrl && typeof Worker !== "undefined");
|
|
15077
|
+
logGifDecodeMode(useWorker ? "worker" : "main-thread", {
|
|
15236
15078
|
byteLength: buffer.byteLength,
|
|
15237
15079
|
workerUrl: gifWorkerUrl
|
|
15238
15080
|
});
|
|
15239
|
-
const
|
|
15240
|
-
|
|
15241
|
-
const gif2 = decode(buffer);
|
|
15242
|
-
return {
|
|
15243
|
-
gif: gif2,
|
|
15244
|
-
decodedFrames: gifWorkerUrl ? await decodeFrames(buffer, { gif: gif2, workerUrl: gifWorkerUrl }) : await decodeFrames(buffer, { gif: gif2 })
|
|
15245
|
-
};
|
|
15246
|
-
}
|
|
15247
|
-
);
|
|
15248
|
-
const frames2 = decodedFrames.map((frame) => {
|
|
15081
|
+
const decodedGif = useWorker ? await decodeGifInWorker(buffer) : await decodeGifOnMainThread(buffer);
|
|
15082
|
+
const frames2 = decodedGif.frames.map((frame) => {
|
|
15249
15083
|
const canvas = document.createElement("canvas");
|
|
15250
15084
|
canvas.width = frame.width;
|
|
15251
15085
|
canvas.height = frame.height;
|
|
15252
15086
|
const context = canvas.getContext("2d");
|
|
15253
15087
|
if (context) {
|
|
15254
15088
|
const imageData = context.createImageData(frame.width, frame.height);
|
|
15255
|
-
imageData.data.set(frame.data);
|
|
15089
|
+
imageData.data.set(new Uint8ClampedArray(frame.data));
|
|
15256
15090
|
context.putImageData(imageData, 0, 0);
|
|
15257
15091
|
}
|
|
15258
15092
|
return canvas;
|
|
15259
15093
|
});
|
|
15260
15094
|
return {
|
|
15261
15095
|
frames: frames2,
|
|
15262
|
-
delays:
|
|
15263
|
-
width:
|
|
15264
|
-
height:
|
|
15096
|
+
delays: decodedGif.frames.map((frame) => Math.max(frame.delay, 16)),
|
|
15097
|
+
width: decodedGif.width,
|
|
15098
|
+
height: decodedGif.height
|
|
15265
15099
|
};
|
|
15266
15100
|
};
|
|
15267
15101
|
var activeGifDecodeCount = 0;
|