@coco-vexel/coco-office-editor 1.0.1 → 1.0.2

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 (51) hide show
  1. package/README.md +33 -1
  2. package/dist/index.cjs +352 -99
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +5 -4
  5. package/dist/index.d.ts +5 -4
  6. package/dist/index.js +353 -101
  7. package/dist/index.js.map +1 -1
  8. package/dist/{model-DB6aN6uJ.d.cts → model-DNNBhhCB.d.cts} +4 -3
  9. package/dist/{model-DB6aN6uJ.d.ts → model-DNNBhhCB.d.ts} +4 -3
  10. package/dist/{native-B6B649CC.d.ts → native-OrEUvS8p.d.ts} +5 -1
  11. package/dist/native-TMv552dv.d.cts +317 -0
  12. package/dist/native-TMv552dv.d.ts +317 -0
  13. package/dist/{native-Ct9nN06K.d.cts → native-f2y3N8N5.d.cts} +5 -1
  14. package/dist/ppt-native.cjs +129 -59
  15. package/dist/ppt-native.cjs.map +1 -1
  16. package/dist/ppt-native.d.cts +1 -1
  17. package/dist/ppt-native.d.ts +1 -1
  18. package/dist/ppt-native.js +130 -60
  19. package/dist/ppt-native.js.map +1 -1
  20. package/dist/ppt.cjs +129 -58
  21. package/dist/ppt.cjs.map +1 -1
  22. package/dist/ppt.d.cts +3 -306
  23. package/dist/ppt.d.ts +3 -306
  24. package/dist/ppt.js +130 -60
  25. package/dist/ppt.js.map +1 -1
  26. package/dist/read-only-1_LQCO1d.d.cts +7 -0
  27. package/dist/read-only-1_LQCO1d.d.ts +7 -0
  28. package/dist/spreadsheet.cjs +114 -17
  29. package/dist/spreadsheet.cjs.map +1 -1
  30. package/dist/spreadsheet.d.cts +15 -3
  31. package/dist/spreadsheet.d.ts +15 -3
  32. package/dist/spreadsheet.js +114 -18
  33. package/dist/spreadsheet.js.map +1 -1
  34. package/dist/word-editing.d.cts +1 -1
  35. package/dist/word-editing.d.ts +1 -1
  36. package/dist/word-native.cjs +132 -23
  37. package/dist/word-native.cjs.map +1 -1
  38. package/dist/word-native.d.cts +2 -2
  39. package/dist/word-native.d.ts +2 -2
  40. package/dist/word-native.js +132 -23
  41. package/dist/word-native.js.map +1 -1
  42. package/dist/word-prosemirror.d.cts +1 -1
  43. package/dist/word-prosemirror.d.ts +1 -1
  44. package/dist/word.cjs +145 -23
  45. package/dist/word.cjs.map +1 -1
  46. package/dist/word.d.cts +5 -4
  47. package/dist/word.d.ts +5 -4
  48. package/dist/word.js +145 -24
  49. package/dist/word.js.map +1 -1
  50. package/package.json +3 -3
  51. package/src/styles/editor.css +1 -0
package/dist/ppt.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Presentation } from '@coco-vexel/coco-office/ppt';
1
+ import { resolvePptEffectivePlaceholderProperties, Presentation } from '@coco-vexel/coco-office/ppt';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __defProps = Object.defineProperties;
@@ -34,7 +34,16 @@ var __objRest = (source, exclude) => {
34
34
  };
35
35
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
36
36
 
