@silurus/ooxml 0.76.2 → 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-BOSu_OHa.d.ts
533
+ //#region dist/.types-work/docx-BkK3rbgp.d.ts
521
534
  interface DocxDocumentModel {
522
535
  section: SectionProps;
523
536
  body: BodyElement[];
@@ -874,7 +887,7 @@ interface ShapeRun {
874
887
  stroke: string | null;
875
888
  strokeWidth?: number;
876
889
  strokeDash?: string | null;
877
- strokeCap?: CanvasLineCap | null;
890
+ strokeCap?: 'butt' | 'round' | 'square' | null;
878
891
  headEnd?: LineEnd | null;
879
892
  tailEnd?: LineEnd | null;
880
893
  rotation?: number;
@@ -1169,24 +1182,12 @@ interface CellBorders {
1169
1182
  insideH: BorderSpec | null;
1170
1183
  insideV: BorderSpec | null;
1171
1184
  }
1172
- interface RenderPageOptions {
1173
- width?: number;
1174
- dpr?: number;
1175
- defaultTextColor?: string;
1176
- onTextRun?: (run: {
1177
- text: string;
1178
- x: number;
1179
- y: number;
1180
- w: number;
1181
- h: number;
1182
- fontSize: number;
1183
- font: string;
1184
- transform?: string;
1185
- }) => void;
1186
- showTrackChanges?: boolean;
1187
- currentDate?: Date | number;
1188
- }
1189
1185
  interface DocxTextRunInfo {
1186
+ source?: Readonly<{
1187
+ story: 'body' | 'header' | 'footer' | 'footnote' | 'endnote' | 'textbox';
1188
+ storyInstance: string;
1189
+ path: readonly number[];
1190
+ }>;
1190
1191
  paragraphId?: string;
1191
1192
  text: string;
1192
1193
  x: number;
@@ -1200,12 +1201,74 @@ interface DocxTextRunInfo {
1200
1201
  hyperlink?: HyperlinkTarget;
1201
1202
  eastAsianVert?: boolean;
1202
1203
  }
1203
- 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
+ }
1204
1266
  interface LoadOptions extends LoadOptions$1 {
1205
1267
  math?: MathRenderer;
1206
1268
  mode?: 'main' | 'worker';
1207
1269
  }
1208
- type RenderPageToBitmapOptions = WireRenderPageOptions & {
1270
+ type CollectPageRunsOptions = Pick<RenderPageOptions, 'width' | 'currentDate'>;
1271
+ type RenderPageToBitmapOptions = Omit<RenderPageOptions, 'onTextRun'> & {
1209
1272
  onTextRun?: (run: DocxTextRunInfo) => void;
1210
1273
  };
1211
1274
  declare class DocxDocument {
@@ -1246,14 +1309,18 @@ declare class DocxDocument {
1246
1309
  };
1247
1310
  renderPage(target: HTMLCanvasElement | OffscreenCanvas, pageIndex: number, opts?: RenderPageOptions): Promise<void>;
1248
1311
  renderPageToBitmap(pageIndex: number, opts?: RenderPageToBitmapOptions): Promise<ImageBitmap>;
1249
- 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>;
1250
1314
  }
1251
1315
  interface DocxMatchLocation {
1252
1316
  page: number;
1253
1317
  }
1254
- interface DocxViewerOptions extends RenderPageOptions, LoadOptions {
1318
+ interface DocxViewerOptions extends Omit<RenderPageOptions, 'onTextRun'>, LoadOptions {
1255
1319
  container?: HTMLElement;
1256
1320
  enableTextSelection?: boolean;
1321
+ enableElementSelection?: boolean;
1322
+ onSelectionContextChange?: (context: DocxSelectionContext | null) => void;
1323
+ onContextMenu?: (event: ViewerContextMenuEvent<DocxSelectionContext>) => void;
1257
1324
  findHighlightColors?: FindHighlightColors;
1258
1325
  onPageChange?: (index: number, total: number) => void;
1259
1326
  zoomMin?: number;
@@ -1275,6 +1342,7 @@ declare class DocxViewer implements ZoomableViewer {
1275
1342
  private readonly _canvasMount;
1276
1343
  private _textLayer;
1277
1344
  private _highlightLayer;
1345
+ private _elementLayer;
1278
1346
  private _find;
1279
1347
  private _measureCtx;
1280
1348
  private _opts;
@@ -1282,6 +1350,12 @@ declare class DocxViewer implements ZoomableViewer {
1282
1350
  private readonly _renderDispatcher;
1283
1351
  private readonly _errorRouter;
1284
1352
  private _destroyed;
1353
+ private _selectionChangeListener;
1354
+ private _selectionContextKey;
1355
+ private _elementContext;
1356
+ private _elementHitGeneration;
1357
+ private _elementClickListener;
1358
+ private _contextMenuListener;
1285
1359
  static fromDocument(canvas: HTMLCanvasElement, document: DocxDocument, opts?: Omit<DocxViewerOptions, keyof LoadOptions>): Omit<DocxViewer, 'load'>;
1286
1360
  constructor(canvas: HTMLCanvasElement, opts?: DocxViewerOptions);
1287
1361
  load(source: string | ArrayBuffer): Promise<void>;
@@ -1310,6 +1384,14 @@ declare class DocxViewer implements ZoomableViewer {
1310
1384
  private _activateMatch;
1311
1385
  private _redrawHighlights;
1312
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;
1313
1395
  destroy(): void;
1314
1396
  private _render;
1315
1397
  private _reportRenderError;
@@ -1330,6 +1412,9 @@ interface DocxScrollViewerOptions extends Omit<RenderPageOptions, 'onTextRun'>,
1330
1412
  paddingRight?: number;
1331
1413
  overscan?: number;
1332
1414
  enableTextSelection?: boolean;
1415
+ enableElementSelection?: boolean;
1416
+ onSelectionContextChange?: (context: DocxSelectionContext | null) => void;
1417
+ onContextMenu?: (event: ViewerContextMenuEvent<DocxSelectionContext>) => void;
1333
1418
  findHighlightColors?: FindHighlightColors;
1334
1419
  zoomMin?: number;
1335
1420
  zoomMax?: number;
@@ -1362,6 +1447,12 @@ declare class DocxScrollViewer implements ZoomableViewer {
1362
1447
  private _lastRange;
1363
1448
  private _lastTopIndex;
1364
1449
  private _scrollListener;
1450
+ private _selectionChangeListener;
1451
+ private _selectionContextKey;
1452
+ private _elementClickListener;
1453
+ private _contextMenuListener;
1454
+ private _elementContext;
1455
+ private _elementHitGeneration;
1365
1456
  private _destroyed;
1366
1457
  private _measureCtx;
1367
1458
  private readonly _bitmapInFlight;
@@ -1384,6 +1475,7 @@ declare class DocxScrollViewer implements ZoomableViewer {
1384
1475
  private _fitWidthPx;
1385
1476
  private _baseScale;
1386
1477
  relayout(): void;
1478
+ private _relayout;
1387
1479
  private _recomputeHeights;
1388
1480
  private _gap;
1389
1481
  private _overscan;
@@ -1433,9 +1525,18 @@ declare class DocxScrollViewer implements ZoomableViewer {
1433
1525
  private _onResize;
1434
1526
  get topVisiblePage(): number;
1435
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;
1436
1537
  destroy(): void;
1437
1538
  }
1438
- 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;
1439
1540
  interface DocxHighlightMatch {
1440
1541
  slices: MatchRunSlice[];
1441
1542
  active: boolean;
@@ -1443,4 +1544,4 @@ interface DocxHighlightMatch {
1443
1544
  type DocxHighlightColors = FindHighlightColors;
1444
1545
  declare function buildDocxHighlightLayer(layer: HTMLDivElement, runs: DocxTextRunInfo[], matches: DocxHighlightMatch[], cssWidth: number, cssHeight: number, measureForFont: (font: string) => (s: string) => number, colors?: DocxHighlightColors): void;
1445
1546
  //#endregion
1446
- 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 };