@silurus/ooxml 0.74.6 → 0.75.0

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.
Files changed (47) hide show
  1. package/README.md +105 -6
  2. package/dist/bounded-raw-part-cache-BTfZD_Sz.js +1248 -0
  3. package/dist/{docx-DftZMp7R.js → document-pull-client-H80_E10V.js} +11165 -11517
  4. package/dist/docx-BX0mJqS1.js +1274 -0
  5. package/dist/docx.mjs +6 -3
  6. package/dist/docx_parser_bg.wasm +0 -0
  7. package/dist/duotone-bitmap-by-path-Dv5Ikbzl.js +28 -0
  8. package/dist/find-cursor-Dc5iM6s7.js +815 -0
  9. package/dist/highlight-rect-cCvVU-MW.js +48 -0
  10. package/dist/hyperlink-D85FexTa.js +27 -0
  11. package/dist/index.mjs +4 -4
  12. package/dist/{highlight-rect-IjFkGg4X.js → line-distribute-DkLgIa7B.js} +37 -84
  13. package/dist/{find-cursor-DtgyGs5V.js → line-metrics-qwIyTk7Q.js} +1169 -3641
  14. package/dist/math.mjs +1 -1
  15. package/dist/node.mjs +998 -0
  16. package/dist/pptx-BEYjiTnZ.js +822 -0
  17. package/dist/pptx-CXgyi7wu.js +1705 -0
  18. package/dist/pptx.mjs +7 -3
  19. package/dist/pptx_parser_bg.wasm +0 -0
  20. package/dist/preload-BEouWnlI.js +132 -0
  21. package/dist/render-C0wMf5eT.js +71 -0
  22. package/dist/render-worker-host-CLdOlxFu.js +27 -0
  23. package/dist/render-worker-host-DZ4u0RFs.js +27 -0
  24. package/dist/render-worker-host-s3J-mWBP.js +27 -0
  25. package/dist/renderer-CwzTv9hH.js +5225 -0
  26. package/dist/resource-measurement-6aReN3K0.js +93 -0
  27. package/dist/slide-pull-client-D_T0AIoX.js +175 -0
  28. package/dist/svg-image-by-path-C1M3N2pT.js +1623 -0
  29. package/dist/transfer-3QEJrsJa.js +6 -0
  30. package/dist/types/docx.d.ts +290 -105
  31. package/dist/types/index.d.ts +399 -142
  32. package/dist/types/math.d.ts +1 -1
  33. package/dist/types/node.d.ts +4855 -0
  34. package/dist/types/pptx.d.ts +431 -245
  35. package/dist/types/xlsx.d.ts +320 -120
  36. package/dist/visible-index-CKvgpUrf.js +17 -0
  37. package/dist/worksheet-pull-worker-DCei8u-4.js +347 -0
  38. package/dist/{xlsx-BqMHvfsE.js → xlsx-DJyPlzjB.js} +1499 -1284
  39. package/dist/xlsx.mjs +7 -3
  40. package/dist/xlsx_parser_bg.wasm +0 -0
  41. package/package.json +12 -2
  42. package/dist/pptx-qbadwIv4.js +0 -6761
  43. package/dist/render-worker-host-Bcm9j4-H.js +0 -27
  44. package/dist/render-worker-host-BqSTDaYt.js +0 -27
  45. package/dist/render-worker-host-C523QxVw.js +0 -27
  46. package/dist/visible-index-C3_3gBg-.js +0 -50
  47. /package/dist/{mathjax-BPjQ2C_j.js → mathjax-Dqo857oC.js} +0 -0
@@ -0,0 +1,6 @@
1
+ //#region packages/core/src/worker/transfer.ts
2
+ function e(e) {
3
+ return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength && e.buffer instanceof ArrayBuffer ? e.buffer : e.slice().buffer;
4
+ }
5
+ //#endregion
6
+ export { e as t };
@@ -1,4 +1,4 @@
1
- //#region dist/.types-work/mathjax-6BV6bQWa.d.ts
1
+ //#region dist/.types-work/mathjax-BO1uUSCW.d.ts
2
2
  //#region packages/core/src/math/mathjax.d.ts