37
- // src/ppt/scene.ts
37
+ // src/read-only.ts
38
+ var _EditorReadOnlyError = class _EditorReadOnlyError extends Error {
39
+ constructor(editor) {
40
+ super(`${editor} editor is read-only`);
41
+ __publicField(this, "code", "EDITOR_READ_ONLY");
42
+ this.name = "EditorReadOnlyError";
43
+ }
44
+ };
45
+ __name(_EditorReadOnlyError, "EditorReadOnlyError");
46
+ var EditorReadOnlyError = _EditorReadOnlyError;
38
47
  var DEFAULT_PPT_SLIDE_SIZE = {
39
48
  width: 9144e3,
40
49
  height: 5143500
@@ -66,7 +75,7 @@ function buildPptSlideScene(slide, fallbackSize) {
66
75
  ].filter(shouldRenderInheritedShape);
67
76
  const shapes = [
68
77
  ...inheritedShapes,
69
- ...slide.shapes.map((shape) => applyPlaceholderInheritance(shape, layoutShapes))
78
+ ...slide.shapes.map((shape) => applyPlaceholderInheritance(shape, slide.layout))
70
79
  ];
71
80
  const renderShapes = shapes.flatMap(flattenRenderableShape);
72
81
  const background = (_j = (_g = slide.background) != null ? _g : (_f = slide.layout) == null ? void 0 : _f.background) != null ? _j : (_i = (_h = slide.layout) == null ? void 0 : _h.master) == null ? void 0 : _i.background;
@@ -207,28 +216,21 @@ function normalizeRotation(rotation) {
207
216
  return normalized === 0 ? void 0 : normalized;
208
217
  }
209
218
  __name(normalizeRotation, "normalizeRotation");
210
- function applyPlaceholderInheritance(shape, layoutShapes) {
211
- var _a;
212
- if (!shape.placeholder || !shape.text) return shape;
213
- const layoutShape = layoutShapes.find((candidate) => samePlaceholder(shape, candidate));
214
- const inheritedStyle = (_a = layoutShape == null ? void 0 : layoutShape.text) == null ? void 0 : _a.style;
215
- if (!inheritedStyle && !layoutShape) return shape;
216
- return __spreadProps(__spreadValues({}, shape), {
217
- geometry: __spreadValues(__spreadValues({}, layoutShape == null ? void 0 : layoutShape.geometry), shape.geometry),
219
+ function applyPlaceholderInheritance(shape, layout) {
220
+ if (!shape.placeholder) return shape;
221
+ const effective = resolvePptEffectivePlaceholderProperties(shape, layout);
222
+ return __spreadValues(__spreadProps(__spreadValues({}, shape), {
223
+ placeholder: effective.placeholder,
224
+ geometry: effective.geometry,
225
+ style: effective.style
226
+ }), shape.text ? {
218
227
  text: __spreadProps(__spreadValues({}, shape.text), {
219
- style: __spreadValues(__spreadValues({}, inheritedStyle), shape.text.style)
228
+ style: effective.textStyle,
229
+ body: effective.textBody
220
230
  })
221
- });
231
+ } : {});
222
232
  }
223
233
  __name(applyPlaceholderInheritance, "applyPlaceholderInheritance");
224
- function samePlaceholder(shape, candidate) {
225
- var _a, _b;
226
- if (!candidate.placeholder) return false;
227
- if (((_a = shape.placeholder) == null ? void 0 : _a.index) && candidate.placeholder.index === shape.placeholder.index)
228
- return true;
229
- return Boolean(((_b = shape.placeholder) == null ? void 0 : _b.type) && candidate.placeholder.type === shape.placeholder.type);
230
- }
231
- __name(samePlaceholder, "samePlaceholder");
232
234
  function buildPptSceneNode(shape, options = {}) {
233
235
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
234
236
  const capabilities = pptSceneNodeCapabilities(shape);
@@ -676,6 +678,7 @@ var _PptEditorSession = class _PptEditorSession {
676
678
  __publicField(this, "redoStack", []);
677
679
  __publicField(this, "textBodyOverrides", /* @__PURE__ */ new Map());
678
680
  __publicField(this, "maxHistory");
681
+ __publicField(this, "readOnlyValue");
679
682
  __publicField(this, "changeListeners", /* @__PURE__ */ new Set());
680
683
  __publicField(this, "selectionListeners", /* @__PURE__ */ new Set());
681
684
  var _a;
@@ -683,9 +686,11 @@ var _PptEditorSession = class _PptEditorSession {
683
686
  this.modelValue = view.model;
684
687
  this.sceneValue = view.scene;
685
688
  this.maxHistory = (_a = options.maxHistory) != null ? _a : 50;
689
+ this.readOnlyValue = options.readOnly === true;
686
690
  this.selectionValue = view.scene.slides[0] ? { kind: "slide", slideId: view.scene.slides[0].id } : null;
687
691
  }
688
692
  presentation() {
693
+ this.assertWritable();
689
694
  return this.presentationValue;
690
695
  }
691
696
  model() {
@@ -700,11 +705,17 @@ var _PptEditorSession = class _PptEditorSession {
700
705
  revision() {
701
706
  return this.revisionValue;
702
707
  }
708
+ isReadOnly() {
709
+ return this.readOnlyValue;
710
+ }
711
+ setReadOnly(readOnly) {
712
+ this.readOnlyValue = readOnly;
713
+ }
703
714
  canUndo() {
704
- return this.undoStack.length > 0;
715
+ return !this.readOnlyValue && this.undoStack.length > 0;
705
716
  }
706
717
  canRedo() {
707
- return this.redoStack.length > 0;
718
+ return !this.readOnlyValue && this.redoStack.length > 0;
708
719
  }
709
720
  subscribe(event, listener) {
710
721
  const listeners = event === "change" ? this.changeListeners : this.selectionListeners;
@@ -720,6 +731,7 @@ var _PptEditorSession = class _PptEditorSession {
720
731
  await this.applySelectionCommand(command);
721
732
  return;
722
733
  }
734
+ this.assertWritable();
723
735
  const before = await this.presentationValue.toZip();
724
736
  const nextSelection = await this.applyEditCommand(command);
725
737
  this.pushUndo(before);
@@ -728,6 +740,7 @@ var _PptEditorSession = class _PptEditorSession {
728
740
  if (nextSelection !== void 0) this.setSelection(nextSelection);
729
741
  }
730
742
  async undo() {
743
+ this.assertWritable();
731
744
  const entry = this.undoStack.pop();
732
745
  if (!entry) return;
733
746
  const selection = this.selectionValue;
@@ -736,6 +749,7 @@ var _PptEditorSession = class _PptEditorSession {
736
749
  await this.replacePresentation(entry.bytes, selection);
737
750
  }
738
751
  async redo() {
752
+ this.assertWritable();
739
753
  const entry = this.redoStack.pop();
740
754
  if (!entry) return;
741
755
  const selection = this.selectionValue;
@@ -768,6 +782,9 @@ var _PptEditorSession = class _PptEditorSession {
768
782
  this.changeListeners.clear();
769
783
  this.selectionListeners.clear();
770
784
  }
785
+ assertWritable() {
786
+ if (this.readOnlyValue) throw new EditorReadOnlyError("ppt");
787
+ }
771
788
  async applySelectionCommand(command) {
772
789
  const slide = findPptSceneSlide(this.sceneValue, command.slideIdOrIndex);
773
790
  if (!slide) throw new Error(`PPT slide not found: ${String(command.slideIdOrIndex)}`);
@@ -991,6 +1008,7 @@ var PPT_THUMB_WIDTH_PX = 128;
991
1008
  var PPT_THUMB_MARGIN_BOTTOM_PX = 8;
992
1009
  var PPT_THUMB_OVERSCAN = 2;
993
1010
  var PPT_THUMB_RASTER_SCALE = 2;
1011
+ var PPT_THUMB_LAYOUT_SCALE = 4;
994
1012
  function renderNativePptEditor(host, view, options = {}) {
995
1013
  return new NativePptEditorController(host, view, options);
996
1014
  }
@@ -1152,7 +1170,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1152
1170
  __publicField(this, "pendingCommands", /* @__PURE__ */ new Set());
1153
1171
  this.options = options;
1154
1172
  this.root = options.styleIsolation === "none" ? host : host.attachShadow({ mode: "open" });
1155
- this.sessionValue = new PptEditorSession(view);
1173
+ this.sessionValue = new PptEditorSession(view, { readOnly: options.readOnly });
1156
1174
  this.imageResources = view.images;
1157
1175
  this.fontResources = view.fonts;
1158
1176
  this.referencedFontFamilies = usedFontFamiliesInView(view);
@@ -1177,6 +1195,23 @@ var _NativePptEditorController = class _NativePptEditorController {
1177
1195
  selection() {
1178
1196
  return this.sessionValue.selection();
1179
1197
  }
1198
+ isReadOnly() {
1199
+ return this.sessionValue.isReadOnly();
1200
+ }
1201
+ setReadOnly(readOnly) {
1202
+ if (this.isReadOnly() === readOnly) return;
1203
+ const editable = this.root.querySelector('[contenteditable="true"]');
1204
+ editable == null ? void 0 : editable.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }));
1205
+ if (this.dragState) {
1206
+ this.restoreDragElementBounds(this.dragState);
1207
+ this.clearDragVisualState(this.dragState.element, true);
1208
+ this.dragState = null;
1209
+ this.hideSnapGuides();
1210
+ }
1211
+ this.hideContextMenu();
1212
+ this.sessionValue.setReadOnly(readOnly);
1213
+ this.render();
1214
+ }
1180
1215
  async dispatch(command) {
1181
1216
  const pending = this.dispatchAndRender(command);
1182
1217
  this.pendingCommands.add(pending);
@@ -1246,6 +1281,8 @@ var _NativePptEditorController = class _NativePptEditorController {
1246
1281
  ${fontFaceCss(this.fontResources)}
1247
1282
  :host, .coco-ppt-editor { box-sizing: border-box; width: 100%; height: 100%; min-height: 360px; }
1248
1283
  .coco-ppt-editor { display: grid; grid-template-columns: 160px minmax(0, 1fr); background: #f4f6f8; color: #17202a; font: 13px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
1284
+ .coco-ppt-editor[data-show-slide-list="false"] { grid-template-columns: minmax(0, 1fr); }
1285
+ .coco-ppt-editor[data-show-slide-list="false"] .coco-ppt-slides { display: none; }
1249
1286
  .coco-ppt-slides { overflow: auto; border-right: 1px solid #d7dde5; background: #edf1f5; padding: 8px; }
1250
1287
  .coco-ppt-thumb { width: 128px; aspect-ratio: 16 / 9; margin: 0 0 8px; border: 1px solid #c7d0dc; background: #fff; display: block; position: relative; overflow: hidden; cursor: pointer; padding: 0; }
1251
1288
  .coco-ppt-thumb[data-selected="true"] { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18); }
@@ -1275,6 +1312,11 @@ var _NativePptEditorController = class _NativePptEditorController {
1275
1312
  .coco-ppt-table td[contenteditable="true"] { cursor: text; outline: 2px solid #2563eb; outline-offset: -2px; }
1276
1313
  .coco-ppt-node[contenteditable="true"] { cursor: text; outline: 2px solid rgba(37, 99, 235, 0.3); user-select: text; }
1277
1314
  .coco-ppt-text-layer[contenteditable="true"] { cursor: text; outline: 2px solid rgba(37, 99, 235, 0.3); user-select: text; }
1315
+ .coco-ppt-editor[data-read-only="true"] .coco-ppt-node,
1316
+ .coco-ppt-editor[data-read-only="true"] .coco-ppt-text-layer,
1317
+ .coco-ppt-editor[data-read-only="true"] .coco-ppt-rich-text,
1318
+ .coco-ppt-editor[data-read-only="true"] .coco-ppt-paragraph { user-select: text; cursor: text; }
1319
+ .coco-ppt-editor[data-read-only="true"] .coco-ppt-resize-handle { display: none !important; }
1278
1320
  .coco-ppt-node[data-kind="picture"] { background: transparent; }
1279
1321
  .coco-ppt-unsupported-image { position: absolute; inset: 0; display: grid; place-items: center; box-sizing: border-box; border: 1px dashed rgba(100, 116, 139, 0.48); background: repeating-linear-gradient(135deg, rgba(148, 163, 184, 0.12) 0 8px, rgba(248, 250, 252, 0.1) 8px 16px); color: rgba(51, 65, 85, 0.72); font: 11px/1.2 "Segoe UI", sans-serif; pointer-events: none; }
1280
1322
  .coco-ppt-thumb-node .coco-ppt-unsupported-image { font-size: 8px; border-width: 0.5px; }
@@ -1311,6 +1353,8 @@ var _NativePptEditorController = class _NativePptEditorController {
1311
1353
  `;
1312
1354
  const shell = document.createElement("div");
1313
1355
  shell.className = "coco-ppt-editor";
1356
+ shell.dataset.showSlideList = String(this.options.showSlideList !== false);
1357
+ shell.dataset.readOnly = String(this.isReadOnly());
1314
1358
  this.slideList.className = "coco-ppt-slides";
1315
1359
  const stage = document.createElement("div");
1316
1360
  stage.className = "coco-ppt-stage";
@@ -1349,9 +1393,11 @@ var _NativePptEditorController = class _NativePptEditorController {
1349
1393
  });
1350
1394
  }
1351
1395
  render() {
1396
+ const shell = this.root.querySelector(".coco-ppt-editor");
1397
+ if (shell) shell.dataset.readOnly = String(this.isReadOnly());
1352
1398
  const scene = this.sessionValue.scene();
1353
1399
  this.slideList.replaceChildren(
1354
- ...scene.slides.map((slide) => {
1400
+ ...this.options.showSlideList === false ? [] : scene.slides.map((slide) => {
1355
1401
  var _a;
1356
1402
  const thumb = document.createElement("button");
1357
1403
  thumb.className = "coco-ppt-thumb";
@@ -1374,7 +1420,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1374
1420
  return thumb;
1375
1421
  })
1376
1422
  );
1377
- this.renderVisibleThumbnails(scene.slides);
1423
+ if (this.options.showSlideList !== false) this.renderVisibleThumbnails(scene.slides);
1378
1424
  const selected = this.currentSlide();
1379
1425
  if (!selected) {
1380
1426
  this.canvas.replaceChildren();
@@ -1443,9 +1489,11 @@ var _NativePptEditorController = class _NativePptEditorController {
1443
1489
  renderThumbnailSlide(slide) {
1444
1490
  const wrapper = document.createElement("div");
1445
1491
  wrapper.className = "coco-ppt-thumb-slide";
1446
- const scale = PPT_THUMB_WIDTH_PX / slide.size.width;
1492
+ const layoutWidth = PPT_THUMB_WIDTH_PX * PPT_THUMB_LAYOUT_SCALE;
1493
+ const scale = layoutWidth / slide.size.width;
1447
1494
  wrapper.style.width = `${slide.size.width * scale}px`;
1448
1495
  wrapper.style.height = `${slide.size.height * scale}px`;
1496
+ wrapper.style.transform = `scale(${1 / PPT_THUMB_LAYOUT_SCALE})`;
1449
1497
  wrapper.style.background = cssBackground(slide.background, this.imageResources);
1450
1498
  wrapper.replaceChildren(
1451
1499
  ...slide.nodes.map((node) => this.renderNode(node, scale, slide, false))
@@ -1467,7 +1515,9 @@ var _NativePptEditorController = class _NativePptEditorController {
1467
1515
  PPT_THUMB_WIDTH_PX,
1468
1516
  PPT_THUMB_WIDTH_PX * (slide.size.height / slide.size.width),
1469
1517
  PPT_THUMB_RASTER_SCALE,
1470
- (_b = (_a = this.root.querySelector("style")) == null ? void 0 : _a.textContent) != null ? _b : ""
1518
+ (_b = (_a = this.root.querySelector("style")) == null ? void 0 : _a.textContent) != null ? _b : "",
1519
+ PPT_THUMB_WIDTH_PX * PPT_THUMB_LAYOUT_SCALE,
1520
+ PPT_THUMB_WIDTH_PX * PPT_THUMB_LAYOUT_SCALE * (slide.size.height / slide.size.width)
1471
1521
  );
1472
1522
  if (!canvas) return;
1473
1523
  if (epoch !== this.thumbnailRasterEpoch || !thumb.isConnected) return;
@@ -1502,8 +1552,8 @@ var _NativePptEditorController = class _NativePptEditorController {
1502
1552
  element.dataset.kind = node.kind;
1503
1553
  element.dataset.locked = String(node.locked);
1504
1554
  if (interactive) {
1505
- element.dataset.draggable = String(node.capabilities.editGeometry);
1506
- element.dataset.resizable = String(node.capabilities.editGeometry);
1555
+ element.dataset.draggable = String(!this.isReadOnly() && node.capabilities.editGeometry);
1556
+ element.dataset.resizable = String(!this.isReadOnly() && node.capabilities.editGeometry);
1507
1557
  element.dataset.shapeId = node.id;
1508
1558
  }
1509
1559
  element.style.left = `${node.bounds.left * scale - (lineNode && lineAxis === "vertical" ? nodeWidth / 2 : 0)}px`;
@@ -1583,6 +1633,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1583
1633
  });
1584
1634
  });
1585
1635
  table.addEventListener("dblclick", (event) => {
1636
+ if (this.isReadOnly()) return;
1586
1637
  const cell = tableCellFromEvent(event);
1587
1638
  if (!cell || !node.capabilities.editTableCells) return;
1588
1639
  event.stopPropagation();
@@ -1636,7 +1687,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1636
1687
  const handle = document.createElement("div");
1637
1688
  handle.className = "coco-ppt-resize-handle";
1638
1689
  handle.addEventListener("mousedown", (event) => {
1639
- if (!node.capabilities.editGeometry) return;
1690
+ if (this.isReadOnly() || !node.capabilities.editGeometry) return;
1640
1691
  event.preventDefault();
1641
1692
  event.stopPropagation();
1642
1693
  this.startDrag(event, "resize", slide, node, scale, element);
@@ -1691,6 +1742,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1691
1742
  });
1692
1743
  element.addEventListener("contextmenu", (event) => {
1693
1744
  var _a2;
1745
+ if (this.isReadOnly()) return;
1694
1746
  event.preventDefault();
1695
1747
  event.stopPropagation();
1696
1748
  const targetNode = (_a2 = this.pointerOperationNode(slide, node, event, scale)) != null ? _a2 : node;
@@ -1704,7 +1756,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1704
1756
  var _a2, _b2;
1705
1757
  const targetNode = (_a2 = this.pointerOperationNode(slide, node, event, scale)) != null ? _a2 : node;
1706
1758
  const targetElement = (_b2 = elementForShape(this.canvas, targetNode.id)) != null ? _b2 : element;
1707
- if (isEditingText(targetElement, event.target) || event.button !== 0 || !targetNode.capabilities.editGeometry)
1759
+ if (isEditingText(targetElement, event.target) || this.isReadOnly() || event.button !== 0 || !targetNode.capabilities.editGeometry)
1708
1760
  return;
1709
1761
  event.preventDefault();
1710
1762
  event.stopPropagation();
@@ -1712,6 +1764,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1712
1764
  });
1713
1765
  element.addEventListener("dblclick", (event) => {
1714
1766
  var _a2, _b2, _c2;
1767
+ if (this.isReadOnly()) return;
1715
1768
  event.stopPropagation();
1716
1769
  const redirectedNode = redirectedEditableTextHit(slide, node, event, scale);
1717
1770
  if (redirectedNode) {
@@ -1790,6 +1843,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1790
1843
  }
1791
1844
  startTextEdit(element, slide, node) {
1792
1845
  var _a, _b, _c, _d;
1846
+ if (this.isReadOnly()) return;
1793
1847
  const originalText = (_a = node.text) != null ? _a : "";
1794
1848
  const editableTarget = editableTextTarget(element);
1795
1849
  let finished = false;
@@ -1882,6 +1936,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1882
1936
  }
1883
1937
  startTableCellEdit(cell, slide, node, row, column) {
1884
1938
  var _a, _b, _c;
1939
+ if (this.isReadOnly()) return;
1885
1940
  const originalText = tableCellRawText(cell, node, row, column);
1886
1941
  let finished = false;
1887
1942
  void this.sessionValue.dispatch({ kind: "select-shape", slideIdOrIndex: slide.id, shapeIdOrName: node.id }).then(() => this.renderSelection());
@@ -1962,6 +2017,7 @@ var _NativePptEditorController = class _NativePptEditorController {
1962
2017
  cell.addEventListener("paste", handlePaste);
1963
2018
  }
1964
2019
  startDrag(event, mode, slide, node, scale, element) {
2020
+ if (this.isReadOnly()) return;
1965
2021
  if (mode === "resize") prepareTextResizePreview(element, node);
1966
2022
  this.dragState = {
1967
2023
  mode,
@@ -2267,6 +2323,7 @@ var _NativePptEditorController = class _NativePptEditorController {
2267
2323
  const node = slide == null ? void 0 : slide.nodes.find((item) => item.id === selection.shapeId);
2268
2324
  if (!slide || !node) return;
2269
2325
  const commandKey = event.ctrlKey || event.metaKey;
2326
+ if (this.isReadOnly()) return;
2270
2327
  if (commandKey && event.key.toLowerCase() === "c") {
2271
2328
  event.preventDefault();
2272
2329
  this.copySelectedShape(slide, node);
@@ -2325,6 +2382,7 @@ var _NativePptEditorController = class _NativePptEditorController {
2325
2382
  });
2326
2383
  }
2327
2384
  handleSelectStart(event) {
2385
+ if (this.isReadOnly()) return;
2328
2386
  if (isTypingTarget(event.target)) return;
2329
2387
  if (event.target instanceof HTMLElement && event.target.closest('[contenteditable="true"]'))
2330
2388
  return;
@@ -2419,6 +2477,7 @@ var _NativePptEditorController = class _NativePptEditorController {
2419
2477
  });
2420
2478
  }
2421
2479
  showContextMenu(event, slide, node) {
2480
+ if (this.isReadOnly()) return;
2422
2481
  const editable = isShapeCollectionEditable(node);
2423
2482
  const hasClipboard = Boolean(this.clipboardShape);
2424
2483
  const run = /* @__PURE__ */ __name((action) => () => {
@@ -2618,7 +2677,7 @@ function nextAnimationFrame() {
2618
2677
  return new Promise((resolve) => requestAnimationFrame(() => resolve()));
2619
2678
  }
2620
2679
  __name(nextAnimationFrame, "nextAnimationFrame");
2621
- async function rasterizeThumbnailElement(element, width, height, scale, cssText) {
2680
+ async function rasterizeThumbnailElement(element, width, height, scale, cssText, layoutWidth = width, layoutHeight = height) {
2622
2681
  if (typeof XMLSerializer === "undefined" || typeof Blob === "undefined" || typeof URL === "undefined" || typeof URL.createObjectURL !== "function")
2623
2682
  return null;
2624
2683
  await waitForThumbnailImages(element);
@@ -2629,8 +2688,8 @@ async function rasterizeThumbnailElement(element, width, height, scale, cssText)
2629
2688
  if (!context) return null;
2630
2689
  const wrapper = document.createElement("div");
2631
2690
  wrapper.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
2632
- wrapper.style.width = `${width}px`;
2633
- wrapper.style.height = `${height}px`;
2691
+ wrapper.style.width = `${layoutWidth}px`;
2692
+ wrapper.style.height = `${layoutHeight}px`;
2634
2693
  wrapper.style.position = "relative";
2635
2694
  wrapper.style.overflow = "hidden";
2636
2695
  wrapper.style.background = "#fff";
@@ -2641,9 +2700,10 @@ async function rasterizeThumbnailElement(element, width, height, scale, cssText)
2641
2700
  clone.style.position = "relative";
2642
2701
  clone.style.left = "0";
2643
2702
  clone.style.top = "0";
2703
+ clone.style.transform = "none";
2644
2704
  wrapper.append(style, clone);
2645
2705
  const serialized = new XMLSerializer().serializeToString(wrapper);
2646
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${canvas.width}" height="${canvas.height}" viewBox="0 0 ${width} ${height}"><foreignObject width="100%" height="100%">${serialized}</foreignObject></svg>`;
2706
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${canvas.width}" height="${canvas.height}" viewBox="0 0 ${layoutWidth} ${layoutHeight}"><foreignObject width="100%" height="100%">${serialized}</foreignObject></svg>`;
2647
2707
  const url = URL.createObjectURL(new Blob([svg], { type: "image/svg+xml;charset=utf-8" }));
2648
2708
  try {
2649
2709
  const image = await loadRasterImage(url);
@@ -3013,13 +3073,9 @@ function googleFontCssUrl(family) {
3013
3073
  }
3014
3074
  __name(googleFontCssUrl, "googleFontCssUrl");
3015
3075
  function cssFontFamilyStack(family) {
3016
- return [
3017
- cssString(family),
3018
- '"Calibri"',
3019
- '"Microsoft YaHei"',
3020
- '"Segoe UI"',
3021
- "sans-serif"
3022
- ].join(", ");
3076
+ return [cssString(family), '"Calibri"', '"Microsoft YaHei"', '"Segoe UI"', "sans-serif"].join(
3077
+ ", "
3078
+ );
3023
3079
  }
3024
3080
  __name(cssFontFamilyStack, "cssFontFamilyStack");
3025
3081
  function cssString(value) {
@@ -3522,8 +3578,7 @@ __name(firstExplicitFontSize, "firstExplicitFontSize");
3522
3578
  function applyTextStyleToElement(element, style, scale) {
3523
3579
  var _a, _b, _c;
3524
3580
  if (style.fontSize) element.style.fontSize = `${Math.max(1, style.fontSize * 12700 * scale)}px`;
3525
- if (style.fontFamily)
3526
- element.style.fontFamily = cssFontFamilyStack(style.fontFamily);
3581
+ if (style.fontFamily) element.style.fontFamily = cssFontFamilyStack(style.fontFamily);
3527
3582
  if (style.lineHeight) element.style.lineHeight = String(style.lineHeight);
3528
3583
  if (style.characterSpacing !== void 0)
3529
3584
  element.style.letterSpacing = `${style.characterSpacing * 12700 * scale}px`;
@@ -3818,7 +3873,10 @@ function renderPresetGeometry(node, scale) {
3818
3873
  const fillOpacity = effectiveFillOpacity(node);
3819
3874
  if (fillOpacity !== void 0 && node.presetGeometry !== "arc")
3820
3875
  path.setAttribute("fill-opacity", String(fillOpacity));
3821
- path.setAttribute("stroke", lineGradientId ? `url(#${lineGradientId})` : (_c = node.lineColor) != null ? _c : "none");
3876
+ path.setAttribute(
3877
+ "stroke",
3878
+ lineGradientId ? `url(#${lineGradientId})` : (_c = node.lineColor) != null ? _c : "none"
3879
+ );
3822
3880
  path.setAttribute("stroke-width", String(strokeWidth));
3823
3881
  if (node.lineOpacity !== void 0)
3824
3882
  path.setAttribute("stroke-opacity", String(Math.max(0, Math.min(1, node.lineOpacity))));
@@ -4032,14 +4090,18 @@ function customGeometryIsRectangular(geometry) {
4032
4090
  { x: 0, y: height }
4033
4091
  ];
4034
4092
  return corners.every(
4035
- (corner) => unique.some((point) => geometryPointNear(point.x, corner.x) && geometryPointNear(point.y, corner.y))
4093
+ (corner) => unique.some(
4094
+ (point) => geometryPointNear(point.x, corner.x) && geometryPointNear(point.y, corner.y)
4095
+ )
4036
4096
  );
4037
4097
  }
4038
4098
  __name(customGeometryIsRectangular, "customGeometryIsRectangular");
4039
4099
  function dedupeGeometryPoints(points) {
4040
4100
  const result = [];
4041
4101
  for (const point of points) {
4042
- if (!result.some((existing) => geometryPointNear(existing.x, point.x) && geometryPointNear(existing.y, point.y))) {
4102
+ if (!result.some(
4103
+ (existing) => geometryPointNear(existing.x, point.x) && geometryPointNear(existing.y, point.y)
4104
+ )) {
4043
4105
  result.push(point);
4044
4106
  }
4045
4107
  }
@@ -4065,7 +4127,8 @@ function renderCustomGeometryPicture(node, url) {
4065
4127
  for (const path of (_h = (_g = node.customGeometry) == null ? void 0 : _g.paths) != null ? _h : []) {
4066
4128
  const clipShape = document.createElementNS("http://www.w3.org/2000/svg", "path");
4067
4129
  clipShape.setAttribute("d", customGeometryPathData(path.commands));
4068
- if (customGeometryNeedsEvenOddFill(path.commands)) clipShape.setAttribute("fill-rule", "evenodd");
4130
+ if (customGeometryNeedsEvenOddFill(path.commands))
4131
+ clipShape.setAttribute("fill-rule", "evenodd");
4069
4132
  clipPath.append(clipShape);
4070
4133
  }
4071
4134
  defs.append(clipPath);
@@ -4150,7 +4213,10 @@ function renderCustomGeometry(node, scale) {
4150
4213
  const fillOpacity = effectiveFillOpacity(node);
4151
4214
  if (hasFill && fillOpacity !== void 0)
4152
4215
  shape.setAttribute("fill-opacity", String(fillOpacity));
4153
- shape.setAttribute("stroke", lineGradientId ? `url(#${lineGradientId})` : (_j = node.lineColor) != null ? _j : "none");
4216
+ shape.setAttribute(
4217
+ "stroke",
4218
+ lineGradientId ? `url(#${lineGradientId})` : (_j = node.lineColor) != null ? _j : "none"
4219
+ );
4154
4220
  shape.setAttribute("stroke-width", String(strokeWidth));
4155
4221
  if (node.lineOpacity !== void 0)
4156
4222
  shape.setAttribute("stroke-opacity", String(Math.max(0, Math.min(1, node.lineOpacity))));
@@ -4174,13 +4240,7 @@ function customGeometryEllipse(path) {
4174
4240
  }
4175
4241
  const cx = width / 2;
4176
4242
  const cy = height / 2;
4177
- const endpoints = [
4178
- commands[0],
4179
- commands[1],
4180
- commands[2],
4181
- commands[3],
4182
- commands[4]
4183
- ];
4243
+ const endpoints = [commands[0], commands[1], commands[2], commands[3], commands[4]];
4184
4244
  const expected = [
4185
4245
  { x: width, y: cy },
4186
4246
  { x: cx, y: height },
@@ -4354,7 +4414,9 @@ function customGeometryPathData(commands) {
4354
4414
  parts.push(`L ${command.x} ${command.y}`);
4355
4415
  current = { x: command.x, y: command.y };
4356
4416
  } else if (command.kind === "cubicBezierTo") {
4357
- parts.push(`C ${command.x1} ${command.y1} ${command.x2} ${command.y2} ${command.x} ${command.y}`);
4417
+ parts.push(
4418
+ `C ${command.x1} ${command.y1} ${command.x2} ${command.y2} ${command.x} ${command.y}`
4419
+ );
4358
4420
  current = { x: command.x, y: command.y };
4359
4421
  } else if (command.kind === "arcTo") {
4360
4422
  const arc = svgArcCommandForCustomGeometry(command, current);
@@ -5098,7 +5160,15 @@ function renderLineValueLabels(svg, seriesList, plot, min, max) {
5098
5160
  series.values.forEach((value, pointIndex) => {
5099
5161
  const x = plot.left + (series.values.length === 1 ? plot.width / 2 : plot.width * pointIndex / (series.values.length - 1));
5100
5162
  const y = plot.top + plot.height - (value - min) / Math.max(1, max - min) * plot.height;
5101
- appendSvgText(svg, String(value), x, Math.max(plot.top + 2, y - 2.2), 2.6, "#374151", "middle");
5163
+ appendSvgText(
5164
+ svg,
5165
+ String(value),
5166
+ x,
5167
+ Math.max(plot.top + 2, y - 2.2),
5168
+ 2.6,
5169
+ "#374151",
5170
+ "middle"
5171
+ );
5102
5172
  });
5103
5173
  });
5104
5174
  }
@@ -5405,6 +5475,6 @@ function appendSvgMultilineText(svg, lines, x, y, size, color, anchor = "start")
5405
5475
  }
5406
5476
  __name(appendSvgMultilineText, "appendSvgMultilineText");
5407
5477
 
5408
- export { DEFAULT_PPT_SLIDE_SIZE, PptEditorSession, buildPptEditorViewFromModel, buildPptEditorViewFromPptx, buildPptEditorViewFromPresentation, buildPptPresentationScene, buildPptSceneNode, buildPptSlideScene, findPptSceneNode, findPptSceneSlide, isPptShapeEditable, normalizePptGeometry, pptSceneGeometryToSourceGeometry, pptSceneNodeCapabilities, renderNativePptEditor };
5478
+ export { DEFAULT_PPT_SLIDE_SIZE, EditorReadOnlyError, PptEditorSession, buildPptEditorViewFromModel, buildPptEditorViewFromPptx, buildPptEditorViewFromPresentation, buildPptPresentationScene, buildPptSceneNode, buildPptSlideScene, findPptSceneNode, findPptSceneSlide, isPptShapeEditable, normalizePptGeometry, pptSceneGeometryToSourceGeometry, pptSceneNodeCapabilities, renderNativePptEditor };
5409
5479
  //# sourceMappingURL=ppt.js.map
5410
5480
  //# sourceMappingURL=ppt.js.map