@office-open/core 0.14.0 → 0.14.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.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +193 -11
- package/dist/index.mjs.map +1 -1
- package/dist/util/index.mjs +1 -1
- package/dist/{util-B3K-9ODR.mjs → util-D61LJ_Wz.mjs} +64 -7
- package/dist/util-D61LJ_Wz.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/util-B3K-9ODR.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -128,7 +128,9 @@ declare class ParsedArchive {
|
|
|
128
128
|
private readonly parts;
|
|
129
129
|
private readonly modified;
|
|
130
130
|
private readonly wrapperCache;
|
|
131
|
+
private readonly order;
|
|
131
132
|
constructor(data: Uint8Array);
|
|
133
|
+
static open(data: Uint8Array | Blob): Promise<ParsedArchive>;
|
|
132
134
|
private inflate;
|
|
133
135
|
get(path: string, parseOptions?: ParseOptions): Element | undefined;
|
|
134
136
|
set(path: string, element: Element): void;
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/opc/media.ts","../src/opc/embeddings.ts","../src/opc/variant-types.ts","../src/opc/app-properties.ts","../src/opc/custom-properties.ts","../src/opc/encryption.ts","../src/util/base64.ts","../src/opc/parser.ts","../src/opc/namespaces.ts","../src/opc/part-registry.ts","../src/opc/opc-consistency.ts","../src/opc/content-type-overrides.ts","../src/opc/content-types-input.ts","../src/opc/passthrough.ts","../src/table/types.ts","../src/picture/types.ts","../src/connector/types.ts","../src/group/types.ts"],"mappings":";;;;;;;;;;;;;;UAyBiB;EACf;EACA,MAAM;EACN;;cAeW,MAAM,UAAU;mBACV;mBAEA;mBAEA;UACT;UAGA;EAYD,SACL,MAAM,YACN,cACA,QAAQ,qBAAqB,GAC7B,oBACC;UAuCK;UAaA;UAoBA;MASG,SAAS;;;;UC3IL;EAEf;EAEA,MAAM;EAEN;EAOA;;cAQW;UACH;UACA;UAEA;EAGD;EAeA,aACL,MAAM,YACN,wBACA,iBACA,mBAAmB,oCAClB;MAsBQ,SAAS;UAKZ;;;;KC9DE,2CAA2C;iBA+CvC,sBAAsB,OAAO,cAAc;iBAkB3C,kBAAkB,IAAI,UAAU;iBAuBhC,sBAAsB;iBAgBtB,YAAY,IAAI,sBAAsB;;;UCpGrC;EAEf;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAMA,SAAS;EAET;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA,eAAe;EAEf;EAMA;;UAIe;EAEf;EAEA;;KAIU,qBAAqB;cAEpB,mBAAmB,iBAAiB;;;UC9EhC;EAEf;EAEA,OAAO;EAMP;;UAIe;EACf,YAAY;;cAGD,sBAAsB,iBAAiB;;;UCpBnC;EAEf,MAAM;;iBAIQ,qBAAqB,MAAM;iBAQ3B,yBAAyB,UAAU,YACjD;EAAQ,YAAY;GACpB,MAAM,GACN,mBACC,aAAa;iBAOA,yBAAyB;EACvC,YAAY;IACV,eAAe;iBAmBH,yBACd;EAAQ,YAAY;GACpB;;;iBCvDc,aAAa,gBAAgB;iBAkB7B,aAAa,OAAO;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/opc/media.ts","../src/opc/embeddings.ts","../src/opc/variant-types.ts","../src/opc/app-properties.ts","../src/opc/custom-properties.ts","../src/opc/encryption.ts","../src/util/base64.ts","../src/opc/parser.ts","../src/opc/namespaces.ts","../src/opc/part-registry.ts","../src/opc/opc-consistency.ts","../src/opc/content-type-overrides.ts","../src/opc/content-types-input.ts","../src/opc/passthrough.ts","../src/table/types.ts","../src/picture/types.ts","../src/connector/types.ts","../src/group/types.ts"],"mappings":";;;;;;;;;;;;;;UAyBiB;EACf;EACA,MAAM;EACN;;cAeW,MAAM,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ACV,WAAW;;cAKA,kBAAkB,iBAAiB;KAiDpC,2BAA2B;iBAgBvB,qBAAqB,UAAU,sBAAsB;UAgBpD;EAGf,SAAS;EAET,mBAAmB,SAAS;EAE5B,eAAe;EAMf,YAAY;IAAgB;IAAc;;EAU1C,SAAS;EAQT,gBAAgB;;iBAkBF,mBACd,WAAW,kBACX,SAAS,4BACR;cAyJU,2BAA2B;;;UC5SvB;EACf;EACA,MAAM;EAON;;UAGe;EAKf;EACA;EAEA;EAEA;EAEA;;UAGe;EACf,OAAO;EACP,eAAe;;iBAuBD,wBACd,SAAS,eACT,cAAc,mBACb;iBA+Ga,4BACd,OAAO,UACP,mCAAmC;;;UClLpB;EAEf;EAEA;EAEA;;UAKe,oBAAoB,QAAQ;EAC3C,OAAO;;UAKQ,iBAAiB,OAAO;EACvC,MAAM;EAMN,yBAAyB;EAEzB;EACA;EACA;EACA;EACA;EACA;;;;UCnCe,2BAA2B;EAM1C,OAAO;EAOP;EAEA;;;;UCXe,6BAA6B;EAE5C,UAAU;EAEV,kBAAkB;EAElB,gBAAgB;;iBAQF,kBACd,MAAM,mCACL,QAAQ;;;UClBM,yBAAyB;EAOxC,UAAU;;iBAQI,cAAc,MAAM,+BAA+B,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as ZIP_STORED_LEVEL, B as OoxmlMimeType, C as replaceVideoPlaceholders, D as addBinaryFile, E as randomBytes, F as strFromU8, H as
|
|
1
|
+
import { A as ZIP_STORED_LEVEL, B as OoxmlMimeType, C as replaceVideoPlaceholders, D as addBinaryFile, E as randomBytes, F as strFromU8, G as readCentralDirectory, H as inflateRawWindow, I as unzipSync, K as readCentralDirectoryAsync, L as zipAndConvert, M as createPacker, N as createZipStream, O as compileMapping, P as levelForMediaName, R as zipSync, S as replaceSmartArtPlaceholders, T as hashPasswordAgile, U as inflateZipEntry, V as convertOutput, W as nativeCrc32, _ as replaceMediaPlaceholders, a as getAudioRefs, b as replaceOlePlaceholders, c as getReferencedMedia, d as replaceAllPlaceholders, f as replaceAudioPlaceholders, g as replaceImagePlaceholders, h as replaceImageLinkPlaceholders, i as formatId, j as ZipStreamWriter, k as ZIP_DEFLATE_LEVEL, l as getVideoRefs, m as replaceHyperlinkPlaceholders, n as collectPlaceholderKeys, o as getMediaRefs, p as replaceChartPlaceholders, r as findAndReplaceImagePlaceholders, s as getOleRefs, t as addSmartArtRelationships, u as hasPlaceholders, v as replaceNumberingPlaceholders, w as derivePasswordHash, x as replacePlaceholders, y as replaceOleLinkPlaceholders, z as zipSyncAndConvert } from "./util-D61LJ_Wz.mjs";
|
|
2
2
|
import { _ as toJson, a as appendOverride, b as buildCorePropertiesXmlString, c as createTraverser, d as TokenNotFoundError, f as createSplitInject, g as patchSpaceAttribute, h as nextNumericId, i as appendContentType, l as createRunRenderer, m as getFirstLevelElements, n as appendRelationship, o as removeOverride, p as createTextElementContents, r as getNextRelationshipIndex, s as createReplacer, t as applyCorePropertiesOverride, u as createTokenReplacer, v as DOCX_NS, x as parseCorePropsElement, y as PPTX_NS } from "./patch-AkQY17CD.mjs";
|
|
3
3
|
import { $ as xsdErrorValueType, $t as shortHexNumber, A as parsePercent, At as xsdTextVerticalType, B as xsdAxisCrosses, C as convertUniversalMeasureToInch, Ct as xsdStrikeStyle, D as emitPercent, Dt as xsdTextBuild, E as emitAngle, Et as xsdTextAnchor, F as xsdAnimClass, Ft as isBase64DataURL, G as xsdChartBuild, Gt as hexColorValue, H as xsdAxisOrientation, Ht as decimalNumber, I as xsdAnimLevel, It as toUint8Array, J as xsdConsolidateFunction, Jt as measurementOrPercentValue, K as xsdComments, Kt as hpsMeasureValue, L as xsdAnimValueType, Lt as toUint8ArrayAsync, M as parseUniversalMeasure, Mt as xsdTrendlineType, N as invertMap, Nt as xsdUnderlineStyle, O as mapOptional, Ot as xsdTextCaps, P as xsdAnimCalcMode, Pt as xsdVerticalMergeRev, Q as xsdEffectContainer, Qt as positiveUniversalMeasureValue, R as xsdAnimationDgmBuild, Rt as decodeBase64, S as convertUniversalMeasureToEmu, St as xsdSplitType, T as convertUniversalMeasureToTwip, Tt as xsdTextAlign, U as xsdAxisPosition, Ut as eighthPointMeasureValue, V as xsdAxisLabelAlignment, Vt as dateTimeValue, W as xsdBlendMode, Wt as hexBinary, X as xsdDiagramBuild, Xt as percentageValue, Y as xsdDataLabelPosition, Yt as parseOnOff, Z as xsdDiagramDirection, Zt as pointMeasureValue, _ as convertToEmu, _t as xsdRectAlignment, a as uniqueNumericIdCreator, an as universalMeasureValue, at as xsdLegendPosition, b as convertToTwip, bt as xsdSizeRepresents, c as convertEmuToPixels, ct as xsdLineEndSize, d as convertInchesToEmu, dt as xsdOrient, en as signedHpsMeasureValue, et as xsdFontAlignment, f as convertInchesToTwip, ft as xsdPathFillMode, g as convertPointsToTwip, gt as xsdPresetShadow, h as convertPointsToEmu, ht as xsdPlaceholderType, i as uniqueId, in as uCharHexNumber, it as xsdJcAlignment, j as parsePercentAttr, jt as xsdTotalsRowFunction, k as parseAngle, kt as xsdTextTabAlignment, l as convertEmuToPoints, lt as xsdMaterialType, m as convertPixelsToEmu, mt as xsdPenAlignment, n as imageTypeFromPath, nn as stripColorHashPrefix, nt as xsdHueDirection, o as uniqueUuid, on as unsignedDecimalNumber, ot as xsdLightRigDirection, p as convertMillimetersToTwip, pt as xsdPattern, q as xsdCompoundLine, qt as longHexNumber, r as hashedId, rn as twipsMeasureValue, rt as xsdIterateType, s as convertEmuToInches, st as xsdLineCap, t as extUriMatches, tn as signedTwipsMeasureValue, tt as xsdHierBranch, u as convertEmuToTwip, ut as xsdMathStyle, v as convertToInch, vt as xsdResizeHandles, w as convertUniversalMeasureToPt, wt as xsdTableWidthType, x as convertTwipToEmu, xt as xsdSlideLayoutType, y as convertToPt, yt as xsdShadingPattern, z as xsdAxisCrossBetween, zt as encodeBase64 } from "./ext-uri-5jTDczSP.mjs";
|
|
4
4
|
import { C as stringifyDataModelOptions, D as COLOR_CATEGORIES, E as stringifyConnection, O as LAYOUT_CATEGORIES, S as stringifyDataModel, T as stringifyTransPoint, _ as parseLayoutDefinition, a as getColorXml, b as withDiagramNamespaces, c as parseStyleDefinition, d as styleDefDesc, f as colorsDefDesc, g as layoutDefDesc, h as stringifyColorDefinitionPart, i as DEFAULT_DRAWING_XML, k as STYLE_CATEGORIES, l as stringifyStyleDefinition, m as stringifyColorDefinition, n as SmartArtCollection, o as getLayoutXml, p as parseColorDefinition, r as definitionId, s as getStyleXml, t as createDataModel, u as stringifyStyleDefinitionPart, v as stringifyLayoutDefinition, w as stringifyPoint, x as parseDataModelOptions, y as stringifyLayoutDefinitionPart } from "./smartart-CrVPot34.mjs";
|
|
@@ -770,6 +770,21 @@ function assertEncryptedExclusive(file, hasContent) {
|
|
|
770
770
|
if (file.encrypted && hasContent) throw new Error("Encrypted passthrough carries no editable content — clear the content fields or drop `encrypted`.");
|
|
771
771
|
}
|
|
772
772
|
//#endregion
|
|
773
|
+
//#region src/opc/byte-source.ts
|
|
774
|
+
/** Blob/File source — every read is a `slice()` window, the package never materializes. */
|
|
775
|
+
function blobSource(blob) {
|
|
776
|
+
return {
|
|
777
|
+
byteLength: blob.size,
|
|
778
|
+
async read(offset, length) {
|
|
779
|
+
const buf = await blob.slice(offset, offset + length).arrayBuffer();
|
|
780
|
+
return new Uint8Array(buf);
|
|
781
|
+
},
|
|
782
|
+
stream(offset, length) {
|
|
783
|
+
return blob.slice(offset, offset + length).stream();
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
//#endregion
|
|
773
788
|
//#region src/opc/gfxdata.ts
|
|
774
789
|
/**
|
|
775
790
|
* Byte-level strip of oversized `o:gfxdata` attribute values from XML parts.
|
|
@@ -842,6 +857,84 @@ function findNeedle(xml, from) {
|
|
|
842
857
|
}
|
|
843
858
|
return -1;
|
|
844
859
|
}
|
|
860
|
+
const QUOTE = 34;
|
|
861
|
+
/** Chunks can split the needle; this many tail bytes are held back between chunks. */
|
|
862
|
+
const NEEDLE_LEN = 11;
|
|
863
|
+
function concatChunks(chunks) {
|
|
864
|
+
let total = 0;
|
|
865
|
+
for (const c of chunks) total += c.length;
|
|
866
|
+
const out = new Uint8Array(total);
|
|
867
|
+
let offset = 0;
|
|
868
|
+
for (const c of chunks) {
|
|
869
|
+
out.set(c, offset);
|
|
870
|
+
offset += c.length;
|
|
871
|
+
}
|
|
872
|
+
return out;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Transform stream removing oversized `o:gfxdata="…"` attribute values on the
|
|
876
|
+
* fly. Feed it inflated XML chunks; the readable side yields the XML with
|
|
877
|
+
* those attributes already gone.
|
|
878
|
+
*/
|
|
879
|
+
function gfxdataStripStream(threshold = GFXDATA_STRIP_THRESHOLD) {
|
|
880
|
+
let carry = /* @__PURE__ */ new Uint8Array(0);
|
|
881
|
+
let mode = "scan";
|
|
882
|
+
let collected = [];
|
|
883
|
+
let valueLen = 0;
|
|
884
|
+
return new TransformStream({
|
|
885
|
+
transform(chunk, controller) {
|
|
886
|
+
const buf = carry.length > 0 ? concatChunks([carry, chunk]) : chunk;
|
|
887
|
+
carry = /* @__PURE__ */ new Uint8Array(0);
|
|
888
|
+
let i = 0;
|
|
889
|
+
const out = [];
|
|
890
|
+
const emitPending = () => {
|
|
891
|
+
if (out.length === 1) controller.enqueue(out[0]);
|
|
892
|
+
else if (out.length > 1) controller.enqueue(concatChunks(out));
|
|
893
|
+
};
|
|
894
|
+
while (true) if (mode === "scan") {
|
|
895
|
+
if (i >= buf.length) break;
|
|
896
|
+
const hit = findNeedle(buf, i);
|
|
897
|
+
if (hit === -1) {
|
|
898
|
+
const keepFrom = Math.max(i, buf.length - 10);
|
|
899
|
+
if (keepFrom > i) out.push(buf.subarray(i, keepFrom));
|
|
900
|
+
carry = buf.slice(keepFrom);
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
if (hit > i) out.push(buf.subarray(i, hit));
|
|
904
|
+
collected = Array.from(NEEDLE, (ch) => ch.charCodeAt(0));
|
|
905
|
+
valueLen = 0;
|
|
906
|
+
mode = "collecting";
|
|
907
|
+
i = hit + NEEDLE_LEN;
|
|
908
|
+
} else {
|
|
909
|
+
let q = i;
|
|
910
|
+
while (q < buf.length && buf[q] !== QUOTE) {
|
|
911
|
+
if (mode === "collecting") {
|
|
912
|
+
collected.push(buf[q]);
|
|
913
|
+
valueLen++;
|
|
914
|
+
if (valueLen > threshold) {
|
|
915
|
+
mode = "discarding";
|
|
916
|
+
collected = [];
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
q++;
|
|
920
|
+
}
|
|
921
|
+
if (q === buf.length) break;
|
|
922
|
+
if (mode === "collecting") out.push(new Uint8Array(collected));
|
|
923
|
+
out.push(buf.subarray(q, q + 1));
|
|
924
|
+
collected = [];
|
|
925
|
+
mode = "scan";
|
|
926
|
+
i = q + 1;
|
|
927
|
+
}
|
|
928
|
+
emitPending();
|
|
929
|
+
},
|
|
930
|
+
flush(controller) {
|
|
931
|
+
if (mode === "collecting") controller.enqueue(new Uint8Array(collected));
|
|
932
|
+
else if (mode === "scan" && carry.length > 0) controller.enqueue(carry);
|
|
933
|
+
carry = /* @__PURE__ */ new Uint8Array(0);
|
|
934
|
+
collected = [];
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
}
|
|
845
938
|
//#endregion
|
|
846
939
|
//#region src/opc/namespaces.ts
|
|
847
940
|
/**
|
|
@@ -1031,6 +1124,43 @@ const OOXML_CANONICAL_PREFIXES = {
|
|
|
1031
1124
|
[`${SCHEMAS_MS}/office/spreadsheetml/2016/revision6`]: "xr6",
|
|
1032
1125
|
[`${SCHEMAS_MS}/office/spreadsheetml/2016/revision10`]: "xr10"
|
|
1033
1126
|
};
|
|
1127
|
+
/**
|
|
1128
|
+
* Inflate a compressed zip entry from `source`, streaming when the entry is
|
|
1129
|
+
* an oversized XML part (the gfxdata-stripping transform rides along) and
|
|
1130
|
+
* reading a plain window otherwise. STORE entries skip decompression. No
|
|
1131
|
+
* CRC-32 is verified on the streaming path — the JS table costs more than
|
|
1132
|
+
* the inflate itself at these sizes, and the fflate fallback parity is
|
|
1133
|
+
* check-free by contract. XML parts get oversized `o:gfxdata` values
|
|
1134
|
+
* stripped on both paths, matching the bytes-backed archive behavior.
|
|
1135
|
+
*/
|
|
1136
|
+
async function inflateEntryFrom(source, entry) {
|
|
1137
|
+
const xml = entry.name.endsWith(".xml");
|
|
1138
|
+
const raw = await source.read(entry.dataStart, entry.compSize);
|
|
1139
|
+
if (entry.method === 0) return xml ? stripOversizedGfxdata(raw) : raw;
|
|
1140
|
+
if (xml && entry.uncompSize > 33554432 && typeof DecompressionStream !== "undefined") return inflateRawStreaming(source, entry);
|
|
1141
|
+
const data = inflateRawWindow(raw, entry);
|
|
1142
|
+
return xml ? stripOversizedGfxdata(data) : data;
|
|
1143
|
+
}
|
|
1144
|
+
/** Stream `slice → DecompressionStream → gfxdata strip` and join the output. */
|
|
1145
|
+
async function inflateRawStreaming(source, entry) {
|
|
1146
|
+
const decoded = source.stream(entry.dataStart, entry.compSize).pipeThrough(new DecompressionStream("deflate-raw")).pipeThrough(gfxdataStripStream());
|
|
1147
|
+
const chunks = [];
|
|
1148
|
+
let total = 0;
|
|
1149
|
+
const reader = decoded.getReader();
|
|
1150
|
+
for (;;) {
|
|
1151
|
+
const { done, value } = await reader.read();
|
|
1152
|
+
if (done) break;
|
|
1153
|
+
chunks.push(value);
|
|
1154
|
+
total += value.length;
|
|
1155
|
+
}
|
|
1156
|
+
const out = new Uint8Array(total);
|
|
1157
|
+
let offset = 0;
|
|
1158
|
+
for (const chunk of chunks) {
|
|
1159
|
+
out.set(chunk, offset);
|
|
1160
|
+
offset += chunk.length;
|
|
1161
|
+
}
|
|
1162
|
+
return out;
|
|
1163
|
+
}
|
|
1034
1164
|
//#endregion
|
|
1035
1165
|
//#region src/opc/parser.ts
|
|
1036
1166
|
const XML_PARSE_OPTIONS = {
|
|
@@ -1051,7 +1181,7 @@ const XML_PARSE_OPTIONS = {
|
|
|
1051
1181
|
* Provides unstorage-style API (get/set/getRaw/setRaw/remove/has/keys)
|
|
1052
1182
|
* for reading and modifying individual parts, then serializing back to a ZIP buffer.
|
|
1053
1183
|
*/
|
|
1054
|
-
var ParsedArchive = class {
|
|
1184
|
+
var ParsedArchive = class ParsedArchive {
|
|
1055
1185
|
source;
|
|
1056
1186
|
/** Compressed entries not yet inflated (empty on the eager fallback path). */
|
|
1057
1187
|
index;
|
|
@@ -1059,6 +1189,13 @@ var ParsedArchive = class {
|
|
|
1059
1189
|
parts = /* @__PURE__ */ new Map();
|
|
1060
1190
|
modified = /* @__PURE__ */ new Map();
|
|
1061
1191
|
wrapperCache = /* @__PURE__ */ new Map();
|
|
1192
|
+
/**
|
|
1193
|
+
* Central-directory order of every entry. keys() is ordered by this so a
|
|
1194
|
+
* bytes-backed archive (entries migrate index→parts as they are read) and
|
|
1195
|
+
* a Blob-backed one (hydrated wholesale) list parts identically — callers
|
|
1196
|
+
* compare parsed documents, and part order leaks into them.
|
|
1197
|
+
*/
|
|
1198
|
+
order;
|
|
1062
1199
|
constructor(data) {
|
|
1063
1200
|
this.source = data;
|
|
1064
1201
|
let entries;
|
|
@@ -1068,19 +1205,49 @@ var ParsedArchive = class {
|
|
|
1068
1205
|
const eager = unzipSync$1(data);
|
|
1069
1206
|
for (const [name, bytes] of Object.entries(eager)) this.parts.set(name, bytes);
|
|
1070
1207
|
this.index = /* @__PURE__ */ new Map();
|
|
1208
|
+
this.order = Object.keys(eager);
|
|
1071
1209
|
return;
|
|
1072
1210
|
}
|
|
1073
1211
|
this.index = new Map(entries.map((e) => [e.name, e]));
|
|
1212
|
+
this.order = entries.map((e) => e.name);
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Open an archive from bytes or a `Blob`/`File`. Bytes take the synchronous
|
|
1216
|
+
* constructor path; a Blob is read through {@link blobSource} random-access
|
|
1217
|
+
* windows — the package never materializes as one contiguous buffer — and
|
|
1218
|
+
* every entry is decompressed up front (oversized XML through the streaming
|
|
1219
|
+
* pipeline), so the returned archive serves the same synchronous
|
|
1220
|
+
* `get`/`getRaw` API as a bytes-backed one.
|
|
1221
|
+
*/
|
|
1222
|
+
static async open(data) {
|
|
1223
|
+
if (!(data instanceof Blob)) return new ParsedArchive(data);
|
|
1224
|
+
const source = blobSource(data);
|
|
1225
|
+
let entries;
|
|
1226
|
+
try {
|
|
1227
|
+
entries = await readCentralDirectoryAsync(source);
|
|
1228
|
+
} catch {
|
|
1229
|
+
return new ParsedArchive(await toUint8ArrayAsync(data));
|
|
1230
|
+
}
|
|
1231
|
+
const archive = Object.create(ParsedArchive.prototype);
|
|
1232
|
+
archive.source = source;
|
|
1233
|
+
archive.index = new Map(entries.map((e) => [e.name, e]));
|
|
1234
|
+
archive.parts = /* @__PURE__ */ new Map();
|
|
1235
|
+
archive.modified = /* @__PURE__ */ new Map();
|
|
1236
|
+
archive.wrapperCache = /* @__PURE__ */ new Map();
|
|
1237
|
+
archive.order = entries.map((e) => e.name);
|
|
1238
|
+
await hydrateArchive(archive);
|
|
1239
|
+
return archive;
|
|
1074
1240
|
}
|
|
1075
1241
|
/** Inflate and cache the compressed entry for `path`, if still compressed. */
|
|
1076
1242
|
inflate(path) {
|
|
1077
1243
|
const entry = this.index.get(path);
|
|
1078
1244
|
if (entry === void 0) return void 0;
|
|
1245
|
+
const bytes = this.source;
|
|
1079
1246
|
let data;
|
|
1080
1247
|
try {
|
|
1081
|
-
data = inflateZipEntry(
|
|
1248
|
+
data = inflateZipEntry(bytes, entry);
|
|
1082
1249
|
} catch {
|
|
1083
|
-
const raw =
|
|
1250
|
+
const raw = bytes.subarray(entry.dataStart, entry.dataStart + entry.compSize);
|
|
1084
1251
|
data = entry.method === 0 ? raw.slice() : inflateSync(raw);
|
|
1085
1252
|
}
|
|
1086
1253
|
if (path.endsWith(".xml")) data = stripOversizedGfxdata(data);
|
|
@@ -1147,13 +1314,16 @@ var ParsedArchive = class {
|
|
|
1147
1314
|
has(path) {
|
|
1148
1315
|
return this.modified.has(path) || this.parts.has(path) || this.index.has(path);
|
|
1149
1316
|
}
|
|
1150
|
-
/** List all paths matching an optional prefix. */
|
|
1317
|
+
/** List all paths matching an optional prefix, in central-directory order. */
|
|
1151
1318
|
keys(prefix) {
|
|
1152
|
-
const
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1319
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1320
|
+
const collect = (key) => {
|
|
1321
|
+
if (!prefix || key.startsWith(prefix)) seen.add(key);
|
|
1322
|
+
};
|
|
1323
|
+
for (const key of this.order) collect(key);
|
|
1324
|
+
for (const key of this.parts.keys()) collect(key);
|
|
1325
|
+
for (const key of this.modified.keys()) collect(key);
|
|
1326
|
+
return [...seen];
|
|
1157
1327
|
}
|
|
1158
1328
|
/** Serialize back to a ZIP buffer, inflating any untouched compressed entries. */
|
|
1159
1329
|
save() {
|
|
@@ -1161,7 +1331,7 @@ var ParsedArchive = class {
|
|
|
1161
1331
|
const collect = (path, data) => {
|
|
1162
1332
|
files[path] = [data, { level: levelForMediaName(path, 6) }];
|
|
1163
1333
|
};
|
|
1164
|
-
for (const path of
|
|
1334
|
+
for (const path of this.keys()) {
|
|
1165
1335
|
if (this.modified.has(path)) continue;
|
|
1166
1336
|
const data = this.parts.get(path) ?? this.inflate(path);
|
|
1167
1337
|
if (data !== void 0) collect(path, data);
|
|
@@ -1174,6 +1344,18 @@ var ParsedArchive = class {
|
|
|
1174
1344
|
function parseArchive(data) {
|
|
1175
1345
|
return new ParsedArchive(data);
|
|
1176
1346
|
}
|
|
1347
|
+
/** Decompress every indexed entry (Blob-backed open — after this, sync reads). */
|
|
1348
|
+
async function hydrateArchive(archive) {
|
|
1349
|
+
const source = archive.source;
|
|
1350
|
+
for (const entry of archive.index.values()) {
|
|
1351
|
+
const data = await inflateEntryFrom(source, entry).catch(async () => {
|
|
1352
|
+
const raw = await source.read(entry.dataStart, entry.compSize);
|
|
1353
|
+
return entry.method === 0 ? raw.slice() : inflateSync(raw);
|
|
1354
|
+
});
|
|
1355
|
+
archive.index.delete(entry.name);
|
|
1356
|
+
archive.parts.set(entry.name, data);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1177
1359
|
//#endregion
|
|
1178
1360
|
//#region src/opc/opc-consistency.ts
|
|
1179
1361
|
/**
|