@silurus/ooxml 0.76.1 → 0.77.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.
@@ -1,5 +1,5 @@
1
1
  import { t as e } from "./chunk-DmhlhrBa.js";
2
- import { c as t, i as n } from "./slide-pull-client-WCuYCjio.js";
2
+ import { c as t, i as n } from "./slide-pull-client-BXb67StB.js";
3
3
  import { B as r, F as i, H as a, I as o, K as s, P as c, R as l, at as u, dt as d, ft as f, hn as p, it as m, lt as h, ot as g, rt as _, st as v, ut as y } from "./line-metrics-BdCACYlq.js";
4
4
  import { t as b } from "./transfer-DCu4c2BL.js";
5
5
  //#region packages/pptx/src/slide-cursor-operation.ts
@@ -5184,19 +5184,23 @@ async function Mr(e, t, r, i, a = {}, s, l) {
5184
5184
  });
5185
5185
  })), d())) return e;
5186
5186
  }
5187
- for (let n of t.elements) {
5187
+ for (let [n, r] of t.elements.entries()) {
5188
5188
  if (d()) return e;
5189
- if (n.type === "shape") cr(b, n, m, x, w, C, s, a.fetchImage);
5190
- else if (n.type === "picture") await Sr(b, n, m, d, a.fetchImage);
5191
- else if (n.type === "table") Er(b, n, m, w, C);
5192
- else if (n.type === "media") await Cr(b, n, m, d, a.fetchMedia, a.skipMediaControls, a.fetchImage);
5193
- else if (n.type === "chart") {
5189
+ if (r.type === "shape") cr(b, r, m, x, w, C, s ? (e) => s({
5190
+ ...e,
5191
+ elementIndex: n,
5192
+ origin: t.elementSources?.[n]?.origin ?? "slide"
5193
+ }) : void 0, a.fetchImage);
5194
+ else if (r.type === "picture") await Sr(b, r, m, d, a.fetchImage);
5195
+ else if (r.type === "table") Er(b, r, m, w, C);
5196
+ else if (r.type === "media") await Cr(b, r, m, d, a.fetchMedia, a.skipMediaControls, a.fetchImage);
5197
+ else if (r.type === "chart") {
5194
5198
  let e = K * m;
5195
- b.save(), Tr(b, n, m), c(b, n.chart, {
5196
- x: J(n.x, m),
5197
- y: J(n.y, m),
5198
- w: J(n.width, m),
5199
- h: J(n.height, m)
5199
+ b.save(), Tr(b, r, m), c(b, r.chart, {
5200
+ x: J(r.x, m),
5201
+ y: J(r.y, m),
5202
+ w: J(r.width, m),
5203
+ h: J(r.height, m)
5200
5204
  }, e), b.restore();
5201
5205
  }
5202
5206
  }
@@ -10,7 +10,7 @@ interface MathRenderer {
10
10
  mathMLToSvg(mathml: string): Promise<MathSvg>;
11
11
  }
12
12
  //#endregion
13
- //#region dist/.types-work/hyperlink-BnJnsq2_.d.ts
13
+ //#region dist/.types-work/hyperlink-BqgLAFOG.d.ts
14
14
  type MathStyle = 'roman' | 'italic' | 'bold' | 'boldItalic';
15
15
  interface MathRun {
16
16
  kind: 'run';
@@ -383,9 +383,14 @@ interface LegendManualLayout {
383
383
  w: number;
384
384
  h: number;
385
385
  }
386
+ interface ChartRect {
387
+ x: number;
388
+ y: number;
389
+ w: number;
390
+ h: number;
391
+ }
386
392
  type OoxmlErrorCode = 'encrypted' | 'invalid-password' | 'unsupported-encryption' | 'legacy-binary-format' | 'not-ooxml';
387
393
  type OoxmlErrorStage = 'container' | 'decompression' | 'parsing' | 'serialization' | 'layout' | 'rendering' | 'worker';
388
- type OoxmlErrorSource = 'container' | 'zip-part' | 'parser' | 'serializer' | 'layout' | 'renderer' | 'worker';
389
394
  declare class OoxmlError extends Error {
390
395
  readonly code: OoxmlErrorCode;
391
396
  constructor(code: OoxmlErrorCode, message: string);
@@ -486,7 +491,15 @@ type HyperlinkTarget = {
486
491
  };
487
492
  declare function openExternalHyperlink(url: string, allowed?: readonly string[], win?: Pick<Window, 'open'> | undefined): boolean;
488
493
  //#endregion
489
- //#region dist/.types-work/find-highlight-DkZhNxUb.d.ts
494
+ //#region dist/.types-work/find-highlight-DcNlrW8O.d.ts
495
+ interface TextSelectionContextOptions {
496
+ readonly maxTextCharacters?: number;
497
+ readonly maxRunLocators?: number;
498
+ }
499
+ interface ViewerContextMenuEvent<TContext> {
500
+ readonly originalEvent: MouseEvent;
501
+ getContext(): Promise<TContext | null>;
502
+ }
490
503
  interface AutoResizeOptions {
491
504
  pauseWhenHidden?: boolean;
492
505
  }
@@ -517,7 +530,7 @@ interface FindHighlightColors {
517
530
  active?: string;
518
531
  }
519
532
  //#endregion
520
- //#region dist/.types-work/docx-C5SBoWU-.d.ts
533
+ //#region dist/.types-work/docx-BkK3rbgp.d.ts
521
534
  interface DocxDocumentModel {
522
535
  section: SectionProps;
523
536
  body: BodyElement[];
@@ -688,6 +701,7 @@ interface DocParagraph {
688
701
  markVanish?: boolean;
689
702
  widowControl?: boolean;
690
703
  overflowPunct?: boolean;
704
+ adjustRightInd?: boolean;
691
705
  borders?: ParagraphBorders | null;
692
706
  styleId?: string | null;
693
707
  defaultFontSize?: number;
@@ -873,7 +887,7 @@ interface ShapeRun {
873
887
  stroke: string | null;
874
888
  strokeWidth?: number;
875
889
  strokeDash?: string | null;
876
- strokeCap?: CanvasLineCap | null;
890
+ strokeCap?: 'butt' | 'round' | 'square' | null;
877
891
  headEnd?: LineEnd | null;
878
892
  tailEnd?: LineEnd | null;
879
893
  rotation?: number;
@@ -1168,24 +1182,12 @@ interface CellBorders {
1168
1182
  insideH: BorderSpec | null;
1169
1183
  insideV: BorderSpec | null;
1170
1184
  }
1171
- interface RenderPageOptions {
1172
- width?: number;
1173
- dpr?: number;
1174
- defaultTextColor?: string;
1175
- onTextRun?: (run: {
1176
- text: string;
1177
- x: number;
1178
- y: number;
1179
- w: number;
1180
- h: number;
1181
- fontSize: number;
1182
- font: string;
1183
- transform?: string;
1184
- }) => void;
1185
- showTrackChanges?: boolean;
1186
- currentDate?: Date | number;
1187
- }
1188
1185
  interface DocxTextRunInfo {
1186
+ source?: Readonly<{
1187
+ story: 'body' | 'header' | 'footer' | 'footnote' | 'endnote' | 'textbox';
1188
+ storyInstance: string;
1189
+ path: readonly number[];
1190
+ }>;
1189
1191
  paragraphId?: string;
1190
1192
  text: string;
1191
1193
  x: number;
@@ -1199,12 +1201,74 @@ interface DocxTextRunInfo {
1199
1201
  hyperlink?: HyperlinkTarget;
1200
1202
  eastAsianVert?: boolean;
1201
1203
  }
1202
- type WireRenderPageOptions = Omit<RenderPageOptions, 'onTextRun'>;
1204
+ interface RenderPageOptions {
1205
+ width?: number;
1206
+ dpr?: number;
1207
+ defaultTextColor?: string;
1208
+ onTextRun?: (run: DocxTextRunInfo) => void;
1209
+ currentDate?: Date | number;
1210
+ }
1211
+ type DocxSelectionContextOptions = TextSelectionContextOptions;
1212
+ interface DocxSelectionSourceLocator {
1213
+ readonly story: 'body' | 'header' | 'footer' | 'footnote' | 'endnote' | 'textbox';
1214
+ readonly storyInstance: string;
1215
+ readonly path: readonly number[];
1216
+ }
1217
+ interface DocxSelectionRunLocator {
1218
+ readonly pageIndex: number;
1219
+ readonly runIndex: number;
1220
+ readonly paragraphId?: string;
1221
+ readonly source?: DocxSelectionSourceLocator;
1222
+ }
1223
+ interface DocxTextSelectionContext {
1224
+ readonly format: 'docx';
1225
+ readonly kind: 'text';
1226
+ readonly text: string;
1227
+ readonly pageIndexes: readonly number[];
1228
+ readonly paragraphIds: readonly string[];
1229
+ readonly runs: readonly DocxSelectionRunLocator[];
1230
+ readonly truncated: boolean;
1231
+ readonly truncationReasons: readonly ('text' | 'runs')[];
1232
+ readonly textCharacters: number;
1233
+ readonly maxTextCharacters: number;
1234
+ readonly maxRunLocators: number;
1235
+ }
1236
+ interface DocxPagePoint {
1237
+ readonly xPt: number;
1238
+ readonly yPt: number;
1239
+ }
1240
+ interface DocxElementContext {
1241
+ readonly format: 'docx';
1242
+ readonly kind: 'element';
1243
+ readonly pageIndex: number;
1244
+ readonly elementIndex: number;
1245
+ readonly elementType: 'chart' | 'image' | 'shape';
1246
+ readonly point: DocxPagePoint;
1247
+ readonly bounds: Readonly<DocxPagePoint & {
1248
+ widthPt: number;
1249
+ heightPt: number;
1250
+ }>;
1251
+ readonly source: DocxSelectionSourceLocator;
1252
+ readonly text?: string;
1253
+ readonly mimeType?: string;
1254
+ readonly seriesCount?: number;
1255
+ readonly truncated: boolean;
1256
+ readonly truncationReasons: readonly ('text')[];
1257
+ readonly textCharacters: number;
1258
+ readonly maxTextCharacters: number;
1259
+ }
1260
+ type DocxSelectionContext = DocxTextSelectionContext | DocxElementContext;
1261
+ declare function readDocxTextSelectionContext(root: HTMLElement, selection: Selection | null, options?: DocxSelectionContextOptions): DocxTextSelectionContext | null;
1262
+ interface DocxElementContextOptions {
1263
+ readonly maxTextCharacters?: number;
1264
+ readonly currentDate?: Date | number;
1265
+ }
1203
1266
  interface LoadOptions extends LoadOptions$1 {
1204
1267
  math?: MathRenderer;
1205
1268
  mode?: 'main' | 'worker';
1206
1269
  }
1207
- type RenderPageToBitmapOptions = WireRenderPageOptions & {
1270
+ type CollectPageRunsOptions = Pick<RenderPageOptions, 'width' | 'currentDate'>;
1271
+ type RenderPageToBitmapOptions = Omit<RenderPageOptions, 'onTextRun'> & {
1208
1272
  onTextRun?: (run: DocxTextRunInfo) => void;
1209
1273
  };
1210
1274
  declare class DocxDocument {
@@ -1245,14 +1309,18 @@ declare class DocxDocument {
1245
1309
  };
1246
1310
  renderPage(target: HTMLCanvasElement | OffscreenCanvas, pageIndex: number, opts?: RenderPageOptions): Promise<void>;
1247
1311
  renderPageToBitmap(pageIndex: number, opts?: RenderPageToBitmapOptions): Promise<ImageBitmap>;
1248
- collectPageRuns(pageIndex: number, opts?: WireRenderPageOptions): Promise<DocxTextRunInfo[]>;
1312
+ collectPageRuns(pageIndex: number, opts?: CollectPageRunsOptions): Promise<DocxTextRunInfo[]>;
1313
+ getElementContextAt(pageIndex: number, point: DocxPagePoint, opts?: DocxElementContextOptions): Promise<DocxElementContext | null>;
1249
1314
  }
1250
1315
  interface DocxMatchLocation {
1251
1316
  page: number;
1252
1317
  }
1253
- interface DocxViewerOptions extends RenderPageOptions, LoadOptions {
1318
+ interface DocxViewerOptions extends Omit<RenderPageOptions, 'onTextRun'>, LoadOptions {
1254
1319
  container?: HTMLElement;
1255
1320
  enableTextSelection?: boolean;
1321
+ enableElementSelection?: boolean;
1322
+ onSelectionContextChange?: (context: DocxSelectionContext | null) => void;
1323
+ onContextMenu?: (event: ViewerContextMenuEvent<DocxSelectionContext>) => void;
1256
1324
  findHighlightColors?: FindHighlightColors;
1257
1325
  onPageChange?: (index: number, total: number) => void;
1258
1326
  zoomMin?: number;
@@ -1274,6 +1342,7 @@ declare class DocxViewer implements ZoomableViewer {
1274
1342
  private readonly _canvasMount;
1275
1343
  private _textLayer;
1276
1344
  private _highlightLayer;
1345
+ private _elementLayer;
1277
1346
  private _find;
1278
1347
  private _measureCtx;
1279
1348
  private _opts;
@@ -1281,6 +1350,12 @@ declare class DocxViewer implements ZoomableViewer {
1281
1350
  private readonly _renderDispatcher;
1282
1351
  private readonly _errorRouter;
1283
1352
  private _destroyed;
1353
+ private _selectionChangeListener;
1354
+ private _selectionContextKey;
1355
+ private _elementContext;
1356
+ private _elementHitGeneration;
1357
+ private _elementClickListener;
1358
+ private _contextMenuListener;
1284
1359
  static fromDocument(canvas: HTMLCanvasElement, document: DocxDocument, opts?: Omit<DocxViewerOptions, keyof LoadOptions>): Omit<DocxViewer, 'load'>;
1285
1360
  constructor(canvas: HTMLCanvasElement, opts?: DocxViewerOptions);
1286
1361
  load(source: string | ArrayBuffer): Promise<void>;
@@ -1309,6 +1384,14 @@ declare class DocxViewer implements ZoomableViewer {
1309
1384
  private _activateMatch;
1310
1385
  private _redrawHighlights;
1311
1386
  getResourceMetrics(): Promise<OoxmlResourceMetrics>;
1387
+ getSelectionContext(options?: DocxSelectionContextOptions): DocxSelectionContext | null;
1388
+ private _emitSelectionContextChange;
1389
+ private _setElementContext;
1390
+ private _invalidateElementContext;
1391
+ private _redrawElementOutline;
1392
+ private _onElementClick;
1393
+ private _onContextMenu;
1394
+ private _resolveContextAt;
1312
1395
  destroy(): void;
1313
1396
  private _render;
1314
1397
  private _reportRenderError;
@@ -1329,6 +1412,9 @@ interface DocxScrollViewerOptions extends Omit<RenderPageOptions, 'onTextRun'>,
1329
1412
  paddingRight?: number;
1330
1413
  overscan?: number;
1331
1414
  enableTextSelection?: boolean;
1415
+ enableElementSelection?: boolean;
1416
+ onSelectionContextChange?: (context: DocxSelectionContext | null) => void;
1417
+ onContextMenu?: (event: ViewerContextMenuEvent<DocxSelectionContext>) => void;
1332
1418
  findHighlightColors?: FindHighlightColors;
1333
1419
  zoomMin?: number;
1334
1420
  zoomMax?: number;
@@ -1361,6 +1447,12 @@ declare class DocxScrollViewer implements ZoomableViewer {
1361
1447
  private _lastRange;
1362
1448
  private _lastTopIndex;
1363
1449
  private _scrollListener;
1450
+ private _selectionChangeListener;
1451
+ private _selectionContextKey;
1452
+ private _elementClickListener;
1453
+ private _contextMenuListener;
1454
+ private _elementContext;
1455
+ private _elementHitGeneration;
1364
1456
  private _destroyed;
1365
1457
  private _measureCtx;
1366
1458
  private readonly _bitmapInFlight;
@@ -1383,6 +1475,7 @@ declare class DocxScrollViewer implements ZoomableViewer {
1383
1475
  private _fitWidthPx;
1384
1476
  private _baseScale;
1385
1477
  relayout(): void;
1478
+ private _relayout;
1386
1479
  private _recomputeHeights;
1387
1480
  private _gap;
1388
1481
  private _overscan;
@@ -1432,9 +1525,18 @@ declare class DocxScrollViewer implements ZoomableViewer {
1432
1525
  private _onResize;
1433
1526
  get topVisiblePage(): number;
1434
1527
  getResourceMetrics(): Promise<OoxmlResourceMetrics>;
1528
+ getSelectionContext(options?: DocxSelectionContextOptions): DocxSelectionContext | null;
1529
+ private _emitSelectionContextChange;
1530
+ private _setElementContext;
1531
+ private _invalidateElementContext;
1532
+ private _redrawElementOutlines;
1533
+ private _redrawElementOutlineForSlot;
1534
+ private _onElementClick;
1535
+ private _onContextMenu;
1536
+ private _resolveContextAt;
1435
1537
  destroy(): void;
1436
1538
  }
1437
- declare function buildDocxTextLayer(layer: HTMLDivElement, runs: DocxTextRunInfo[], cssWidth: number, cssHeight: number, onHyperlinkClick?: (target: HyperlinkTarget) => void, measureForFont?: (font: string) => (s: string) => number): void;
1539
+ declare function buildDocxTextLayer(layer: HTMLDivElement, runs: DocxTextRunInfo[], cssWidth: number, cssHeight: number, onHyperlinkClick?: (target: HyperlinkTarget) => void, measureForFont?: (font: string) => (s: string) => number, pageIndex?: number): void;
1438
1540
  interface DocxHighlightMatch {
1439
1541
  slices: MatchRunSlice[];
1440
1542
  active: boolean;
@@ -1442,4 +1544,4 @@ interface DocxHighlightMatch {
1442
1544
  type DocxHighlightColors = FindHighlightColors;
1443
1545
  declare function buildDocxHighlightLayer(layer: HTMLDivElement, runs: DocxTextRunInfo[], matches: DocxHighlightMatch[], cssWidth: number, cssHeight: number, measureForFont: (font: string) => (s: string) => number, colors?: DocxHighlightColors): void;
1444
1546
  //#endregion
1445
- 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 };
1547
+ export { type AnchorHostMetrics, type AutoResizeOptions, type BodyElement, type BorderSpec, type CellBorders, type CellElement, type ChartDataLabelOverride, type ChartDataPointOverride, type ChartErrBars, type ChartLabelBox, type ChartManualLayout, type ChartModel, type ChartRect, type ChartRun, type ChartSeries, type ChartSeriesDataLabels, type ChartTrendline, type ChartType, type ChartexBoxSeries, type ChartexBoxWhisker, type ChartexSunburst, type ChartexSunburstRow, type ColSpec, type CollectPageRunsOptions, type ColumnsSpec, type DocComment, type DocNote, type DocParagraph, type DocRevision, type DocRun, type DocSettings, type DocTable, type DocTableCell, type DocTableRow, DocxDocument, type DocxDocumentModel, type DocxElementContext, type DocxElementContextOptions, type DocxHighlightColors, type DocxHighlightMatch, type DocxMatchLocation, type DocxPagePoint, type DocxRunBorder, DocxScrollViewer, type DocxScrollViewerOptions, type DocxSelectionContext, type DocxSelectionContextOptions, type DocxSelectionRunLocator, type DocxSelectionSourceLocator, type DocxTextRun, type DocxTextRunInfo, type DocxTextSelectionContext, DocxViewer, type DocxViewerOptions, type Duotone, type EmbeddedFontRef, type FieldRun, type FillRect, type FindHighlightColors, type FindMatch, type FindMatchesOptions, type FramePr, type GradientStop, type HeaderFooter, type HeadersFooters, type HyperlinkTarget, type ImageRun, type LegendManualLayout, type LineEnd, type LineNumbering, type LineSpacing, type LoadOptions, type MatchRunSlice, type MathAccent, type MathArray, type MathBar, type MathBorderBox, type MathBox, type MathDelimiter, type MathFraction, type MathFunc, type MathGroup, type MathGroupChr, type MathLimit, type MathNary, type MathNode, type MathPhant, type MathRadical, type MathRenderer, type MathRun, type MathSPre, type MathScript, type MathStyle, type MathSvg, type NoteRef, type NumberingInfo, OoxmlDecodedImageLimitError, type OoxmlDecodedImageLimitMetric, OoxmlError, type OoxmlErrorCode, 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 SecondaryValueAxis, type SectionGeom, type SectionProps, type ShapeRun, type ShapeText, type ShapeTextRun, type TabStop, type TableBorders, type TblpPr, type TextPath, type TextSelectionContextOptions, type TileInfo, type ViewerContextMenuEvent, type ZoomableViewer, autoResize, buildDocxHighlightLayer, buildDocxTextLayer, isOoxmlDecodedImageLimitError, noteText, openExternalHyperlink, readDocxTextSelectionContext };