@extend-ai/react-xlsx 0.16.3 → 0.16.4

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.cts CHANGED
@@ -878,6 +878,11 @@ interface XlsxImageRect {
878
878
  top: number;
879
879
  width: number;
880
880
  }
881
+ /** Rendered column widths and row heights in logical pixels, indexed by worksheet coordinates. */
882
+ interface XlsxDrawingLayout {
883
+ columnWidths: readonly number[];
884
+ rowHeights: readonly number[];
885
+ }
881
886
  type XlsxImageResizeHandlePosition = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw";
882
887
  interface XlsxImageRenderProps {
883
888
  /** The built-in image element that react-xlsx would render without customization. */
@@ -1175,8 +1180,8 @@ interface XlsxViewerController {
1175
1180
  sortTable: (tableName: string, columnIndex: number, direction: XlsxTableSortDirection) => void;
1176
1181
  setChartSeriesFormula: (chartId: string, seriesIndex: number, formula: string) => boolean;
1177
1182
  selectImage: (id: string | null) => void;
1178
- setChartRect: (id: string, rect: XlsxImageRect) => void;
1179
- setImageRect: (id: string, rect: XlsxImageRect) => void;
1183
+ setChartRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1184
+ setImageRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1180
1185
  getRowsBatchAsync?: (workbookSheetIndex: number, startRow: number, rowCount: number) => Promise<unknown[] | null>;
1181
1186
  tables: XlsxTable[];
1182
1187
  tabs: XlsxWorkbookTab[];
@@ -1319,8 +1324,8 @@ interface XlsxViewerImages {
1319
1324
  selectChartElement: (selection: XlsxChartElementSelection | null) => void;
1320
1325
  selectImage: (id: string | null) => void;
1321
1326
  setChartSeriesFormula: (chartId: string, seriesIndex: number, formula: string) => boolean;
1322
- setChartRect: (id: string, rect: XlsxImageRect) => void;
1323
- setImageRect: (id: string, rect: XlsxImageRect) => void;
1327
+ setChartRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1328
+ setImageRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1324
1329
  updateChart: (id: string, patch: Partial<XlsxChart>) => void;
1325
1330
  }
1326
1331
  interface XlsxViewerCharts {
@@ -1346,7 +1351,7 @@ interface XlsxViewerCharts {
1346
1351
  selectChartElement: (selection: XlsxChartElementSelection | null) => void;
1347
1352
  setChartSeriesFormula: (chartId: string, seriesIndex: number, formula: string) => boolean;
1348
1353
  setActiveTabIndex: (index: number) => void;
1349
- setChartRect: (id: string, rect: XlsxImageRect) => void;
1354
+ setChartRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1350
1355
  tabs: XlsxWorkbookTab[];
1351
1356
  updateChart: (id: string, patch: Partial<XlsxChart>) => void;
1352
1357
  }
@@ -1653,4 +1658,4 @@ declare function useXlsxViewerThumbnails(options?: UseXlsxViewerThumbnailsOption
1653
1658
  declare function XlsxViewer(props: XlsxViewerProps): react_jsx_runtime.JSX.Element;
1654
1659
  declare function DefaultXlsxToolbar(): react_jsx_runtime.JSX.Element;
1655
1660
 
1656
- export { DefaultXlsxToolbar, type UseXlsxViewerControllerOptions, type UseXlsxViewerThumbnailsOptions, type XlsxCellAddress, type XlsxCellAlignmentInput, type XlsxCellBorderEdgeInput, type XlsxCellBorderStyleInput, type XlsxCellFillStyleInput, type XlsxCellFontStyleInput, type XlsxCellGradientStopInput, type XlsxCellNumberFormatInput, type XlsxCellProtectionInput, type XlsxCellRange, type XlsxCellStyleColorInput, type XlsxCellStyleContext, type XlsxCellStyleInput, type XlsxChart, type XlsxChartAxis, type XlsxChartDataLabels, type XlsxChartElementSelection, type XlsxChartLoadingRenderProps, type XlsxChartReference, type XlsxChartSeries, type XlsxChartsheet, XlsxFileSizeLimitExceededError, type XlsxFileTooLargeRenderProps, type XlsxFormControl, type XlsxFormControlActionEvent, type XlsxFormControlCaption, type XlsxFormControlCaptionInput, type XlsxFormControlCaptionRun, type XlsxFormControlChangeEvent, type XlsxFormControlInput, type XlsxFormControlKind, type XlsxFormControlKindInput, type XlsxFormControlPatch, type XlsxFormControlRenderProps, type XlsxFormControlSelectionMode, type XlsxFormControlState, type XlsxFormulaTarget, type XlsxImage, type XlsxImageAnchor, type XlsxImageRect, type XlsxImageRenderProps, type XlsxImageResizeHandlePosition, type XlsxImageSelectionRenderProps, type XlsxScrollerRenderProps, type XlsxShape, type XlsxShapeFill, type XlsxShapeParagraph, type XlsxShapeStroke, type XlsxShapeTextBox, type XlsxShapeTextRun, type XlsxSheetData, type XlsxSheetThumbnail, type XlsxSheetThumbnailResolution, type XlsxSheetVisibility, type XlsxTable, type XlsxTableColumn, type XlsxTableHeaderMenuRenderProps, type XlsxTableSortDirection, type XlsxTableSortState, type XlsxThemePalette, XlsxViewer, type XlsxViewerCharts, type XlsxViewerController, type XlsxViewerEditing, type XlsxViewerImages, type XlsxViewerProps, XlsxViewerProvider, type XlsxViewerProviderProps, type XlsxViewerSelection, type XlsxViewerTables, type XlsxViewerThumbnails, type XlsxViewerZoom, type XlsxWasmSource, type XlsxWorkbookTab, initWasm, setWasmSource, useXlsxViewer, useXlsxViewerCharts, useXlsxViewerController, useXlsxViewerEditing, useXlsxViewerImages, useXlsxViewerSelection, useXlsxViewerTables, useXlsxViewerThumbnails, useXlsxViewerZoom };
1661
+ export { DefaultXlsxToolbar, type UseXlsxViewerControllerOptions, type UseXlsxViewerThumbnailsOptions, type XlsxCellAddress, type XlsxCellAlignmentInput, type XlsxCellBorderEdgeInput, type XlsxCellBorderStyleInput, type XlsxCellFillStyleInput, type XlsxCellFontStyleInput, type XlsxCellGradientStopInput, type XlsxCellNumberFormatInput, type XlsxCellProtectionInput, type XlsxCellRange, type XlsxCellStyleColorInput, type XlsxCellStyleContext, type XlsxCellStyleInput, type XlsxChart, type XlsxChartAxis, type XlsxChartDataLabels, type XlsxChartElementSelection, type XlsxChartLoadingRenderProps, type XlsxChartReference, type XlsxChartSeries, type XlsxChartsheet, type XlsxDrawingLayout, XlsxFileSizeLimitExceededError, type XlsxFileTooLargeRenderProps, type XlsxFormControl, type XlsxFormControlActionEvent, type XlsxFormControlCaption, type XlsxFormControlCaptionInput, type XlsxFormControlCaptionRun, type XlsxFormControlChangeEvent, type XlsxFormControlInput, type XlsxFormControlKind, type XlsxFormControlKindInput, type XlsxFormControlPatch, type XlsxFormControlRenderProps, type XlsxFormControlSelectionMode, type XlsxFormControlState, type XlsxFormulaTarget, type XlsxImage, type XlsxImageAnchor, type XlsxImageRect, type XlsxImageRenderProps, type XlsxImageResizeHandlePosition, type XlsxImageSelectionRenderProps, type XlsxScrollerRenderProps, type XlsxShape, type XlsxShapeFill, type XlsxShapeParagraph, type XlsxShapeStroke, type XlsxShapeTextBox, type XlsxShapeTextRun, type XlsxSheetData, type XlsxSheetThumbnail, type XlsxSheetThumbnailResolution, type XlsxSheetVisibility, type XlsxTable, type XlsxTableColumn, type XlsxTableHeaderMenuRenderProps, type XlsxTableSortDirection, type XlsxTableSortState, type XlsxThemePalette, XlsxViewer, type XlsxViewerCharts, type XlsxViewerController, type XlsxViewerEditing, type XlsxViewerImages, type XlsxViewerProps, XlsxViewerProvider, type XlsxViewerProviderProps, type XlsxViewerSelection, type XlsxViewerTables, type XlsxViewerThumbnails, type XlsxViewerZoom, type XlsxWasmSource, type XlsxWorkbookTab, initWasm, setWasmSource, useXlsxViewer, useXlsxViewerCharts, useXlsxViewerController, useXlsxViewerEditing, useXlsxViewerImages, useXlsxViewerSelection, useXlsxViewerTables, useXlsxViewerThumbnails, useXlsxViewerZoom };
package/dist/index.d.ts CHANGED
@@ -878,6 +878,11 @@ interface XlsxImageRect {
878
878
  top: number;
879
879
  width: number;
880
880
  }
881
+ /** Rendered column widths and row heights in logical pixels, indexed by worksheet coordinates. */
882
+ interface XlsxDrawingLayout {
883
+ columnWidths: readonly number[];
884
+ rowHeights: readonly number[];
885
+ }
881
886
  type XlsxImageResizeHandlePosition = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw";
882
887
  interface XlsxImageRenderProps {
883
888
  /** The built-in image element that react-xlsx would render without customization. */
@@ -1175,8 +1180,8 @@ interface XlsxViewerController {
1175
1180
  sortTable: (tableName: string, columnIndex: number, direction: XlsxTableSortDirection) => void;
1176
1181
  setChartSeriesFormula: (chartId: string, seriesIndex: number, formula: string) => boolean;
1177
1182
  selectImage: (id: string | null) => void;
1178
- setChartRect: (id: string, rect: XlsxImageRect) => void;
1179
- setImageRect: (id: string, rect: XlsxImageRect) => void;
1183
+ setChartRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1184
+ setImageRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1180
1185
  getRowsBatchAsync?: (workbookSheetIndex: number, startRow: number, rowCount: number) => Promise<unknown[] | null>;
1181
1186
  tables: XlsxTable[];
1182
1187
  tabs: XlsxWorkbookTab[];
@@ -1319,8 +1324,8 @@ interface XlsxViewerImages {
1319
1324
  selectChartElement: (selection: XlsxChartElementSelection | null) => void;
1320
1325
  selectImage: (id: string | null) => void;
1321
1326
  setChartSeriesFormula: (chartId: string, seriesIndex: number, formula: string) => boolean;
1322
- setChartRect: (id: string, rect: XlsxImageRect) => void;
1323
- setImageRect: (id: string, rect: XlsxImageRect) => void;
1327
+ setChartRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1328
+ setImageRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1324
1329
  updateChart: (id: string, patch: Partial<XlsxChart>) => void;
1325
1330
  }
1326
1331
  interface XlsxViewerCharts {
@@ -1346,7 +1351,7 @@ interface XlsxViewerCharts {
1346
1351
  selectChartElement: (selection: XlsxChartElementSelection | null) => void;
1347
1352
  setChartSeriesFormula: (chartId: string, seriesIndex: number, formula: string) => boolean;
1348
1353
  setActiveTabIndex: (index: number) => void;
1349
- setChartRect: (id: string, rect: XlsxImageRect) => void;
1354
+ setChartRect: (id: string, rect: XlsxImageRect, layout?: XlsxDrawingLayout) => void;
1350
1355
  tabs: XlsxWorkbookTab[];
1351
1356
  updateChart: (id: string, patch: Partial<XlsxChart>) => void;
1352
1357
  }
@@ -1653,4 +1658,4 @@ declare function useXlsxViewerThumbnails(options?: UseXlsxViewerThumbnailsOption
1653
1658
  declare function XlsxViewer(props: XlsxViewerProps): react_jsx_runtime.JSX.Element;
1654
1659
  declare function DefaultXlsxToolbar(): react_jsx_runtime.JSX.Element;
1655
1660
 
1656
- export { DefaultXlsxToolbar, type UseXlsxViewerControllerOptions, type UseXlsxViewerThumbnailsOptions, type XlsxCellAddress, type XlsxCellAlignmentInput, type XlsxCellBorderEdgeInput, type XlsxCellBorderStyleInput, type XlsxCellFillStyleInput, type XlsxCellFontStyleInput, type XlsxCellGradientStopInput, type XlsxCellNumberFormatInput, type XlsxCellProtectionInput, type XlsxCellRange, type XlsxCellStyleColorInput, type XlsxCellStyleContext, type XlsxCellStyleInput, type XlsxChart, type XlsxChartAxis, type XlsxChartDataLabels, type XlsxChartElementSelection, type XlsxChartLoadingRenderProps, type XlsxChartReference, type XlsxChartSeries, type XlsxChartsheet, XlsxFileSizeLimitExceededError, type XlsxFileTooLargeRenderProps, type XlsxFormControl, type XlsxFormControlActionEvent, type XlsxFormControlCaption, type XlsxFormControlCaptionInput, type XlsxFormControlCaptionRun, type XlsxFormControlChangeEvent, type XlsxFormControlInput, type XlsxFormControlKind, type XlsxFormControlKindInput, type XlsxFormControlPatch, type XlsxFormControlRenderProps, type XlsxFormControlSelectionMode, type XlsxFormControlState, type XlsxFormulaTarget, type XlsxImage, type XlsxImageAnchor, type XlsxImageRect, type XlsxImageRenderProps, type XlsxImageResizeHandlePosition, type XlsxImageSelectionRenderProps, type XlsxScrollerRenderProps, type XlsxShape, type XlsxShapeFill, type XlsxShapeParagraph, type XlsxShapeStroke, type XlsxShapeTextBox, type XlsxShapeTextRun, type XlsxSheetData, type XlsxSheetThumbnail, type XlsxSheetThumbnailResolution, type XlsxSheetVisibility, type XlsxTable, type XlsxTableColumn, type XlsxTableHeaderMenuRenderProps, type XlsxTableSortDirection, type XlsxTableSortState, type XlsxThemePalette, XlsxViewer, type XlsxViewerCharts, type XlsxViewerController, type XlsxViewerEditing, type XlsxViewerImages, type XlsxViewerProps, XlsxViewerProvider, type XlsxViewerProviderProps, type XlsxViewerSelection, type XlsxViewerTables, type XlsxViewerThumbnails, type XlsxViewerZoom, type XlsxWasmSource, type XlsxWorkbookTab, initWasm, setWasmSource, useXlsxViewer, useXlsxViewerCharts, useXlsxViewerController, useXlsxViewerEditing, useXlsxViewerImages, useXlsxViewerSelection, useXlsxViewerTables, useXlsxViewerThumbnails, useXlsxViewerZoom };
1661
+ export { DefaultXlsxToolbar, type UseXlsxViewerControllerOptions, type UseXlsxViewerThumbnailsOptions, type XlsxCellAddress, type XlsxCellAlignmentInput, type XlsxCellBorderEdgeInput, type XlsxCellBorderStyleInput, type XlsxCellFillStyleInput, type XlsxCellFontStyleInput, type XlsxCellGradientStopInput, type XlsxCellNumberFormatInput, type XlsxCellProtectionInput, type XlsxCellRange, type XlsxCellStyleColorInput, type XlsxCellStyleContext, type XlsxCellStyleInput, type XlsxChart, type XlsxChartAxis, type XlsxChartDataLabels, type XlsxChartElementSelection, type XlsxChartLoadingRenderProps, type XlsxChartReference, type XlsxChartSeries, type XlsxChartsheet, type XlsxDrawingLayout, XlsxFileSizeLimitExceededError, type XlsxFileTooLargeRenderProps, type XlsxFormControl, type XlsxFormControlActionEvent, type XlsxFormControlCaption, type XlsxFormControlCaptionInput, type XlsxFormControlCaptionRun, type XlsxFormControlChangeEvent, type XlsxFormControlInput, type XlsxFormControlKind, type XlsxFormControlKindInput, type XlsxFormControlPatch, type XlsxFormControlRenderProps, type XlsxFormControlSelectionMode, type XlsxFormControlState, type XlsxFormulaTarget, type XlsxImage, type XlsxImageAnchor, type XlsxImageRect, type XlsxImageRenderProps, type XlsxImageResizeHandlePosition, type XlsxImageSelectionRenderProps, type XlsxScrollerRenderProps, type XlsxShape, type XlsxShapeFill, type XlsxShapeParagraph, type XlsxShapeStroke, type XlsxShapeTextBox, type XlsxShapeTextRun, type XlsxSheetData, type XlsxSheetThumbnail, type XlsxSheetThumbnailResolution, type XlsxSheetVisibility, type XlsxTable, type XlsxTableColumn, type XlsxTableHeaderMenuRenderProps, type XlsxTableSortDirection, type XlsxTableSortState, type XlsxThemePalette, XlsxViewer, type XlsxViewerCharts, type XlsxViewerController, type XlsxViewerEditing, type XlsxViewerImages, type XlsxViewerProps, XlsxViewerProvider, type XlsxViewerProviderProps, type XlsxViewerSelection, type XlsxViewerTables, type XlsxViewerThumbnails, type XlsxViewerZoom, type XlsxWasmSource, type XlsxWorkbookTab, initWasm, setWasmSource, useXlsxViewer, useXlsxViewerCharts, useXlsxViewerController, useXlsxViewerEditing, useXlsxViewerImages, useXlsxViewerSelection, useXlsxViewerTables, useXlsxViewerThumbnails, useXlsxViewerZoom };
package/dist/index.js CHANGED
@@ -3064,6 +3064,17 @@ function applyChartOrigins(chartsByWorkbookSheetIndex, chartOriginsById, archive
3064
3064
  });
3065
3065
  }
3066
3066
  }
3067
+ function hydrateWorkbookChartStyles(chartsByWorkbookSheetIndex, imageAssets) {
3068
+ const chartOriginsById = /* @__PURE__ */ new Map();
3069
+ applyChartOrigins(chartsByWorkbookSheetIndex, chartOriginsById, imageAssets.archive, imageAssets.sheetOrigins);
3070
+ for (const charts of chartsByWorkbookSheetIndex) {
3071
+ for (const chart of charts) {
3072
+ applyChartStyleFromXml(chart, chart.chartPath, imageAssets.archive, imageAssets.themePalette);
3073
+ applyBuiltinChartDefaults(chart, imageAssets.themePalette);
3074
+ }
3075
+ }
3076
+ return chartOriginsById;
3077
+ }
3067
3078
  function loadWorkbookChartAssets(workbook, imageAssets, visibleSheetIndexByWorkbookSheetIndex, showHiddenSheets = false) {
3068
3079
  const excludedChartIds = /* @__PURE__ */ new Set();
3069
3080
  const chartsByWorkbookSheetIndex = Array.from({ length: workbook.sheetCount }, (_, workbookSheetIndex) => {
@@ -3164,21 +3175,14 @@ function loadWorkbookChartAssets(workbook, imageAssets, visibleSheetIndexByWorkb
3164
3175
  });
3165
3176
  const chartsheets = Array.isArray(workbook.chartsheets) ? workbook.chartsheets.map((entry, index) => normalizeChartsheet(entry, index)) : [];
3166
3177
  const tabs = buildTabs(workbook, chartsheets, visibleSheetIndexByWorkbookSheetIndex, showHiddenSheets);
3167
- const chartOriginsById = /* @__PURE__ */ new Map();
3178
+ const chartOriginsById = imageAssets ? hydrateWorkbookChartStyles(chartsByWorkbookSheetIndex, imageAssets) : /* @__PURE__ */ new Map();
3168
3179
  if (imageAssets) {
3169
- applyChartOrigins(chartsByWorkbookSheetIndex, chartOriginsById, imageAssets.archive, imageAssets.sheetOrigins);
3170
3180
  for (let index = 0; index < chartsByWorkbookSheetIndex.length; index += 1) {
3171
3181
  chartsByWorkbookSheetIndex[index] = (chartsByWorkbookSheetIndex[index] ?? []).filter((chart) => !excludedChartIds.has(chart.id));
3172
3182
  }
3173
3183
  for (const id of excludedChartIds) {
3174
3184
  chartOriginsById.delete(id);
3175
3185
  }
3176
- for (const charts of chartsByWorkbookSheetIndex) {
3177
- for (const chart of charts) {
3178
- applyChartStyleFromXml(chart, chart.chartPath, imageAssets.archive, imageAssets.themePalette);
3179
- applyBuiltinChartDefaults(chart, imageAssets.themePalette);
3180
- }
3181
- }
3182
3186
  } else {
3183
3187
  for (let index = 0; index < chartsByWorkbookSheetIndex.length; index += 1) {
3184
3188
  chartsByWorkbookSheetIndex[index] = (chartsByWorkbookSheetIndex[index] ?? []).filter((chart) => !excludedChartIds.has(chart.id));
@@ -5892,11 +5896,11 @@ function parseShapeNode(shapeNode, fallbackAnchor, drawingRelationships, theme,
5892
5896
  zIndex
5893
5897
  };
5894
5898
  }
5895
- function parseAnchorContents(anchorNode, fallbackAnchor, drawingRelationships, archive, contentTypes, objectUrls, workbookSheetIndex, theme, ids, imageOriginsById, anchorIndex, sheetState, parentGroup = null) {
5899
+ function parseAnchorContents(anchorNode, fallbackAnchor, drawingRelationships, archive, contentTypes, objectUrls, workbookSheetIndex, theme, ids, imageOriginsById, anchorIndex, sheetState, drawingPath, parentGroup = null, picturePath = []) {
5896
5900
  const images = [];
5897
5901
  const shapes = [];
5898
5902
  const mediaPaths = /* @__PURE__ */ new Set();
5899
- Array.from(anchorNode.childNodes).filter(isElementNode2).forEach((child) => {
5903
+ Array.from(anchorNode.childNodes).filter(isElementNode2).forEach((child, childIndex) => {
5900
5904
  if (child.localName === "pic") {
5901
5905
  const imageId = `sheet-${workbookSheetIndex}-${ids.image}`;
5902
5906
  const parsed = parsePictureNode(
@@ -5917,6 +5921,8 @@ function parseAnchorContents(anchorNode, fallbackAnchor, drawingRelationships, a
5917
5921
  mediaPaths.add(parsed.mediaPath);
5918
5922
  imageOriginsById.set(imageId, {
5919
5923
  anchorIndex,
5924
+ drawingPath,
5925
+ picturePath: [...picturePath, childIndex],
5920
5926
  workbookSheetIndex
5921
5927
  });
5922
5928
  }
@@ -5976,7 +5982,9 @@ function parseAnchorContents(anchorNode, fallbackAnchor, drawingRelationships, a
5976
5982
  imageOriginsById,
5977
5983
  anchorIndex,
5978
5984
  sheetState,
5979
- nextGroup
5985
+ drawingPath,
5986
+ nextGroup,
5987
+ [...picturePath, childIndex]
5980
5988
  );
5981
5989
  parsedGroup.images.forEach((image) => images.push(image));
5982
5990
  parsedGroup.shapes.forEach((shape) => shapes.push(shape));
@@ -6032,7 +6040,8 @@ function parseDrawingObjects(archive, contentTypes, drawingPath, objectUrls, wor
6032
6040
  ids,
6033
6041
  imageOriginsById,
6034
6042
  anchorIndex,
6035
- sheetState
6043
+ sheetState,
6044
+ drawingPath
6036
6045
  );
6037
6046
  parsed.images.forEach((image) => images.push(image));
6038
6047
  parsed.shapes.forEach((shape) => shapes.push(shape));
@@ -6191,6 +6200,9 @@ function updateWorkbookImageAnchor(assets, imageId, anchor) {
6191
6200
  }
6192
6201
  const attachments = assets.sheetOrigins[origin.workbookSheetIndex]?.attachments ?? [];
6193
6202
  for (const attachment of attachments) {
6203
+ if (attachment.drawingPath !== origin.drawingPath) {
6204
+ continue;
6205
+ }
6194
6206
  const drawingXml = readArchiveText2(assets.archive, attachment.drawingPath);
6195
6207
  if (!drawingXml) {
6196
6208
  continue;
@@ -6201,10 +6213,45 @@ function updateWorkbookImageAnchor(assets, imageId, anchor) {
6201
6213
  }
6202
6214
  const anchorNodes = createImageAnchorNodes(drawingDocument);
6203
6215
  const anchorNode = anchorNodes[origin.anchorIndex];
6204
- if (!anchorNode || !getFirstChild(anchorNode, "pic")) {
6216
+ if (!anchorNode) {
6205
6217
  continue;
6206
6218
  }
6207
- updateAnchorNode2(anchorNode, anchor);
6219
+ let pictureNode = anchorNode;
6220
+ let parentGroup = null;
6221
+ let groupAnchor = parseAnchor(anchorNode);
6222
+ for (const childIndex of origin.picturePath) {
6223
+ const child = Array.from(pictureNode.childNodes).filter(isElementNode2)[childIndex];
6224
+ if (!child || !groupAnchor) {
6225
+ break;
6226
+ }
6227
+ pictureNode = child;
6228
+ if (child.localName === "grpSp") {
6229
+ parentGroup = parseGroupTransform(
6230
+ child,
6231
+ parentGroup,
6232
+ groupAnchor,
6233
+ assets.sheetStatesByWorkbookSheetIndex[origin.workbookSheetIndex] ?? null
6234
+ );
6235
+ groupAnchor = rectToAbsoluteAnchor(parentGroup);
6236
+ }
6237
+ }
6238
+ if (pictureNode.localName !== "pic") {
6239
+ continue;
6240
+ }
6241
+ if (parentGroup) {
6242
+ const transform = getFirstDescendant(pictureNode, "xfrm");
6243
+ const off = transform ? getFirstChild(transform, "off") : null;
6244
+ const ext = transform ? getFirstChild(transform, "ext") : null;
6245
+ if (anchor.kind !== "absolute" || !off || !ext || !parentGroup.scaleX || !parentGroup.scaleY) {
6246
+ continue;
6247
+ }
6248
+ off.setAttribute("x", String(Math.round(parentGroup.chX + (anchor.positionEmu.x - parentGroup.x) / parentGroup.scaleX)));
6249
+ off.setAttribute("y", String(Math.round(parentGroup.chY + (anchor.positionEmu.y - parentGroup.y) / parentGroup.scaleY)));
6250
+ ext.setAttribute("cx", String(Math.max(0, Math.round(anchor.sizeEmu.cx / parentGroup.scaleX))));
6251
+ ext.setAttribute("cy", String(Math.max(0, Math.round(anchor.sizeEmu.cy / parentGroup.scaleY))));
6252
+ } else {
6253
+ updateAnchorNode2(anchorNode, anchor);
6254
+ }
6208
6255
  assets.archive[attachment.drawingPath] = strToU82(serializeXml2(drawingDocument));
6209
6256
  assets.dirtyArchivePaths.add(normalizeArchivePath2(attachment.drawingPath));
6210
6257
  const imageList = assets.imagesByWorkbookSheetIndex[origin.workbookSheetIndex] ?? [];
@@ -6315,15 +6362,21 @@ function appendSheetDrawingReference(sheetDocument, relationshipId) {
6315
6362
  }
6316
6363
  const drawingNode = sheetDocument.createElementNS(SPREADSHEET_NS, "drawing");
6317
6364
  drawingNode.setAttributeNS(REL_NS, "r:id", relationshipId);
6318
- const extLst = getFirstChild(worksheet, "extLst");
6319
- if (extLst) {
6320
- worksheet.insertBefore(drawingNode, extLst);
6321
- return;
6322
- }
6323
- worksheet.appendChild(drawingNode);
6365
+ const successorNames = /* @__PURE__ */ new Set([
6366
+ "legacyDrawing",
6367
+ "legacyDrawingHF",
6368
+ "picture",
6369
+ "oleObjects",
6370
+ "controls",
6371
+ "webPublishItems",
6372
+ "tableParts",
6373
+ "extLst"
6374
+ ]);
6375
+ const successor = Array.from(worksheet.childNodes).find((node) => isElementNode2(node) && node.namespaceURI === SPREADSHEET_NS && successorNames.has(node.localName));
6376
+ worksheet.insertBefore(drawingNode, successor ?? null);
6324
6377
  }
6325
6378
  function mergeWorkbookImageAssets(savedBytes, sourceAssets, sheetOrigins) {
6326
- if (!sourceAssets || sourceAssets.dirtyArchivePaths.size === 0) {
6379
+ if (!sourceAssets) {
6327
6380
  return cloneBytes(savedBytes);
6328
6381
  }
6329
6382
  try {
@@ -6334,9 +6387,31 @@ function mergeWorkbookImageAssets(savedBytes, sourceAssets, sheetOrigins) {
6334
6387
  if (!targetContentTypesDocument) {
6335
6388
  return cloneBytes(savedBytes);
6336
6389
  }
6390
+ const copiedParts = /* @__PURE__ */ new Set();
6391
+ const copyDrawingPart = (path) => {
6392
+ const normalizedPath = normalizeArchivePath2(path);
6393
+ const bytes = sourceAssets.archive[normalizedPath];
6394
+ if (!bytes || copiedParts.has(normalizedPath)) {
6395
+ return;
6396
+ }
6397
+ copiedParts.add(normalizedPath);
6398
+ archive[normalizedPath] = cloneBytes(bytes);
6399
+ mergeContentTypeForPath(targetContentTypesDocument, originalContentTypesDocument, normalizedPath);
6400
+ const relsPath = relsPathForDocument(normalizedPath);
6401
+ const relsBytes = sourceAssets.archive[relsPath];
6402
+ if (!relsBytes) {
6403
+ return;
6404
+ }
6405
+ archive[relsPath] = cloneBytes(relsBytes);
6406
+ mergeContentTypeForPath(targetContentTypesDocument, originalContentTypesDocument, relsPath);
6407
+ for (const relationship of parseRelationships(sourceAssets.archive, relsPath, normalizedPath).values()) {
6408
+ if (relationship.targetMode !== "External" && !relationship.type.endsWith("/hyperlink")) {
6409
+ copyDrawingPart(relationship.target);
6410
+ }
6411
+ }
6412
+ };
6337
6413
  sheetOrigins.forEach((origin, workbookSheetIndex) => {
6338
- const hasDirtyAttachment = origin?.attachments.some((attachment) => sourceAssets.dirtyArchivePaths.has(normalizeArchivePath2(attachment.drawingPath)) || attachment.drawingRelsPath && sourceAssets.dirtyArchivePaths.has(normalizeArchivePath2(attachment.drawingRelsPath)) || attachment.mediaPaths.some((path) => sourceAssets.dirtyArchivePaths.has(normalizeArchivePath2(path))));
6339
- if (!origin?.attachments.length || !hasDirtyAttachment) {
6414
+ if (!origin?.attachments.length) {
6340
6415
  return;
6341
6416
  }
6342
6417
  const currentSheet = workbookSheets[workbookSheetIndex];
@@ -6359,23 +6434,7 @@ function mergeWorkbookImageAssets(savedBytes, sourceAssets, sheetOrigins) {
6359
6434
  if (!drawingBytes) {
6360
6435
  return;
6361
6436
  }
6362
- archive[attachment.drawingPath] = cloneBytes(drawingBytes);
6363
- mergeContentTypeForPath(targetContentTypesDocument, originalContentTypesDocument, attachment.drawingPath);
6364
- if (attachment.drawingRelsPath) {
6365
- const drawingRelsBytes = sourceAssets.archive[attachment.drawingRelsPath];
6366
- if (drawingRelsBytes) {
6367
- archive[attachment.drawingRelsPath] = cloneBytes(drawingRelsBytes);
6368
- mergeContentTypeForPath(targetContentTypesDocument, originalContentTypesDocument, attachment.drawingRelsPath);
6369
- }
6370
- }
6371
- attachment.mediaPaths.forEach((mediaPath) => {
6372
- const mediaBytes = sourceAssets.archive[mediaPath];
6373
- if (!mediaBytes) {
6374
- return;
6375
- }
6376
- archive[mediaPath] = cloneBytes(mediaBytes);
6377
- mergeContentTypeForPath(targetContentTypesDocument, originalContentTypesDocument, mediaPath);
6378
- });
6437
+ copyDrawingPart(attachment.drawingPath);
6379
6438
  const relationshipId = nextRelationshipId(relDocument);
6380
6439
  const relationshipNode = relDocument.createElementNS(PKG_REL_NS, "Relationship");
6381
6440
  relationshipNode.setAttribute("Id", relationshipId);
@@ -6437,7 +6496,7 @@ function markerFromOffset(offsetPx, getSizePx) {
6437
6496
  let remaining = Math.max(0, offsetPx);
6438
6497
  let index = 0;
6439
6498
  while (remaining > 0) {
6440
- const size = Math.max(1, getSizePx(index));
6499
+ const size = Math.max(0, getSizePx(index));
6441
6500
  if (remaining < size) {
6442
6501
  break;
6443
6502
  }
@@ -8473,6 +8532,10 @@ function useXlsxViewerController(options) {
8473
8532
  if (requestToken !== chartLoadRequestTokenRef.current) {
8474
8533
  return;
8475
8534
  }
8535
+ if (imageAssetsRef.current && !effectiveSkipXmlParsing) {
8536
+ const chartOriginsById = hydrateWorkbookChartStyles(result.chartsByWorkbookSheetIndex, imageAssetsRef.current);
8537
+ chartAssetsRef.current = { ...result, chartOriginsById };
8538
+ }
8476
8539
  setChartsByWorkbookSheetIndex(result.chartsByWorkbookSheetIndex);
8477
8540
  setChartsheets(result.chartsheets);
8478
8541
  setTabs(result.tabs);
@@ -8688,13 +8751,14 @@ function useXlsxViewerController(options) {
8688
8751
  return;
8689
8752
  }
8690
8753
  setImageAssets(workerImageAssets);
8754
+ const chartOriginsById = workerImageAssets ? hydrateWorkbookChartStyles(snapshot.chartsByWorkbookSheetIndex, workerImageAssets) : /* @__PURE__ */ new Map();
8691
8755
  setFormControlsByWorkbookSheetIndex(snapshot.formControlsByWorkbookSheetIndex);
8692
8756
  setWorkbook(null);
8693
8757
  setSheets(snapshot.sheets);
8694
8758
  setChartsByWorkbookSheetIndex(snapshot.chartsByWorkbookSheetIndex);
8695
8759
  setChartsheets(snapshot.chartsheets);
8696
8760
  setTabs(snapshot.tabs);
8697
- chartAssetsRef.current = null;
8761
+ chartAssetsRef.current = { ...snapshot, chartOriginsById };
8698
8762
  setWorkerTablesByWorkbookSheetIndex(snapshot.tablesByWorkbookSheetIndex);
8699
8763
  setShouldAutoCalculate(false);
8700
8764
  setIsWorkerBacked(true);
@@ -8906,6 +8970,9 @@ function useXlsxViewerController(options) {
8906
8970
  if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
8907
8971
  throw new Error("Worker chart payload incomplete");
8908
8972
  }
8973
+ const workerImageAssets = effectiveSkipXmlParsing ? null : parseWorkbookImageAssets(new Uint8Array(deferredBuffer));
8974
+ setImageAssets(workerImageAssets);
8975
+ const chartOriginsById = workerImageAssets ? hydrateWorkbookChartStyles(snapshot.chartsByWorkbookSheetIndex, workerImageAssets) : /* @__PURE__ */ new Map();
8909
8976
  deferredBufferRef.current = null;
8910
8977
  setDeferredLoadFileSize(null);
8911
8978
  setWorkbook(null);
@@ -8913,7 +8980,7 @@ function useXlsxViewerController(options) {
8913
8980
  setChartsByWorkbookSheetIndex(snapshot.chartsByWorkbookSheetIndex);
8914
8981
  setChartsheets(snapshot.chartsheets);
8915
8982
  setTabs(snapshot.tabs);
8916
- chartAssetsRef.current = null;
8983
+ chartAssetsRef.current = { ...snapshot, chartOriginsById };
8917
8984
  setFormControlsByWorkbookSheetIndex(snapshot.formControlsByWorkbookSheetIndex);
8918
8985
  setWorkerTablesByWorkbookSheetIndex(snapshot.tablesByWorkbookSheetIndex);
8919
8986
  setShouldAutoCalculate(false);
@@ -10004,7 +10071,7 @@ function useXlsxViewerController(options) {
10004
10071
  width: Math.max(1, right - left)
10005
10072
  };
10006
10073
  }, [getColumnWidthPx, getRowHeightPx]);
10007
- const setChartRect = React.useCallback((id, rect) => {
10074
+ const setChartRect = React.useCallback((id, rect, layout) => {
10008
10075
  const hydratedChartAssets = ensureChartAssetsHydrated(workbook, sheets);
10009
10076
  console.info("[react-xlsx debug] setChartRect", {
10010
10077
  hasActiveSheet: Boolean(activeSheet),
@@ -10033,8 +10100,8 @@ function useXlsxViewerController(options) {
10033
10100
  const nextAnchor = rectToImageAnchor(rect, currentChart.anchor, {
10034
10101
  contentOffsetLeft: GRID_ROW_HEADER_WIDTH,
10035
10102
  contentOffsetTop: GRID_HEADER_HEIGHT,
10036
- getColumnWidthPx: (col) => getColumnWidthPx(worksheet, col),
10037
- getRowHeightPx: (row) => getRowHeightPx(worksheet, row)
10103
+ getColumnWidthPx: (col) => layout?.columnWidths[col] ?? getColumnWidthPx(worksheet, col),
10104
+ getRowHeightPx: (row) => layout?.rowHeights[row] ?? getRowHeightPx(worksheet, row)
10038
10105
  });
10039
10106
  recordHistoryBeforeMutation();
10040
10107
  const didUpdateAnchor = updateWorkbookChartAnchor(imageAssetsRef.current, hydratedChartAssets, id, nextAnchor);
@@ -10053,7 +10120,7 @@ function useXlsxViewerController(options) {
10053
10120
  sheets,
10054
10121
  workbook
10055
10122
  ]);
10056
- const setImageRect = React.useCallback((id, rect) => {
10123
+ const setImageRect = React.useCallback((id, rect, layout) => {
10057
10124
  if (readOnly || !workbook || !activeSheet || !imageAssetsRef.current) {
10058
10125
  return;
10059
10126
  }
@@ -10065,8 +10132,8 @@ function useXlsxViewerController(options) {
10065
10132
  const nextAnchor = rectToImageAnchor(rect, currentImage.anchor, {
10066
10133
  contentOffsetLeft: GRID_ROW_HEADER_WIDTH,
10067
10134
  contentOffsetTop: GRID_HEADER_HEIGHT,
10068
- getColumnWidthPx: (col) => getColumnWidthPx(worksheet, col),
10069
- getRowHeightPx: (row) => getRowHeightPx(worksheet, row)
10135
+ getColumnWidthPx: (col) => layout?.columnWidths[col] ?? getColumnWidthPx(worksheet, col),
10136
+ getRowHeightPx: (row) => layout?.rowHeights[row] ?? getRowHeightPx(worksheet, row)
10070
10137
  });
10071
10138
  recordHistoryBeforeMutation();
10072
10139
  if (!updateWorkbookImageAnchor(imageAssetsRef.current, id, nextAnchor)) {
@@ -24163,6 +24230,8 @@ function XlsxGrid({
24163
24230
  const pendingSelectionDragCleanupRef = React4.useRef(null);
24164
24231
  const fillDragCleanupRef = React4.useRef(null);
24165
24232
  const cachedScrollerRectRef = React4.useRef(null);
24233
+ const installImageInteractionListenersRef = React4.useRef(installImageInteractionListeners);
24234
+ const installChartInteractionListenersRef = React4.useRef(installChartInteractionListeners);
24166
24235
  const imageInteractionCleanupRef = React4.useRef(null);
24167
24236
  const imageInteractionRef = React4.useRef(null);
24168
24237
  const chartInteractionCleanupRef = React4.useRef(null);
@@ -25150,6 +25219,10 @@ function XlsxGrid({
25150
25219
  React4.useEffect(() => {
25151
25220
  readOnlyRef.current = readOnly;
25152
25221
  }, [readOnly]);
25222
+ React4.useLayoutEffect(() => {
25223
+ installImageInteractionListenersRef.current = installImageInteractionListeners;
25224
+ installChartInteractionListenersRef.current = installChartInteractionListeners;
25225
+ });
25153
25226
  React4.useEffect(() => {
25154
25227
  chartPreviewRectRef.current = chartPreviewRect;
25155
25228
  }, [chartPreviewRect]);
@@ -29263,7 +29336,7 @@ function XlsxGrid({
29263
29336
  setInteractionMode("select");
29264
29337
  document.body.style.cursor = "move";
29265
29338
  document.body.style.userSelect = "none";
29266
- installChartInteractionListeners(event.pointerId);
29339
+ installChartInteractionListenersRef.current(event.pointerId);
29267
29340
  }, [focusGrid, selectChart]);
29268
29341
  const startChartResize = React4.useCallback((event, chart, rect, handle) => {
29269
29342
  if (readOnlyRef.current || chart.editable === false || event.button !== 0) {
@@ -29289,7 +29362,7 @@ function XlsxGrid({
29289
29362
  setInteractionMode("select");
29290
29363
  document.body.style.cursor = String(IMAGE_HANDLE_CURSOR[handle]);
29291
29364
  document.body.style.userSelect = "none";
29292
- installChartInteractionListeners(event.pointerId);
29365
+ installChartInteractionListenersRef.current(event.pointerId);
29293
29366
  }, [focusGrid, selectChart]);
29294
29367
  const startImageMove = React4.useCallback((event, image, rect) => {
29295
29368
  if (event.button !== 0) {
@@ -29317,7 +29390,7 @@ function XlsxGrid({
29317
29390
  setInteractionMode("select");
29318
29391
  document.body.style.cursor = "move";
29319
29392
  document.body.style.userSelect = "none";
29320
- installImageInteractionListeners(event.pointerId);
29393
+ installImageInteractionListenersRef.current(event.pointerId);
29321
29394
  }, [focusGrid, selectImage]);
29322
29395
  const startImageResize = React4.useCallback((event, image, rect, handle) => {
29323
29396
  if (readOnlyRef.current || image.editable === false || event.button !== 0) {
@@ -29343,7 +29416,7 @@ function XlsxGrid({
29343
29416
  setInteractionMode("select");
29344
29417
  document.body.style.cursor = String(IMAGE_HANDLE_CURSOR[handle]);
29345
29418
  document.body.style.userSelect = "none";
29346
- installImageInteractionListeners(event.pointerId);
29419
+ installImageInteractionListenersRef.current(event.pointerId);
29347
29420
  }, [focusGrid, selectImage]);
29348
29421
  const handleImageClick = React4.useCallback((image) => {
29349
29422
  if (skipNextImageClickRef.current === image.id) {
@@ -30711,7 +30784,10 @@ function XlsxGrid({
30711
30784
  skipNextImageClickRef.current = interaction.imageId;
30712
30785
  }
30713
30786
  if (interaction.didMove && finalRect) {
30714
- setImageRect(interaction.imageId, toLogicalRect(finalRect));
30787
+ setImageRect(interaction.imageId, toLogicalRect(finalRect), {
30788
+ columnWidths: actualColWidths,
30789
+ rowHeights: actualRowHeights
30790
+ });
30715
30791
  }
30716
30792
  }
30717
30793
  imagePreviewRectRef.current = null;
@@ -30788,7 +30864,10 @@ function XlsxGrid({
30788
30864
  skipNextChartClickRef.current = interaction.chartId;
30789
30865
  }
30790
30866
  if (interaction.didMove && finalRect) {
30791
- setChartRect(interaction.chartId, toLogicalRect(finalRect));
30867
+ setChartRect(interaction.chartId, toLogicalRect(finalRect), {
30868
+ columnWidths: actualColWidths,
30869
+ rowHeights: actualRowHeights
30870
+ });
30792
30871
  }
30793
30872
  }
30794
30873
  chartPreviewRectRef.current = null;