3
3
  interface MathSvg {
4
4
  /** standalone `<svg>…</svg>` markup. */
@@ -29,7 +29,7 @@ interface MathRenderer {
29
29
  mathMLToSvg(mathml: string): Promise<MathSvg>;
30
30
  }
31
31
  //#endregion
32
- //#region dist/.types-work/find-highlight-B8ft6Y0g.d.ts
32
+ //#region dist/.types-work/hyperlink-CHHEOeCL.d.ts
33
33
  //#region packages/core/src/types/math.d.ts
34
34
  type MathStyle = 'roman' | 'italic' | 'bold' | 'boldItalic';
35
35
  interface MathRun {
@@ -963,7 +963,157 @@ interface LegendManualLayout {
963
963
  h: number;
964
964
  }
965
965
  //#endregion
966
+ //#region packages/core/src/errors/ooxml-error.d.ts
967
+ /**
968
+ * Machine-readable code for a typed load-time failure.
969
+ *
970
+ * The container-level failures the `load()` factories detect on the main thread
971
+ * before handing bytes to the parser worker (see `sniffCfb` / `decryptOoxml`).
972
+ * This is the seed of the broader typed-error surface tracked as PD4 (OoxmlError
973
+ * typed errors). Add codes here rather than throwing bare `Error(string)`, so
974
+ * callers can `switch` on `err.code` instead of matching message text.
975
+ *
976
+ * - `'encrypted'` — password-protected, but no `password` was
977
+ * supplied (pass `LoadOptions.password` to decrypt).
978
+ * - `'invalid-password'` — a `password` was supplied but did not match.
979
+ * - `'unsupported-encryption'`— encrypted with a scheme other than Agile
980
+ * (Standard / Extensible / a legacy binary encryptor), which this library
981
+ * cannot decrypt (PD8 implements Agile only).
982
+ * - `'legacy-binary-format'` — a raw .doc / .xls / .ppt (not OOXML).
983
+ * - `'not-ooxml'` — a CFB of an unrecognised kind, or otherwise
984
+ * not an OOXML ZIP.
985
+ */
986
+ type OoxmlErrorCode = 'encrypted' | 'invalid-password' | 'unsupported-encryption' | 'legacy-binary-format' | 'not-ooxml';
987
+ type OoxmlErrorStage = 'container' | 'decompression' | 'parsing' | 'serialization' | 'layout' | 'rendering' | 'worker';
988
+ /**
989
+ * @deprecated Use {@link OoxmlErrorStage}. Retained as a compatibility alias
990
+ * for the short-lived resource-governance API that exposed this vocabulary;
991
+ * scheduled for removal in a future breaking release.
992
+ */
993
+ type OoxmlErrorSource = 'container' | 'zip-part' | 'parser' | 'serializer' | 'layout' | 'renderer' | 'worker';
994
+ /**
995
+ * Typed error thrown by the docx / pptx / xlsx `load()` factories for failures
996
+ * that carry a stable, programmatic {@link OoxmlErrorCode} (e.g. a
997
+ * password-protected or legacy-binary file detected from its container magic).
998
+ *
999
+ * Note on workers: `instanceof OoxmlError` does not survive a structured-clone
1000
+ * across the worker boundary. Detection that needs a typed error is therefore
1001
+ * done on the main thread (before the worker is involved) so a genuine
1002
+ * `OoxmlError` instance is thrown to the caller. Errors that must cross the
1003
+ * worker boundary should carry the `code` string and be reconstructed on the
1004
+ * main side.
1005
+ */
1006
+ declare class OoxmlError extends Error {
1007
+ readonly code: OoxmlErrorCode;
1008
+ constructor(code: OoxmlErrorCode, message: string);
1009
+ }
1010
+ type OoxmlFormat = 'docx' | 'xlsx' | 'pptx';
1011
+ interface OoxmlResourceUsageSnapshot {
1012
+ readonly archiveEntryCount: number;
1013
+ readonly declaredInflatedBytes: number;
1014
+ /** Largest actual decompressed size observed for one ZIP entry. */
1015
+ readonly largestInflatedEntryBytes?: number;
1016
+ readonly distinctInflatedBytes: number;
1017
+ readonly operationInflatedBytes: number;
1018
+ }
1019
+ type ExtensibleLiteral<Known extends string> = Known | (string & Record<never, never>);
1020
+ /**
1021
+ * Resource family reported by a policy or hard-quota violation.
1022
+ *
1023
+ * The known literals provide editor completion. The string tail is deliberate:
1024
+ * adding a future format-owned unit must not break exhaustive switches compiled
1025
+ * against an older host while a newer worker is already able to report it.
1026
+ */
1027
+ type OoxmlResourceName = ExtensibleLiteral<'archive' | 'archive-entry' | 'xml-event' | 'xml-context' | 'xml-tree' | 'worksheet-row' | 'worksheet-shell'>;
1028
+ /** Measurement axis used by an OOXML resource violation. Extensible by design. */
1029
+ type OoxmlResourceMetric = ExtensibleLiteral<'declared-inflated-bytes' | 'actual-inflated-bytes' | 'entry-count' | 'central-directory-bytes' | 'distinct-inflated-bytes' | 'bytes' | 'depth' | 'projected-bytes'>;
1030
+ /** Stable public violation record. Valid resource/metric pairings are enforced
1031
+ * by the emitting parser and the worker decoder rather than by a closed public
1032
+ * union that would require a breaking expansion for every new hard quota. */
1033
+ interface OoxmlResourceViolation {
1034
+ readonly format: OoxmlFormat;
1035
+ readonly operation: string;
1036
+ readonly resource: OoxmlResourceName;
1037
+ readonly metric: OoxmlResourceMetric;
1038
+ readonly part?: string;
1039
+ readonly limit: number;
1040
+ readonly observed: number;
1041
+ readonly configurable: boolean;
1042
+ readonly usage: OoxmlResourceUsageSnapshot;
1043
+ }
1044
+ interface OoxmlResourceLimitErrorDetails {
1045
+ readonly stage: OoxmlErrorStage;
1046
+ readonly violation: OoxmlResourceViolation;
1047
+ }
1048
+ /** Deterministic rejection caused by a measured OOXML resource-policy breach. */
1049
+ declare class OoxmlResourceLimitError extends Error {
1050
+ readonly code: "ooxml-resource-limit";
1051
+ readonly details: OoxmlResourceLimitErrorDetails;
1052
+ constructor(message: string, details: OoxmlResourceLimitErrorDetails);
1053
+ }
1054
+ //#endregion
1055
+ //#region packages/core/src/types/resource-metrics.d.ts
1056
+ /** Configured public admission policy used for one measured operation. */
1057
+ interface OoxmlResourcePolicySnapshot {
1058
+ readonly maxArchiveEntryBytes: number | null;
1059
+ readonly maxTotalInflatedBytes: number | null;
1060
+ }
1061
+ interface OoxmlResourceMetricsCheckpoint {
1062
+ readonly name: string;
1063
+ readonly elapsedMs: number;
1064
+ readonly usage?: OoxmlResourceUsageSnapshot;
1065
+ }
1066
+ /**
1067
+ * Content-free, machine-readable resource report for an OOXML load or bounded
1068
+ * Node session. Byte counters describe measured package work, not the JavaScript
1069
+ * heap, WASM allocator overhead, decoded images, canvas, or GPU. Browser engines
1070
+ * and Viewers can return a newer snapshot after lazy package access.
1071
+ *
1072
+ * No source URL, filename, OOXML part name, document text, password, or raw
1073
+ * error message is included. Sizes, counts, and timings are still
1074
+ * document-derived metadata; applications apply their own consent, retention,
1075
+ * and telemetry policy.
1076
+ */
1077
+ interface OoxmlResourceMetrics {
1078
+ /** Version of this metrics payload, independent of the package version. */
1079
+ readonly schemaVersion: 1;
1080
+ /**
1081
+ * Browser factories report `load`; bounded Node sessions report `session`.
1082
+ */
1083
+ readonly scope: 'load' | 'session';
1084
+ readonly format: OoxmlFormat;
1085
+ readonly mode: 'main' | 'worker' | 'node';
1086
+ /** Outcome of this measured load/session, not of later render operations. */
1087
+ readonly status: 'ok' | 'error';
1088
+ /** Compressed or decrypted OOXML container bytes supplied to the parser. */
1089
+ readonly sourceBytes?: number;
1090
+ readonly elapsedMs: number;
1091
+ readonly policy: Readonly<OoxmlResourcePolicySnapshot>;
1092
+ /** Last complete observed package-usage checkpoint. */
1093
+ readonly usage?: OoxmlResourceUsageSnapshot;
1094
+ readonly checkpoints: readonly OoxmlResourceMetricsCheckpoint[];
1095
+ readonly outcome?: Readonly<Record<string, number>>;
1096
+ readonly error?: Readonly<{
1097
+ readonly code?: string;
1098
+ readonly stage?: string;
1099
+ readonly resource?: string;
1100
+ readonly metric?: string;
1101
+ }>;
1102
+ }
1103
+ //#endregion
966
1104
  //#region packages/core/src/types/load-options.d.ts
1105
+ /** A positive safe-integer byte count, or `null` to disable one public limit. */
1106
+ type OoxmlResourceLimit = number | null;
1107
+ /** Admission limits for the inflated contents of one OOXML package session. */
1108
+ interface OoxmlResourceLimits {
1109
+ /**
1110
+ * Maximum permitted inflated size for any one archive entry, including
1111
+ * media. Enforced against both the ZIP declaration and actual output.
1112
+ */
1113
+ maxArchiveEntryBytes?: OoxmlResourceLimit;
1114
+ /** Maximum actual inflated bytes across distinct entries in the session. */
1115
+ maxTotalInflatedBytes?: OoxmlResourceLimit;
1116
+ }
967
1117
  /**
968
1118
  * Common load-time options shared by the docx / pptx / xlsx
969
1119
  * `Document.load` / `Presentation.load` / `Workbook.load` factories and their
@@ -1030,12 +1180,44 @@ interface LoadOptions$1 {
1030
1180
  */
1031
1181
  wasmUrl?: string | URL;
1032
1182
  /**
1033
- * Override the per-entry ZIP decompression cap (bytes) used by the zip-bomb
1034
- * guard in the Rust parser. Defaults to 512 MiB. Raise it to load documents
1035
- * with very large embedded media, or lower it to tighten the budget for
1036
- * untrusted input. Zero / negative values fall back to the default.
1183
+ * @deprecated Use `resourceLimits.maxArchiveEntryBytes`. Scheduled for
1184
+ * removal in a future breaking release.
1185
+ *
1186
+ * Existing positive safe-integer values remain an all-entry inflated-byte
1187
+ * limit. Zero, negative, and NaN values retain their historical fallback
1188
+ * behavior; other invalid positive values reject during `load()`.
1037
1189
  */
1038
1190
  maxZipEntryBytes?: number;
1191
+ /**
1192
+ * Inflated archive admission limits for one document session. Omitted fields
1193
+ * use the library defaults. A positive safe integer overrides a default;
1194
+ * `null` disables that configurable limit only. Limits are admission policy,
1195
+ * not guarantees of exact browser-process memory use.
1196
+ */
1197
+ resourceLimits?: OoxmlResourceLimits;
1198
+ /**
1199
+ * Emit one content-free resource-usage card after load succeeds or fails.
1200
+ * Includes observed archive counters and configured limits, but never source
1201
+ * URLs, part names, document text, passwords, or error messages.
1202
+ */
1203
+ debug?: boolean;
1204
+ /**
1205
+ * Receive the initial content-free, machine-readable report that powers the
1206
+ * debug card, without enabling console output. After resource options validate,
1207
+ * the callback runs once when the current load settles, including failed loads
1208
+ * for which no renderer instance is returned. The callback is not awaited;
1209
+ * synchronous exceptions and rejected promises are ignored and never change
1210
+ * load results.
1211
+ *
1212
+ * A browser report covers the underlying document/workbook/presentation
1213
+ * factory. It does not wait for a Viewer's first canvas paint; that paint and
1214
+ * later lazy worksheet, slide, image, or media access may increase counters or
1215
+ * surface a separate render error. Successfully opened packages include the
1216
+ * declared package total and source byte size in the report. On a successful
1217
+ * load, call `getResourceMetrics()` on the returned engine or Viewer for a fresh
1218
+ * snapshot that includes subsequently observed lazy package work.
1219
+ */
1220
+ onResourceMetrics?: (metrics: OoxmlResourceMetrics) => void;
1039
1221
  /**
1040
1222
  * Reject the parse request if the parser worker does not answer within this
1041
1223
  * many milliseconds. Opt-in safety net for a wedged or crashed worker that
@@ -1058,44 +1240,81 @@ interface LoadOptions$1 {
1058
1240
  math?: MathRenderer;
1059
1241
  }
1060
1242
  //#endregion
1061
- //#region packages/core/src/errors/ooxml-error.d.ts
1243
+ //#region packages/core/src/image/pixel-budget.d.ts
1244
+ type OoxmlDecodedImageLimitMetric = 'image-pixels' | 'active-decoded-bytes';
1245
+ /** Catchable hard-quota crossing for decoded image surfaces. */
1246
+ declare class OoxmlDecodedImageLimitError extends RangeError {
1247
+ readonly metric: OoxmlDecodedImageLimitMetric;
1248
+ readonly limit: number;
1249
+ readonly observed: number;
1250
+ readonly code: "ooxml-decoded-image-limit";
1251
+ constructor(metric: OoxmlDecodedImageLimitMetric, limit: number, observed: number);
1252
+ }
1253
+ declare function isOoxmlDecodedImageLimitError(error: unknown): error is OoxmlDecodedImageLimitError;
1254
+ //#endregion
1255
+ //#region packages/core/src/interaction/hyperlink.d.ts
1062
1256
  /**
1063
- * Machine-readable code for a typed load-time failure.
1257
+ * Shared hyperlink model + URL sanitisation for docx / pptx / xlsx (IX1).
1064
1258
  *
1065
- * The container-level failures the `load()` factories detect on the main thread
1066
- * before handing bytes to the parser worker (see `sniffCfb` / `decryptOoxml`).
1067
- * This is the seed of the broader typed-error surface tracked as PD4 (OoxmlError
1068
- * typed errors). Add codes here rather than throwing bare `Error(string)`, so
1069
- * callers can `switch` on `err.code` instead of matching message text.
1259
+ * All three formats carry the same two ECMA-376 concepts:
1260
+ * - an **external** hyperlink an absolute URL resolved from a relationship
1261
+ * part target (`document.xml.rels` for docx §17.16.22, the slide rels for
1262
+ * pptx §21.1.2.3.5, the worksheet rels for xlsx §18.3.1.47), with
1263
+ * `TargetMode="External"`.
1264
+ * - an **internal** hyperlink — a jump within the document itself:
1265
+ * docx `w:anchor` -> a `<w:bookmarkStart w:name>` (§17.16.23), pptx
1266
+ * `action="ppaction://hlinksldjump"` -> a slide, xlsx `location` -> a defined
1267
+ * name or a `Sheet!A1` cell reference.
1070
1268
  *
1071
- * - `'encrypted'` — password-protected, but no `password` was
1072
- * supplied (pass `LoadOptions.password` to decrypt).
1073
- * - `'invalid-password'` — a `password` was supplied but did not match.
1074
- * - `'unsupported-encryption'`— encrypted with a scheme other than Agile
1075
- * (Standard / Extensible / a legacy binary encryptor), which this library
1076
- * cannot decrypt (PD8 implements Agile only).
1077
- * - `'legacy-binary-format'` — a raw .doc / .xls / .ppt (not OOXML).
1078
- * - `'not-ooxml'` — a CFB of an unrecognised kind, or otherwise
1079
- * not an OOXML ZIP.
1269
+ * The parsers (Rust, one per format) do the format-specific rels lookup and hand
1270
+ * each run / shape / cell a {@link HyperlinkTarget}. Everything downstream — the
1271
+ * text-layer overlay, the viewer default click behaviour, and any integrator
1272
+ * callback — is format-agnostic and consumes this one shape. Keeping the type +
1273
+ * the pure `sanitizeHyperlinkUrl` predicate here (not duplicated per package)
1274
+ * follows the cross-package unification principle: a scheme-allowlist bug fixed
1275
+ * once is fixed everywhere.
1080
1276
  */
1081
- type OoxmlErrorCode = 'encrypted' | 'invalid-password' | 'unsupported-encryption' | 'legacy-binary-format' | 'not-ooxml';
1082
1277
  /**
1083
- * Typed error thrown by the docx / pptx / xlsx `load()` factories for failures
1084
- * that carry a stable, programmatic {@link OoxmlErrorCode} (e.g. a
1085
- * password-protected or legacy-binary file detected from its container magic).
1278
+ * A resolved hyperlink attached to a run, shape, or cell.
1086
1279
  *
1087
- * Note on workers: `instanceof OoxmlError` does not survive a structured-clone
1088
- * across the worker boundary. Detection that needs a typed error is therefore
1089
- * done on the main thread (before the worker is involved) so a genuine
1090
- * `OoxmlError` instance is thrown to the caller. Errors that must cross the
1091
- * worker boundary should carry the `code` string and be reconstructed on the
1092
- * main side.
1280
+ * - `external` `url` is the raw target as authored in the file. It is NOT
1281
+ * guaranteed safe; run it through {@link sanitizeHyperlinkUrl} before
1282
+ * navigating. It is kept verbatim here so an integrator can apply its own
1283
+ * policy (e.g. allow `file:` on a trusted intranet viewer).
1284
+ * - `internal` `ref` is the in-document destination, verbatim from the file:
1285
+ * docx: the bookmark name (`w:anchor`).
1286
+ * pptx: the internal action (e.g. `ppaction://hlinksldjump`), with the
1287
+ * resolved 0-based `slideIndex` when the rels target names a slide.
1288
+ * xlsx: the `location` string (a defined name or `Sheet1!A1`).
1093
1289
  */
1094
- declare class OoxmlError extends Error {
1095
- readonly code: OoxmlErrorCode;
1096
- constructor(code: OoxmlErrorCode, message: string);
1097
- }
1290
+ type HyperlinkTarget = {
1291
+ kind: 'external';
1292
+ url: string;
1293
+ } | {
1294
+ kind: 'internal';
1295
+ ref: string;
1296
+ slideIndex?: number;
1297
+ };
1298
+ /**
1299
+ * The default action a viewer takes for an **external** hyperlink click when
1300
+ * the integrator supplies no `onHyperlinkClick` handler: sanitise the URL and,
1301
+ * if allowed, open it in a new tab with `noopener,noreferrer` so the opened page
1302
+ * gets no `window.opener` handle back into this document. A blocked scheme is a
1303
+ * silent no-op (returns `false`) — the click does nothing rather than navigate
1304
+ * somewhere dangerous.
1305
+ *
1306
+ * Internal targets are intentionally NOT handled here: the in-document jump
1307
+ * (page / slide / cell) is format-specific and lives in each viewer.
1308
+ *
1309
+ * Split out (not inlined in three viewers) so the "open in new tab, drop opener,
1310
+ * refuse unsafe schemes" policy is defined once. `win` is injected for tests;
1311
+ * defaults to the ambient `window`.
1312
+ *
1313
+ * @returns `true` if navigation was initiated, `false` if the URL was blocked.
1314
+ */
1315
+ declare function openExternalHyperlink(url: string, allowed?: readonly string[], win?: Pick<Window, 'open'> | undefined): boolean;
1098
1316
  //#endregion
1317
+ //#region dist/.types-work/find-highlight-gMP3FAnW.d.ts
1099
1318
  //#region packages/core/src/autoResize.d.ts
1100
1319
  interface AutoResizeOptions {
1101
1320
  /**
@@ -1208,68 +1427,6 @@ interface ZoomableViewer {
1208
1427
  fitPage(): void | Promise<void>;
1209
1428
  }
1210
1429
  //#endregion
1211
- //#region packages/core/src/interaction/hyperlink.d.ts
1212
- /**
1213
- * Shared hyperlink model + URL sanitisation for docx / pptx / xlsx (IX1).
1214
- *
1215
- * All three formats carry the same two ECMA-376 concepts:
1216
- * - an **external** hyperlink — an absolute URL resolved from a relationship
1217
- * part target (`document.xml.rels` for docx §17.16.22, the slide rels for
1218
- * pptx §21.1.2.3.5, the worksheet rels for xlsx §18.3.1.47), with
1219
- * `TargetMode="External"`.
1220
- * - an **internal** hyperlink — a jump within the document itself:
1221
- * docx `w:anchor` -> a `<w:bookmarkStart w:name>` (§17.16.23), pptx
1222
- * `action="ppaction://hlinksldjump"` -> a slide, xlsx `location` -> a defined
1223
- * name or a `Sheet!A1` cell reference.
1224
- *
1225
- * The parsers (Rust, one per format) do the format-specific rels lookup and hand
1226
- * each run / shape / cell a {@link HyperlinkTarget}. Everything downstream — the
1227
- * text-layer overlay, the viewer default click behaviour, and any integrator
1228
- * callback — is format-agnostic and consumes this one shape. Keeping the type +
1229
- * the pure `sanitizeHyperlinkUrl` predicate here (not duplicated per package)
1230
- * follows the cross-package unification principle: a scheme-allowlist bug fixed
1231
- * once is fixed everywhere.
1232
- */
1233
- /**
1234
- * A resolved hyperlink attached to a run, shape, or cell.
1235
- *
1236
- * - `external` — `url` is the raw target as authored in the file. It is NOT
1237
- * guaranteed safe; run it through {@link sanitizeHyperlinkUrl} before
1238
- * navigating. It is kept verbatim here so an integrator can apply its own
1239
- * policy (e.g. allow `file:` on a trusted intranet viewer).
1240
- * - `internal` — `ref` is the in-document destination, verbatim from the file:
1241
- * docx: the bookmark name (`w:anchor`).
1242
- * pptx: the internal action (e.g. `ppaction://hlinksldjump`), with the
1243
- * resolved 0-based `slideIndex` when the rels target names a slide.
1244
- * xlsx: the `location` string (a defined name or `Sheet1!A1`).
1245
- */
1246
- type HyperlinkTarget = {
1247
- kind: 'external';
1248
- url: string;
1249
- } | {
1250
- kind: 'internal';
1251
- ref: string;
1252
- slideIndex?: number;
1253
- };
1254
- /**
1255
- * The default action a viewer takes for an **external** hyperlink click when
1256
- * the integrator supplies no `onHyperlinkClick` handler: sanitise the URL and,
1257
- * if allowed, open it in a new tab with `noopener,noreferrer` so the opened page
1258
- * gets no `window.opener` handle back into this document. A blocked scheme is a
1259
- * silent no-op (returns `false`) — the click does nothing rather than navigate
1260
- * somewhere dangerous.
1261
- *
1262
- * Internal targets are intentionally NOT handled here: the in-document jump
1263
- * (page / slide / cell) is format-specific and lives in each viewer.
1264
- *
1265
- * Split out (not inlined in three viewers) so the "open in new tab, drop opener,
1266
- * refuse unsafe schemes" policy is defined once. `win` is injected for tests;
1267
- * defaults to the ambient `window`.
1268
- *
1269
- * @returns `true` if navigation was initiated, `false` if the URL was blocked.
1270
- */
1271
- declare function openExternalHyperlink(url: string, allowed?: readonly string[], win?: Pick<Window, 'open'> | undefined): boolean;
1272
- //#endregion
1273
1430
  //#region packages/core/src/search/text-index.d.ts
1274
1431
  /**
1275
1432
  * The slice of one run a match covers: the run's index in the original `runs[]`
@@ -1344,7 +1501,7 @@ interface FindHighlightColors {
1344
1501
  active?: string;
1345
1502
  }
1346
1503
  //#endregion
1347
- //#region dist/.types-work/docx-BatSd3II.d.ts
1504
+ //#region dist/.types-work/renderer-CU7Ays06.d.ts
1348
1505
  //#region packages/docx/src/types.d.ts
1349
1506
  interface DocxDocumentModel {
1350
1507
  section: SectionProps;
@@ -2875,14 +3032,15 @@ interface DocxTextRunInfo {
2875
3032
  eastAsianVert?: boolean;
2876
3033
  }
2877
3034
  //#endregion
3035
+ //#region dist/.types-work/docx-VDKt2JLe.d.ts
2878
3036
  //#region packages/docx/src/worker-protocol.d.ts
2879
3037
  /** Serializable subset of RenderPageOptions (callbacks cannot cross the wire). */
2880
3038
  type WireRenderPageOptions = Omit<RenderPageOptions, 'onTextRun'>;
2881
3039
  //#endregion
2882
3040
  //#region packages/docx/src/document.d.ts
2883
3041
  /** Options for {@link DocxDocument.load}. Extends the shared load-options type
2884
- * from `@silurus/ooxml-core` (`useGoogleFonts`, `maxZipEntryBytes`) with the
2885
- * opt-in math engine. */
3042
+ * from `@silurus/ooxml-core` (`useGoogleFonts`, `resourceLimits`, and the
3043
+ * deprecated `maxZipEntryBytes` alias) with the opt-in math engine. */
2886
3044
  interface LoadOptions extends LoadOptions$1 {
2887
3045
  /**
2888
3046
  * Opt-in OMML equation engine. Import it from the separate `@silurus/ooxml/math`
@@ -2910,7 +3068,9 @@ type RenderPageToBitmapOptions = WireRenderPageOptions & {
2910
3068
  onTextRun?: (run: DocxTextRunInfo) => void;
2911
3069
  };
2912
3070
  declare class DocxDocument {
3071
+ private _metrics;
2913
3072
  private _document;
3073
+ private _source;
2914
3074
  private _meta;
2915
3075
  /** Lazily-built `bookmarkName → 0-based page index` map for internal hyperlink
2916
3076
  * anchors (IX-nav). Built on first {@link getBookmarkPage} from the paginated
@@ -2920,7 +3080,7 @@ declare class DocxDocument {
2920
3080
  private _mode;
2921
3081
  private _worker;
2922
3082
  private _bridge;
2923
- private _imageCache;
3083
+ private readonly _rawParts;
2924
3084
  /** Embedded `FontFace` objects this document registered into `document.fonts`
2925
3085
  * (main mode only — in worker mode the worker owns them and terminates with
2926
3086
  * its own FontFaceSet). Released in {@link destroy} so they do not leak into
@@ -2962,6 +3122,11 @@ declare class DocxDocument {
2962
3122
  * which de-obfuscates (ECMA-376 §17.8.1) and registers each as a FontFace.
2963
3123
  */
2964
3124
  getFontBytes(partPath: string): Promise<Uint8Array>;
3125
+ private _resourceUsage;
3126
+ /** Return a fresh content-free metrics snapshot, including lazy archive work
3127
+ * completed since load. Collection is always active; `debug` only controls
3128
+ * console presentation. */
3129
+ getResourceMetrics(): Promise<OoxmlResourceMetrics>;
2965
3130
  /**
2966
3131
  * Project the document to GitHub-flavoured markdown: headings (from
2967
3132
  * `<w:outlineLvl>`), bullet / numbered lists, tables (with vMerge
@@ -3116,7 +3281,19 @@ interface DocxViewerOptions extends RenderPageOptions, LoadOptions {
3116
3281
  * text. Set it to disable clickable links entirely — e.g. in a preview where
3117
3282
  * navigation must not leave the current view. */
3118
3283
  enableHyperlinks?: boolean;
3119
- /** Called on parse or render errors. */
3284
+ /**
3285
+ * Receives load failures and asynchronous render failures handled by the
3286
+ * Viewer. Supplying this callback changes load-failure delivery: `load()`
3287
+ * invokes it and resolves; without it, the same load/parse failure rejects
3288
+ * `load()`. Viewer-managed render failures invoke it, or fall back to
3289
+ * `console.error` when omitted.
3290
+ *
3291
+ * Stable cases can be narrowed with `OoxmlError`,
3292
+ * `OoxmlResourceLimitError`, or `OoxmlDecodedImageLimitError` re-exported by
3293
+ * this package. Other failures remain `Error` values; do not parse message
3294
+ * text as an API. A `code` of `parser-crashed` identifies a recognized WASM
3295
+ * trap, not a reliably classified OOM.
3296
+ */
3120
3297
  onError?: (err: Error) => void;
3121
3298
  }
3122
3299
  declare class DocxViewer implements ZoomableViewer {
@@ -3287,6 +3464,8 @@ declare class DocxViewer implements ZoomableViewer {
3287
3464
  /** Rebuild the highlight overlay for the current page from cached runs
3288
3465
  * (no page re-render). */
3289
3466
  private _redrawHighlights;
3467
+ /** Latest content-free resource metrics for the loaded document. */
3468
+ getResourceMetrics(): Promise<OoxmlResourceMetrics>;
3290
3469
  /**
3291
3470
  * Terminate the parser worker and release resources.
3292
3471
  *
@@ -3457,7 +3636,11 @@ interface DocxScrollViewerOptions extends Omit<RenderPageOptions, 'onTextRun'>,
3457
3636
  * per-slot render failures (both main `renderPage` and worker
3458
3637
  * `renderPageToBitmap` rejections); a failed page is left blank rather than
3459
3638
  * crashing the loop. Without an `onError`, render failures are logged via
3460
- * `console.error` so they are never fully silent. */
3639
+ * `console.error` so they are never fully silent. Stable cases can be
3640
+ * narrowed with `OoxmlError`, `OoxmlResourceLimitError`, or
3641
+ * `OoxmlDecodedImageLimitError` re-exported by this package. Other failures
3642
+ * remain `Error` values; a `code` of `parser-crashed` identifies a recognized
3643
+ * WASM trap, not a reliably classified OOM. */
3461
3644
  onError?: (err: Error) => void;
3462
3645
  }
3463
3646
  declare class DocxScrollViewer implements ZoomableViewer {
@@ -3918,6 +4101,8 @@ declare class DocxScrollViewer implements ZoomableViewer {
3918
4101
  */
3919
4102
  private _onResize;
3920
4103
  get topVisiblePage(): number;
4104
+ /** Return the owning engine's latest content-free package-usage snapshot. */
4105
+ getResourceMetrics(): Promise<OoxmlResourceMetrics>;
3921
4106
  /**
3922
4107
  * Tear down the viewer: remove the DOM subtree and (only for a self-loaded
3923
4108
  * engine) destroy the engine. An injected engine is left intact — the caller
@@ -4004,4 +4189,4 @@ type DocxHighlightColors = FindHighlightColors;
4004
4189
  */
4005
4190
  declare function buildDocxHighlightLayer(layer: HTMLDivElement, runs: DocxTextRunInfo[], matches: DocxHighlightMatch[], cssWidth: number, cssHeight: number, measureForFont: (font: string) => (s: string) => number, colors?: DocxHighlightColors): void;
4006
4191
  //#endregion
4007
- export { type AnchorHostMetrics, type AutoResizeOptions, type BodyElement, type BorderSpec, type CellBorders, type CellElement, type ChartRun, type ColSpec, type ColumnsSpec, type DocComment, type DocNote, type DocParagraph, type DocRevision, type DocRun, type DocSettings, type DocTable, type DocTableCell, type DocTableRow, DocxDocument, type DocxDocumentModel, type DocxHighlightColors, type DocxHighlightMatch, type DocxMatchLocation, type DocxRunBorder, DocxScrollViewer, type DocxScrollViewerOptions, type DocxTextRun, type DocxTextRunInfo, DocxViewer, type DocxViewerOptions, type EmbeddedFontRef, type FieldRun, type FindHighlightColors, type FindMatch, type FindMatchesOptions, type FramePr, type GradientStop, type HeaderFooter, type HeadersFooters, type HyperlinkTarget, type ImageRun, type LineEnd, type LineNumbering, type LineSpacing, type LoadOptions, type NoteRef, type NumberingInfo, OoxmlError, type OoxmlErrorCode, type PTabRun, type PageBorderEdge, type PageBorders, type PageNumType, type ParaBorderEdge, type ParagraphBorders, type PathCmd, type RenderPageOptions, type RenderPageToBitmapOptions, type RubyAnnotation, type RunRevision, type SectionGeom, type SectionProps, type ShapeRun, type ShapeText, type ShapeTextRun, type TabStop, type TableBorders, type TblpPr, type TextPath, type WireRenderPageOptions, autoResize, buildDocxHighlightLayer, buildDocxTextLayer, noteText, openExternalHyperlink };
4192
+ export { type AnchorHostMetrics, type AutoResizeOptions, type BodyElement, type BorderSpec, type CellBorders, type CellElement, type ChartRun, type ColSpec, type ColumnsSpec, type DocComment, type DocNote, type DocParagraph, type DocRevision, type DocRun, type DocSettings, type DocTable, type DocTableCell, type DocTableRow, DocxDocument, type DocxDocumentModel, type DocxHighlightColors, type DocxHighlightMatch, type DocxMatchLocation, type DocxRunBorder, DocxScrollViewer, type DocxScrollViewerOptions, type DocxTextRun, type DocxTextRunInfo, DocxViewer, type DocxViewerOptions, type EmbeddedFontRef, type FieldRun, type FindHighlightColors, type FindMatch, type FindMatchesOptions, type FramePr, type GradientStop, type HeaderFooter, type HeadersFooters, type HyperlinkTarget, type ImageRun, type LineEnd, type LineNumbering, type LineSpacing, type LoadOptions, type NoteRef, type NumberingInfo, OoxmlDecodedImageLimitError, type OoxmlDecodedImageLimitMetric, OoxmlError, type OoxmlErrorCode, type OoxmlErrorSource, type OoxmlErrorStage, type OoxmlFormat, type OoxmlResourceLimit, OoxmlResourceLimitError, type OoxmlResourceLimitErrorDetails, type OoxmlResourceLimits, type OoxmlResourceMetric, type OoxmlResourceMetrics, type OoxmlResourceMetricsCheckpoint, type OoxmlResourceName, type OoxmlResourcePolicySnapshot, type OoxmlResourceUsageSnapshot, type OoxmlResourceViolation, type PTabRun, type PageBorderEdge, type PageBorders, type PageNumType, type ParaBorderEdge, type ParagraphBorders, type PathCmd, type RenderPageOptions, type RenderPageToBitmapOptions, type RubyAnnotation, type RunRevision, type SectionGeom, type SectionProps, type ShapeRun, type ShapeText, type ShapeTextRun, type TabStop, type TableBorders, type TblpPr, type TextPath, type WireRenderPageOptions, autoResize, buildDocxHighlightLayer, buildDocxTextLayer, isOoxmlDecodedImageLimitError, noteText, openExternalHyperlink };