@extend-ai/react-xlsx 0.15.0 → 0.15.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/dist/index.cjs +199 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -6750,6 +6750,204 @@ function cloneArrayBufferForTransfer(buffer) {
|
|
|
6750
6750
|
return buffer.slice(0);
|
|
6751
6751
|
}
|
|
6752
6752
|
|
|
6753
|
+
// src/zip-entry-names.ts
|
|
6754
|
+
var BACKSLASH_BYTE = 92;
|
|
6755
|
+
var FORWARD_SLASH_BYTE = 47;
|
|
6756
|
+
var END_OF_CENTRAL_DIRECTORY_SIGNATURE = 101010256;
|
|
6757
|
+
var CENTRAL_FILE_HEADER_SIGNATURE = 33639248;
|
|
6758
|
+
var LOCAL_FILE_HEADER_SIGNATURE = 67324752;
|
|
6759
|
+
var END_OF_CENTRAL_DIRECTORY_LENGTH = 22;
|
|
6760
|
+
var CENTRAL_FILE_HEADER_LENGTH = 46;
|
|
6761
|
+
var LOCAL_FILE_HEADER_LENGTH = 30;
|
|
6762
|
+
var MAX_ZIP_COMMENT_LENGTH = 65535;
|
|
6763
|
+
var ZIP16_SENTINEL = 65535;
|
|
6764
|
+
var ZIP32_SENTINEL = 4294967295;
|
|
6765
|
+
function findEndOfCentralDirectoryOffset(view) {
|
|
6766
|
+
const firstPossibleOffset = Math.max(
|
|
6767
|
+
0,
|
|
6768
|
+
view.byteLength - END_OF_CENTRAL_DIRECTORY_LENGTH - MAX_ZIP_COMMENT_LENGTH
|
|
6769
|
+
);
|
|
6770
|
+
for (let offset = view.byteLength - END_OF_CENTRAL_DIRECTORY_LENGTH; offset >= firstPossibleOffset; offset -= 1) {
|
|
6771
|
+
if (view.getUint32(offset, true) !== END_OF_CENTRAL_DIRECTORY_SIGNATURE) {
|
|
6772
|
+
continue;
|
|
6773
|
+
}
|
|
6774
|
+
const commentLength = view.getUint16(offset + 20, true);
|
|
6775
|
+
if (offset + END_OF_CENTRAL_DIRECTORY_LENGTH + commentLength === view.byteLength) {
|
|
6776
|
+
return offset;
|
|
6777
|
+
}
|
|
6778
|
+
}
|
|
6779
|
+
return null;
|
|
6780
|
+
}
|
|
6781
|
+
function readCentralDirectoryInfo(view) {
|
|
6782
|
+
if (view.byteLength < END_OF_CENTRAL_DIRECTORY_LENGTH) {
|
|
6783
|
+
return null;
|
|
6784
|
+
}
|
|
6785
|
+
const endOfCentralDirectoryOffset = findEndOfCentralDirectoryOffset(view);
|
|
6786
|
+
if (endOfCentralDirectoryOffset === null) {
|
|
6787
|
+
return null;
|
|
6788
|
+
}
|
|
6789
|
+
const diskNumber = view.getUint16(endOfCentralDirectoryOffset + 4, true);
|
|
6790
|
+
const centralDirectoryDiskNumber = view.getUint16(endOfCentralDirectoryOffset + 6, true);
|
|
6791
|
+
const entriesOnDisk = view.getUint16(endOfCentralDirectoryOffset + 8, true);
|
|
6792
|
+
const entryCount = view.getUint16(endOfCentralDirectoryOffset + 10, true);
|
|
6793
|
+
const centralDirectorySize = view.getUint32(endOfCentralDirectoryOffset + 12, true);
|
|
6794
|
+
const centralDirectoryOffset = view.getUint32(endOfCentralDirectoryOffset + 16, true);
|
|
6795
|
+
if (diskNumber !== 0 || centralDirectoryDiskNumber !== 0 || entriesOnDisk !== entryCount || entryCount === ZIP16_SENTINEL || centralDirectorySize === ZIP32_SENTINEL || centralDirectoryOffset === ZIP32_SENTINEL) {
|
|
6796
|
+
return null;
|
|
6797
|
+
}
|
|
6798
|
+
const centralDirectoryEndOffset = centralDirectoryOffset + centralDirectorySize;
|
|
6799
|
+
if (centralDirectoryOffset > endOfCentralDirectoryOffset || centralDirectoryEndOffset > endOfCentralDirectoryOffset || centralDirectoryEndOffset > view.byteLength) {
|
|
6800
|
+
return null;
|
|
6801
|
+
}
|
|
6802
|
+
return {
|
|
6803
|
+
endOffset: centralDirectoryEndOffset,
|
|
6804
|
+
entryCount,
|
|
6805
|
+
offset: centralDirectoryOffset
|
|
6806
|
+
};
|
|
6807
|
+
}
|
|
6808
|
+
function readCentralDirectoryEntry(view, centralDirectoryEndOffset, offset) {
|
|
6809
|
+
if (offset < 0 || offset + CENTRAL_FILE_HEADER_LENGTH > centralDirectoryEndOffset || offset + CENTRAL_FILE_HEADER_LENGTH > view.byteLength || view.getUint32(offset, true) !== CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
6810
|
+
return null;
|
|
6811
|
+
}
|
|
6812
|
+
const nameLength = view.getUint16(offset + 28, true);
|
|
6813
|
+
const extraLength = view.getUint16(offset + 30, true);
|
|
6814
|
+
const commentLength = view.getUint16(offset + 32, true);
|
|
6815
|
+
const nameStart = offset + CENTRAL_FILE_HEADER_LENGTH;
|
|
6816
|
+
const nameEnd = nameStart + nameLength;
|
|
6817
|
+
const nextOffset = nameEnd + extraLength + commentLength;
|
|
6818
|
+
if (nameEnd > centralDirectoryEndOffset || nextOffset > centralDirectoryEndOffset) {
|
|
6819
|
+
return null;
|
|
6820
|
+
}
|
|
6821
|
+
return {
|
|
6822
|
+
diskNumberStart: view.getUint16(offset + 34, true),
|
|
6823
|
+
localHeaderOffset: view.getUint32(offset + 42, true),
|
|
6824
|
+
nameEnd,
|
|
6825
|
+
nameStart,
|
|
6826
|
+
nextOffset
|
|
6827
|
+
};
|
|
6828
|
+
}
|
|
6829
|
+
function entryNameUsesBackslash(bytes, entry) {
|
|
6830
|
+
for (let cursor = entry.nameStart; cursor < entry.nameEnd; cursor += 1) {
|
|
6831
|
+
if (bytes[cursor] === BACKSLASH_BYTE) {
|
|
6832
|
+
return true;
|
|
6833
|
+
}
|
|
6834
|
+
}
|
|
6835
|
+
return false;
|
|
6836
|
+
}
|
|
6837
|
+
function centralDirectoryUsesBackslashSeparators(bytes, view, centralDirectory) {
|
|
6838
|
+
let offset = centralDirectory.offset;
|
|
6839
|
+
for (let index = 0; index < centralDirectory.entryCount; index += 1) {
|
|
6840
|
+
const entry = readCentralDirectoryEntry(view, centralDirectory.endOffset, offset);
|
|
6841
|
+
if (!entry) {
|
|
6842
|
+
return null;
|
|
6843
|
+
}
|
|
6844
|
+
if (entryNameUsesBackslash(bytes, entry)) {
|
|
6845
|
+
return true;
|
|
6846
|
+
}
|
|
6847
|
+
offset = entry.nextOffset;
|
|
6848
|
+
}
|
|
6849
|
+
return false;
|
|
6850
|
+
}
|
|
6851
|
+
function normalizedEntryNameKey(bytes, entry) {
|
|
6852
|
+
let key = "";
|
|
6853
|
+
for (let cursor = entry.nameStart; cursor < entry.nameEnd; cursor += 1) {
|
|
6854
|
+
const byte = bytes[cursor] === BACKSLASH_BYTE ? FORWARD_SLASH_BYTE : bytes[cursor];
|
|
6855
|
+
key += String.fromCharCode(byte);
|
|
6856
|
+
}
|
|
6857
|
+
return key;
|
|
6858
|
+
}
|
|
6859
|
+
function validateEntryNamePatches(bytes, view, centralDirectory) {
|
|
6860
|
+
const normalizedNames = /* @__PURE__ */ new Set();
|
|
6861
|
+
const localHeaderOffsets = /* @__PURE__ */ new Set();
|
|
6862
|
+
let offset = centralDirectory.offset;
|
|
6863
|
+
for (let index = 0; index < centralDirectory.entryCount; index += 1) {
|
|
6864
|
+
const entry = readCentralDirectoryEntry(view, centralDirectory.endOffset, offset);
|
|
6865
|
+
if (!entry || entry.diskNumberStart !== 0 || entry.localHeaderOffset === ZIP32_SENTINEL || entry.localHeaderOffset + LOCAL_FILE_HEADER_LENGTH > centralDirectory.offset || localHeaderOffsets.has(entry.localHeaderOffset)) {
|
|
6866
|
+
return false;
|
|
6867
|
+
}
|
|
6868
|
+
localHeaderOffsets.add(entry.localHeaderOffset);
|
|
6869
|
+
const normalizedName = normalizedEntryNameKey(bytes, entry);
|
|
6870
|
+
if (normalizedNames.has(normalizedName)) {
|
|
6871
|
+
return false;
|
|
6872
|
+
}
|
|
6873
|
+
normalizedNames.add(normalizedName);
|
|
6874
|
+
if (!entryNameUsesBackslash(bytes, entry)) {
|
|
6875
|
+
offset = entry.nextOffset;
|
|
6876
|
+
continue;
|
|
6877
|
+
}
|
|
6878
|
+
if (view.getUint32(entry.localHeaderOffset, true) !== LOCAL_FILE_HEADER_SIGNATURE) {
|
|
6879
|
+
return false;
|
|
6880
|
+
}
|
|
6881
|
+
const localNameLength = view.getUint16(entry.localHeaderOffset + 26, true);
|
|
6882
|
+
const localNameStart = entry.localHeaderOffset + LOCAL_FILE_HEADER_LENGTH;
|
|
6883
|
+
const localNameEnd = localNameStart + localNameLength;
|
|
6884
|
+
if (localNameLength !== entry.nameEnd - entry.nameStart || localNameEnd > centralDirectory.offset) {
|
|
6885
|
+
return false;
|
|
6886
|
+
}
|
|
6887
|
+
for (let nameIndex = 0; nameIndex < localNameLength; nameIndex += 1) {
|
|
6888
|
+
const centralNameOffset = entry.nameStart + nameIndex;
|
|
6889
|
+
const localNameOffset = localNameStart + nameIndex;
|
|
6890
|
+
if (bytes[centralNameOffset] !== bytes[localNameOffset]) {
|
|
6891
|
+
return false;
|
|
6892
|
+
}
|
|
6893
|
+
}
|
|
6894
|
+
offset = entry.nextOffset;
|
|
6895
|
+
}
|
|
6896
|
+
return true;
|
|
6897
|
+
}
|
|
6898
|
+
function patchEntryNameSeparators(bytes, view, centralDirectory) {
|
|
6899
|
+
let offset = centralDirectory.offset;
|
|
6900
|
+
for (let index = 0; index < centralDirectory.entryCount; index += 1) {
|
|
6901
|
+
const entry = readCentralDirectoryEntry(view, centralDirectory.endOffset, offset);
|
|
6902
|
+
if (!entry) {
|
|
6903
|
+
return;
|
|
6904
|
+
}
|
|
6905
|
+
if (entryNameUsesBackslash(bytes, entry)) {
|
|
6906
|
+
const localNameStart = entry.localHeaderOffset + LOCAL_FILE_HEADER_LENGTH;
|
|
6907
|
+
for (let nameIndex = 0; nameIndex < entry.nameEnd - entry.nameStart; nameIndex += 1) {
|
|
6908
|
+
const centralNameOffset = entry.nameStart + nameIndex;
|
|
6909
|
+
if (bytes[centralNameOffset] === BACKSLASH_BYTE) {
|
|
6910
|
+
bytes[centralNameOffset] = FORWARD_SLASH_BYTE;
|
|
6911
|
+
bytes[localNameStart + nameIndex] = FORWARD_SLASH_BYTE;
|
|
6912
|
+
}
|
|
6913
|
+
}
|
|
6914
|
+
}
|
|
6915
|
+
offset = entry.nextOffset;
|
|
6916
|
+
}
|
|
6917
|
+
}
|
|
6918
|
+
function normalizeZipEntryNames(bytes) {
|
|
6919
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
6920
|
+
const centralDirectory = readCentralDirectoryInfo(view);
|
|
6921
|
+
if (!centralDirectory || centralDirectoryUsesBackslashSeparators(bytes, view, centralDirectory) !== true) {
|
|
6922
|
+
return bytes;
|
|
6923
|
+
}
|
|
6924
|
+
if (!validateEntryNamePatches(bytes, view, centralDirectory)) {
|
|
6925
|
+
return bytes;
|
|
6926
|
+
}
|
|
6927
|
+
const normalizedBytes = new Uint8Array(bytes.byteLength);
|
|
6928
|
+
normalizedBytes.set(bytes);
|
|
6929
|
+
const normalizedView = new DataView(
|
|
6930
|
+
normalizedBytes.buffer,
|
|
6931
|
+
normalizedBytes.byteOffset,
|
|
6932
|
+
normalizedBytes.byteLength
|
|
6933
|
+
);
|
|
6934
|
+
patchEntryNameSeparators(normalizedBytes, normalizedView, centralDirectory);
|
|
6935
|
+
return normalizedBytes;
|
|
6936
|
+
}
|
|
6937
|
+
function normalizeWorkbookArrayBuffer(buffer) {
|
|
6938
|
+
const bytes = new Uint8Array(buffer);
|
|
6939
|
+
const normalizedBytes = normalizeZipEntryNames(bytes);
|
|
6940
|
+
if (normalizedBytes === bytes) {
|
|
6941
|
+
return buffer;
|
|
6942
|
+
}
|
|
6943
|
+
if (normalizedBytes.byteOffset === 0 && normalizedBytes.byteLength === normalizedBytes.buffer.byteLength && normalizedBytes.buffer instanceof ArrayBuffer) {
|
|
6944
|
+
return normalizedBytes.buffer;
|
|
6945
|
+
}
|
|
6946
|
+
const normalizedBuffer = new ArrayBuffer(normalizedBytes.byteLength);
|
|
6947
|
+
new Uint8Array(normalizedBuffer).set(normalizedBytes);
|
|
6948
|
+
return normalizedBuffer;
|
|
6949
|
+
}
|
|
6950
|
+
|
|
6753
6951
|
// src/controller.tsx
|
|
6754
6952
|
var FORMULA_COUNT_THRESHOLD = 1e3;
|
|
6755
6953
|
var DEFAULT_ROW_HEIGHT = 24;
|
|
@@ -8393,6 +8591,7 @@ function useXlsxViewerController(options) {
|
|
|
8393
8591
|
if (maxFileSizeBytes > 0 && buffer.byteLength > maxFileSizeBytes) {
|
|
8394
8592
|
throw new XlsxFileSizeLimitExceededError(buffer.byteLength, maxFileSizeBytes);
|
|
8395
8593
|
}
|
|
8594
|
+
buffer = normalizeWorkbookArrayBuffer(buffer);
|
|
8396
8595
|
const preflight = preflightWorkbookBuffer(buffer);
|
|
8397
8596
|
if (preflight?.tooLarge) {
|
|
8398
8597
|
throw createWorkbookTooLargeError(preflight);
|