@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.
- package/README.md +33 -1
- package/dist/index.cjs +352 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +353 -101
- package/dist/index.js.map +1 -1
- package/dist/{model-DB6aN6uJ.d.cts → model-DNNBhhCB.d.cts} +4 -3
- package/dist/{model-DB6aN6uJ.d.ts → model-DNNBhhCB.d.ts} +4 -3
- package/dist/{native-B6B649CC.d.ts → native-OrEUvS8p.d.ts} +5 -1
- package/dist/native-TMv552dv.d.cts +317 -0
- package/dist/native-TMv552dv.d.ts +317 -0
- package/dist/{native-Ct9nN06K.d.cts → native-f2y3N8N5.d.cts} +5 -1
- package/dist/ppt-native.cjs +129 -59
- package/dist/ppt-native.cjs.map +1 -1
- package/dist/ppt-native.d.cts +1 -1
- package/dist/ppt-native.d.ts +1 -1
- package/dist/ppt-native.js +130 -60
- package/dist/ppt-native.js.map +1 -1
- package/dist/ppt.cjs +129 -58
- package/dist/ppt.cjs.map +1 -1
- package/dist/ppt.d.cts +3 -306
- package/dist/ppt.d.ts +3 -306
- package/dist/ppt.js +130 -60
- package/dist/ppt.js.map +1 -1
- package/dist/read-only-1_LQCO1d.d.cts +7 -0
- package/dist/read-only-1_LQCO1d.d.ts +7 -0
- package/dist/spreadsheet.cjs +114 -17
- package/dist/spreadsheet.cjs.map +1 -1
- package/dist/spreadsheet.d.cts +15 -3
- package/dist/spreadsheet.d.ts +15 -3
- package/dist/spreadsheet.js +114 -18
- package/dist/spreadsheet.js.map +1 -1
- package/dist/word-editing.d.cts +1 -1
- package/dist/word-editing.d.ts +1 -1
- package/dist/word-native.cjs +132 -23
- package/dist/word-native.cjs.map +1 -1
- package/dist/word-native.d.cts +2 -2
- package/dist/word-native.d.ts +2 -2
- package/dist/word-native.js +132 -23
- package/dist/word-native.js.map +1 -1
- package/dist/word-prosemirror.d.cts +1 -1
- package/dist/word-prosemirror.d.ts +1 -1
- package/dist/word.cjs +145 -23
- package/dist/word.cjs.map +1 -1
- package/dist/word.d.cts +5 -4
- package/dist/word.d.ts +5 -4
- package/dist/word.js +145 -24
- package/dist/word.js.map +1 -1
- package/package.json +3 -3
- package/src/styles/editor.css +1 -0
package/dist/ppt.cjs
CHANGED
|
@@ -36,7 +36,16 @@ var __objRest = (source, exclude) => {
|
|
|
36
36
|
};
|
|
37
37
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
38
38
|
|
|
39
|
-
// src/
|
|
39
|
+
// src/read-only.ts
|
|
40
|
+
var _EditorReadOnlyError = class _EditorReadOnlyError extends Error {
|
|
41
|
+
constructor(editor) {
|
|
42
|
+
super(`${editor} editor is read-only`);
|
|
43
|
+
__publicField(this, "code", "EDITOR_READ_ONLY");
|
|
44
|
+
this.name = "EditorReadOnlyError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__name(_EditorReadOnlyError, "EditorReadOnlyError");
|
|
48
|
+
var EditorReadOnlyError = _EditorReadOnlyError;
|
|
40
49
|
var DEFAULT_PPT_SLIDE_SIZE = {
|
|
41
50
|
width: 9144e3,
|
|
42
51
|
height: 5143500
|
|
@@ -68,7 +77,7 @@ function buildPptSlideScene(slide, fallbackSize) {
|
|
|
68
77
|
].filter(shouldRenderInheritedShape);
|
|
69
78
|
const shapes = [
|
|
70
79
|
...inheritedShapes,
|
|
71
|
-
...slide.shapes.map((shape) => applyPlaceholderInheritance(shape,
|
|
80
|
+
...slide.shapes.map((shape) => applyPlaceholderInheritance(shape, slide.layout))
|
|
72
81
|
];
|
|
73
82
|
const renderShapes = shapes.flatMap(flattenRenderableShape);
|
|
74
83
|
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;
|
|
@@ -209,28 +218,21 @@ function normalizeRotation(rotation) {
|
|
|
209
218
|
return normalized === 0 ? void 0 : normalized;
|
|
210
219
|
}
|
|
211
220
|
__name(normalizeRotation, "normalizeRotation");
|
|
212
|
-
function applyPlaceholderInheritance(shape,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
function applyPlaceholderInheritance(shape, layout) {
|
|
222
|
+
if (!shape.placeholder) return shape;
|
|
223
|
+
const effective = ppt.resolvePptEffectivePlaceholderProperties(shape, layout);
|
|
224
|
+
return __spreadValues(__spreadProps(__spreadValues({}, shape), {
|
|
225
|
+
placeholder: effective.placeholder,
|
|
226
|
+
geometry: effective.geometry,
|
|
227
|
+
style: effective.style
|
|
228
|
+
}), shape.text ? {
|
|
220
229
|
text: __spreadProps(__spreadValues({}, shape.text), {
|
|
221
|
-
style:
|
|
230
|
+
style: effective.textStyle,
|
|
231
|
+
body: effective.textBody
|
|
222
232
|
})
|
|
223
|
-
});
|
|
233
|
+
} : {});
|
|
224
234
|
}
|
|
225
235
|
__name(applyPlaceholderInheritance, "applyPlaceholderInheritance");
|
|
226
|
-
function samePlaceholder(shape, candidate) {
|
|
227
|
-
var _a, _b;
|
|
228
|
-
if (!candidate.placeholder) return false;
|
|
229
|
-
if (((_a = shape.placeholder) == null ? void 0 : _a.index) && candidate.placeholder.index === shape.placeholder.index)
|
|
230
|
-
return true;
|
|
231
|
-
return Boolean(((_b = shape.placeholder) == null ? void 0 : _b.type) && candidate.placeholder.type === shape.placeholder.type);
|
|
232
|
-
}
|
|
233
|
-
__name(samePlaceholder, "samePlaceholder");
|
|
234
236
|
function buildPptSceneNode(shape, options = {}) {
|
|
235
237
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
236
238
|
const capabilities = pptSceneNodeCapabilities(shape);
|
|
@@ -678,6 +680,7 @@ var _PptEditorSession = class _PptEditorSession {
|
|
|
678
680
|
__publicField(this, "redoStack", []);
|
|
679
681
|
__publicField(this, "textBodyOverrides", /* @__PURE__ */ new Map());
|
|
680
682
|
__publicField(this, "maxHistory");
|
|
683
|
+
__publicField(this, "readOnlyValue");
|
|
681
684
|
__publicField(this, "changeListeners", /* @__PURE__ */ new Set());
|
|
682
685
|
__publicField(this, "selectionListeners", /* @__PURE__ */ new Set());
|
|
683
686
|
var _a;
|
|
@@ -685,9 +688,11 @@ var _PptEditorSession = class _PptEditorSession {
|
|
|
685
688
|
this.modelValue = view.model;
|
|
686
689
|
this.sceneValue = view.scene;
|
|
687
690
|
this.maxHistory = (_a = options.maxHistory) != null ? _a : 50;
|
|
691
|
+
this.readOnlyValue = options.readOnly === true;
|
|
688
692
|
this.selectionValue = view.scene.slides[0] ? { kind: "slide", slideId: view.scene.slides[0].id } : null;
|
|
689
693
|
}
|
|
690
694
|
presentation() {
|
|
695
|
+
this.assertWritable();
|
|
691
696
|
return this.presentationValue;
|
|
692
697
|
}
|
|
693
698
|
model() {
|
|
@@ -702,11 +707,17 @@ var _PptEditorSession = class _PptEditorSession {
|
|
|
702
707
|
revision() {
|
|
703
708
|
return this.revisionValue;
|
|
704
709
|
}
|
|
710
|
+
isReadOnly() {
|
|
711
|
+
return this.readOnlyValue;
|
|
712
|
+
}
|
|
713
|
+
setReadOnly(readOnly) {
|
|
714
|
+
this.readOnlyValue = readOnly;
|
|
715
|
+
}
|
|
705
716
|
canUndo() {
|
|
706
|
-
return this.undoStack.length > 0;
|
|
717
|
+
return !this.readOnlyValue && this.undoStack.length > 0;
|
|
707
718
|
}
|
|
708
719
|
canRedo() {
|
|
709
|
-
return this.redoStack.length > 0;
|
|
720
|
+
return !this.readOnlyValue && this.redoStack.length > 0;
|
|
710
721
|
}
|
|
711
722
|
subscribe(event, listener) {
|
|
712
723
|
const listeners = event === "change" ? this.changeListeners : this.selectionListeners;
|
|
@@ -722,6 +733,7 @@ var _PptEditorSession = class _PptEditorSession {
|
|
|
722
733
|
await this.applySelectionCommand(command);
|
|
723
734
|
return;
|
|
724
735
|
}
|
|
736
|
+
this.assertWritable();
|
|
725
737
|
const before = await this.presentationValue.toZip();
|
|
726
738
|
const nextSelection = await this.applyEditCommand(command);
|
|
727
739
|
this.pushUndo(before);
|
|
@@ -730,6 +742,7 @@ var _PptEditorSession = class _PptEditorSession {
|
|
|
730
742
|
if (nextSelection !== void 0) this.setSelection(nextSelection);
|
|
731
743
|
}
|
|
732
744
|
async undo() {
|
|
745
|
+
this.assertWritable();
|
|
733
746
|
const entry = this.undoStack.pop();
|
|
734
747
|
if (!entry) return;
|
|
735
748
|
const selection = this.selectionValue;
|
|
@@ -738,6 +751,7 @@ var _PptEditorSession = class _PptEditorSession {
|
|
|
738
751
|
await this.replacePresentation(entry.bytes, selection);
|
|
739
752
|
}
|
|
740
753
|
async redo() {
|
|
754
|
+
this.assertWritable();
|
|
741
755
|
const entry = this.redoStack.pop();
|
|
742
756
|
if (!entry) return;
|
|
743
757
|
const selection = this.selectionValue;
|
|
@@ -770,6 +784,9 @@ var _PptEditorSession = class _PptEditorSession {
|
|
|
770
784
|
this.changeListeners.clear();
|
|
771
785
|
this.selectionListeners.clear();
|
|
772
786
|
}
|
|
787
|
+
assertWritable() {
|
|
788
|
+
if (this.readOnlyValue) throw new EditorReadOnlyError("ppt");
|
|
789
|
+
}
|
|
773
790
|
async applySelectionCommand(command) {
|
|
774
791
|
const slide = findPptSceneSlide(this.sceneValue, command.slideIdOrIndex);
|
|
775
792
|
if (!slide) throw new Error(`PPT slide not found: ${String(command.slideIdOrIndex)}`);
|
|
@@ -993,6 +1010,7 @@ var PPT_THUMB_WIDTH_PX = 128;
|
|
|
993
1010
|
var PPT_THUMB_MARGIN_BOTTOM_PX = 8;
|
|
994
1011
|
var PPT_THUMB_OVERSCAN = 2;
|
|
995
1012
|
var PPT_THUMB_RASTER_SCALE = 2;
|
|
1013
|
+
var PPT_THUMB_LAYOUT_SCALE = 4;
|
|
996
1014
|
function renderNativePptEditor(host, view, options = {}) {
|
|
997
1015
|
return new NativePptEditorController(host, view, options);
|
|
998
1016
|
}
|
|
@@ -1154,7 +1172,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1154
1172
|
__publicField(this, "pendingCommands", /* @__PURE__ */ new Set());
|
|
1155
1173
|
this.options = options;
|
|
1156
1174
|
this.root = options.styleIsolation === "none" ? host : host.attachShadow({ mode: "open" });
|
|
1157
|
-
this.sessionValue = new PptEditorSession(view);
|
|
1175
|
+
this.sessionValue = new PptEditorSession(view, { readOnly: options.readOnly });
|
|
1158
1176
|
this.imageResources = view.images;
|
|
1159
1177
|
this.fontResources = view.fonts;
|
|
1160
1178
|
this.referencedFontFamilies = usedFontFamiliesInView(view);
|
|
@@ -1179,6 +1197,23 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1179
1197
|
selection() {
|
|
1180
1198
|
return this.sessionValue.selection();
|
|
1181
1199
|
}
|
|
1200
|
+
isReadOnly() {
|
|
1201
|
+
return this.sessionValue.isReadOnly();
|
|
1202
|
+
}
|
|
1203
|
+
setReadOnly(readOnly) {
|
|
1204
|
+
if (this.isReadOnly() === readOnly) return;
|
|
1205
|
+
const editable = this.root.querySelector('[contenteditable="true"]');
|
|
1206
|
+
editable == null ? void 0 : editable.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }));
|
|
1207
|
+
if (this.dragState) {
|
|
1208
|
+
this.restoreDragElementBounds(this.dragState);
|
|
1209
|
+
this.clearDragVisualState(this.dragState.element, true);
|
|
1210
|
+
this.dragState = null;
|
|
1211
|
+
this.hideSnapGuides();
|
|
1212
|
+
}
|
|
1213
|
+
this.hideContextMenu();
|
|
1214
|
+
this.sessionValue.setReadOnly(readOnly);
|
|
1215
|
+
this.render();
|
|
1216
|
+
}
|
|
1182
1217
|
async dispatch(command) {
|
|
1183
1218
|
const pending = this.dispatchAndRender(command);
|
|
1184
1219
|
this.pendingCommands.add(pending);
|
|
@@ -1248,6 +1283,8 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1248
1283
|
${fontFaceCss(this.fontResources)}
|
|
1249
1284
|
:host, .coco-ppt-editor { box-sizing: border-box; width: 100%; height: 100%; min-height: 360px; }
|
|
1250
1285
|
.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; }
|
|
1286
|
+
.coco-ppt-editor[data-show-slide-list="false"] { grid-template-columns: minmax(0, 1fr); }
|
|
1287
|
+
.coco-ppt-editor[data-show-slide-list="false"] .coco-ppt-slides { display: none; }
|
|
1251
1288
|
.coco-ppt-slides { overflow: auto; border-right: 1px solid #d7dde5; background: #edf1f5; padding: 8px; }
|
|
1252
1289
|
.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; }
|
|
1253
1290
|
.coco-ppt-thumb[data-selected="true"] { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18); }
|
|
@@ -1277,6 +1314,11 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1277
1314
|
.coco-ppt-table td[contenteditable="true"] { cursor: text; outline: 2px solid #2563eb; outline-offset: -2px; }
|
|
1278
1315
|
.coco-ppt-node[contenteditable="true"] { cursor: text; outline: 2px solid rgba(37, 99, 235, 0.3); user-select: text; }
|
|
1279
1316
|
.coco-ppt-text-layer[contenteditable="true"] { cursor: text; outline: 2px solid rgba(37, 99, 235, 0.3); user-select: text; }
|
|
1317
|
+
.coco-ppt-editor[data-read-only="true"] .coco-ppt-node,
|
|
1318
|
+
.coco-ppt-editor[data-read-only="true"] .coco-ppt-text-layer,
|
|
1319
|
+
.coco-ppt-editor[data-read-only="true"] .coco-ppt-rich-text,
|
|
1320
|
+
.coco-ppt-editor[data-read-only="true"] .coco-ppt-paragraph { user-select: text; cursor: text; }
|
|
1321
|
+
.coco-ppt-editor[data-read-only="true"] .coco-ppt-resize-handle { display: none !important; }
|
|
1280
1322
|
.coco-ppt-node[data-kind="picture"] { background: transparent; }
|
|
1281
1323
|
.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; }
|
|
1282
1324
|
.coco-ppt-thumb-node .coco-ppt-unsupported-image { font-size: 8px; border-width: 0.5px; }
|
|
@@ -1313,6 +1355,8 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1313
1355
|
`;
|
|
1314
1356
|
const shell = document.createElement("div");
|
|
1315
1357
|
shell.className = "coco-ppt-editor";
|
|
1358
|
+
shell.dataset.showSlideList = String(this.options.showSlideList !== false);
|
|
1359
|
+
shell.dataset.readOnly = String(this.isReadOnly());
|
|
1316
1360
|
this.slideList.className = "coco-ppt-slides";
|
|
1317
1361
|
const stage = document.createElement("div");
|
|
1318
1362
|
stage.className = "coco-ppt-stage";
|
|
@@ -1351,9 +1395,11 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1351
1395
|
});
|
|
1352
1396
|
}
|
|
1353
1397
|
render() {
|
|
1398
|
+
const shell = this.root.querySelector(".coco-ppt-editor");
|
|
1399
|
+
if (shell) shell.dataset.readOnly = String(this.isReadOnly());
|
|
1354
1400
|
const scene = this.sessionValue.scene();
|
|
1355
1401
|
this.slideList.replaceChildren(
|
|
1356
|
-
...scene.slides.map((slide) => {
|
|
1402
|
+
...this.options.showSlideList === false ? [] : scene.slides.map((slide) => {
|
|
1357
1403
|
var _a;
|
|
1358
1404
|
const thumb = document.createElement("button");
|
|
1359
1405
|
thumb.className = "coco-ppt-thumb";
|
|
@@ -1376,7 +1422,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1376
1422
|
return thumb;
|
|
1377
1423
|
})
|
|
1378
1424
|
);
|
|
1379
|
-
this.renderVisibleThumbnails(scene.slides);
|
|
1425
|
+
if (this.options.showSlideList !== false) this.renderVisibleThumbnails(scene.slides);
|
|
1380
1426
|
const selected = this.currentSlide();
|
|
1381
1427
|
if (!selected) {
|
|
1382
1428
|
this.canvas.replaceChildren();
|
|
@@ -1445,9 +1491,11 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1445
1491
|
renderThumbnailSlide(slide) {
|
|
1446
1492
|
const wrapper = document.createElement("div");
|
|
1447
1493
|
wrapper.className = "coco-ppt-thumb-slide";
|
|
1448
|
-
const
|
|
1494
|
+
const layoutWidth = PPT_THUMB_WIDTH_PX * PPT_THUMB_LAYOUT_SCALE;
|
|
1495
|
+
const scale = layoutWidth / slide.size.width;
|
|
1449
1496
|
wrapper.style.width = `${slide.size.width * scale}px`;
|
|
1450
1497
|
wrapper.style.height = `${slide.size.height * scale}px`;
|
|
1498
|
+
wrapper.style.transform = `scale(${1 / PPT_THUMB_LAYOUT_SCALE})`;
|
|
1451
1499
|
wrapper.style.background = cssBackground(slide.background, this.imageResources);
|
|
1452
1500
|
wrapper.replaceChildren(
|
|
1453
1501
|
...slide.nodes.map((node) => this.renderNode(node, scale, slide, false))
|
|
@@ -1469,7 +1517,9 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1469
1517
|
PPT_THUMB_WIDTH_PX,
|
|
1470
1518
|
PPT_THUMB_WIDTH_PX * (slide.size.height / slide.size.width),
|
|
1471
1519
|
PPT_THUMB_RASTER_SCALE,
|
|
1472
|
-
(_b = (_a = this.root.querySelector("style")) == null ? void 0 : _a.textContent) != null ? _b : ""
|
|
1520
|
+
(_b = (_a = this.root.querySelector("style")) == null ? void 0 : _a.textContent) != null ? _b : "",
|
|
1521
|
+
PPT_THUMB_WIDTH_PX * PPT_THUMB_LAYOUT_SCALE,
|
|
1522
|
+
PPT_THUMB_WIDTH_PX * PPT_THUMB_LAYOUT_SCALE * (slide.size.height / slide.size.width)
|
|
1473
1523
|
);
|
|
1474
1524
|
if (!canvas) return;
|
|
1475
1525
|
if (epoch !== this.thumbnailRasterEpoch || !thumb.isConnected) return;
|
|
@@ -1504,8 +1554,8 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1504
1554
|
element.dataset.kind = node.kind;
|
|
1505
1555
|
element.dataset.locked = String(node.locked);
|
|
1506
1556
|
if (interactive) {
|
|
1507
|
-
element.dataset.draggable = String(node.capabilities.editGeometry);
|
|
1508
|
-
element.dataset.resizable = String(node.capabilities.editGeometry);
|
|
1557
|
+
element.dataset.draggable = String(!this.isReadOnly() && node.capabilities.editGeometry);
|
|
1558
|
+
element.dataset.resizable = String(!this.isReadOnly() && node.capabilities.editGeometry);
|
|
1509
1559
|
element.dataset.shapeId = node.id;
|
|
1510
1560
|
}
|
|
1511
1561
|
element.style.left = `${node.bounds.left * scale - (lineNode && lineAxis === "vertical" ? nodeWidth / 2 : 0)}px`;
|
|
@@ -1585,6 +1635,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1585
1635
|
});
|
|
1586
1636
|
});
|
|
1587
1637
|
table.addEventListener("dblclick", (event) => {
|
|
1638
|
+
if (this.isReadOnly()) return;
|
|
1588
1639
|
const cell = tableCellFromEvent(event);
|
|
1589
1640
|
if (!cell || !node.capabilities.editTableCells) return;
|
|
1590
1641
|
event.stopPropagation();
|
|
@@ -1638,7 +1689,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1638
1689
|
const handle = document.createElement("div");
|
|
1639
1690
|
handle.className = "coco-ppt-resize-handle";
|
|
1640
1691
|
handle.addEventListener("mousedown", (event) => {
|
|
1641
|
-
if (!node.capabilities.editGeometry) return;
|
|
1692
|
+
if (this.isReadOnly() || !node.capabilities.editGeometry) return;
|
|
1642
1693
|
event.preventDefault();
|
|
1643
1694
|
event.stopPropagation();
|
|
1644
1695
|
this.startDrag(event, "resize", slide, node, scale, element);
|
|
@@ -1693,6 +1744,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1693
1744
|
});
|
|
1694
1745
|
element.addEventListener("contextmenu", (event) => {
|
|
1695
1746
|
var _a2;
|
|
1747
|
+
if (this.isReadOnly()) return;
|
|
1696
1748
|
event.preventDefault();
|
|
1697
1749
|
event.stopPropagation();
|
|
1698
1750
|
const targetNode = (_a2 = this.pointerOperationNode(slide, node, event, scale)) != null ? _a2 : node;
|
|
@@ -1706,7 +1758,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1706
1758
|
var _a2, _b2;
|
|
1707
1759
|
const targetNode = (_a2 = this.pointerOperationNode(slide, node, event, scale)) != null ? _a2 : node;
|
|
1708
1760
|
const targetElement = (_b2 = elementForShape(this.canvas, targetNode.id)) != null ? _b2 : element;
|
|
1709
|
-
if (isEditingText(targetElement, event.target) || event.button !== 0 || !targetNode.capabilities.editGeometry)
|
|
1761
|
+
if (isEditingText(targetElement, event.target) || this.isReadOnly() || event.button !== 0 || !targetNode.capabilities.editGeometry)
|
|
1710
1762
|
return;
|
|
1711
1763
|
event.preventDefault();
|
|
1712
1764
|
event.stopPropagation();
|
|
@@ -1714,6 +1766,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1714
1766
|
});
|
|
1715
1767
|
element.addEventListener("dblclick", (event) => {
|
|
1716
1768
|
var _a2, _b2, _c2;
|
|
1769
|
+
if (this.isReadOnly()) return;
|
|
1717
1770
|
event.stopPropagation();
|
|
1718
1771
|
const redirectedNode = redirectedEditableTextHit(slide, node, event, scale);
|
|
1719
1772
|
if (redirectedNode) {
|
|
@@ -1792,6 +1845,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1792
1845
|
}
|
|
1793
1846
|
startTextEdit(element, slide, node) {
|
|
1794
1847
|
var _a, _b, _c, _d;
|
|
1848
|
+
if (this.isReadOnly()) return;
|
|
1795
1849
|
const originalText = (_a = node.text) != null ? _a : "";
|
|
1796
1850
|
const editableTarget = editableTextTarget(element);
|
|
1797
1851
|
let finished = false;
|
|
@@ -1884,6 +1938,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1884
1938
|
}
|
|
1885
1939
|
startTableCellEdit(cell, slide, node, row, column) {
|
|
1886
1940
|
var _a, _b, _c;
|
|
1941
|
+
if (this.isReadOnly()) return;
|
|
1887
1942
|
const originalText = tableCellRawText(cell, node, row, column);
|
|
1888
1943
|
let finished = false;
|
|
1889
1944
|
void this.sessionValue.dispatch({ kind: "select-shape", slideIdOrIndex: slide.id, shapeIdOrName: node.id }).then(() => this.renderSelection());
|
|
@@ -1964,6 +2019,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
1964
2019
|
cell.addEventListener("paste", handlePaste);
|
|
1965
2020
|
}
|
|
1966
2021
|
startDrag(event, mode, slide, node, scale, element) {
|
|
2022
|
+
if (this.isReadOnly()) return;
|
|
1967
2023
|
if (mode === "resize") prepareTextResizePreview(element, node);
|
|
1968
2024
|
this.dragState = {
|
|
1969
2025
|
mode,
|
|
@@ -2269,6 +2325,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
2269
2325
|
const node = slide == null ? void 0 : slide.nodes.find((item) => item.id === selection.shapeId);
|
|
2270
2326
|
if (!slide || !node) return;
|
|
2271
2327
|
const commandKey = event.ctrlKey || event.metaKey;
|
|
2328
|
+
if (this.isReadOnly()) return;
|
|
2272
2329
|
if (commandKey && event.key.toLowerCase() === "c") {
|
|
2273
2330
|
event.preventDefault();
|
|
2274
2331
|
this.copySelectedShape(slide, node);
|
|
@@ -2327,6 +2384,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
2327
2384
|
});
|
|
2328
2385
|
}
|
|
2329
2386
|
handleSelectStart(event) {
|
|
2387
|
+
if (this.isReadOnly()) return;
|
|
2330
2388
|
if (isTypingTarget(event.target)) return;
|
|
2331
2389
|
if (event.target instanceof HTMLElement && event.target.closest('[contenteditable="true"]'))
|
|
2332
2390
|
return;
|
|
@@ -2421,6 +2479,7 @@ var _NativePptEditorController = class _NativePptEditorController {
|
|
|
2421
2479
|
});
|
|
2422
2480
|
}
|
|
2423
2481
|
showContextMenu(event, slide, node) {
|
|
2482
|
+
if (this.isReadOnly()) return;
|
|
2424
2483
|
const editable = isShapeCollectionEditable(node);
|
|
2425
2484
|
const hasClipboard = Boolean(this.clipboardShape);
|
|
2426
2485
|
const run = /* @__PURE__ */ __name((action) => () => {
|
|
@@ -2620,7 +2679,7 @@ function nextAnimationFrame() {
|
|
|
2620
2679
|
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
2621
2680
|
}
|
|
2622
2681
|
__name(nextAnimationFrame, "nextAnimationFrame");
|
|
2623
|
-
async function rasterizeThumbnailElement(element, width, height, scale, cssText) {
|
|
2682
|
+
async function rasterizeThumbnailElement(element, width, height, scale, cssText, layoutWidth = width, layoutHeight = height) {
|
|
2624
2683
|
if (typeof XMLSerializer === "undefined" || typeof Blob === "undefined" || typeof URL === "undefined" || typeof URL.createObjectURL !== "function")
|
|
2625
2684
|
return null;
|
|
2626
2685
|
await waitForThumbnailImages(element);
|
|
@@ -2631,8 +2690,8 @@ async function rasterizeThumbnailElement(element, width, height, scale, cssText)
|
|
|
2631
2690
|
if (!context) return null;
|
|
2632
2691
|
const wrapper = document.createElement("div");
|
|
2633
2692
|
wrapper.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
|
2634
|
-
wrapper.style.width = `${
|
|
2635
|
-
wrapper.style.height = `${
|
|
2693
|
+
wrapper.style.width = `${layoutWidth}px`;
|
|
2694
|
+
wrapper.style.height = `${layoutHeight}px`;
|
|
2636
2695
|
wrapper.style.position = "relative";
|
|
2637
2696
|
wrapper.style.overflow = "hidden";
|
|
2638
2697
|
wrapper.style.background = "#fff";
|
|
@@ -2643,9 +2702,10 @@ async function rasterizeThumbnailElement(element, width, height, scale, cssText)
|
|
|
2643
2702
|
clone.style.position = "relative";
|
|
2644
2703
|
clone.style.left = "0";
|
|
2645
2704
|
clone.style.top = "0";
|
|
2705
|
+
clone.style.transform = "none";
|
|
2646
2706
|
wrapper.append(style, clone);
|
|
2647
2707
|
const serialized = new XMLSerializer().serializeToString(wrapper);
|
|
2648
|
-
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${canvas.width}" height="${canvas.height}" viewBox="0 0 ${
|
|
2708
|
+
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>`;
|
|
2649
2709
|
const url = URL.createObjectURL(new Blob([svg], { type: "image/svg+xml;charset=utf-8" }));
|
|
2650
2710
|
try {
|
|
2651
2711
|
const image = await loadRasterImage(url);
|
|
@@ -3015,13 +3075,9 @@ function googleFontCssUrl(family) {
|
|
|
3015
3075
|
}
|
|
3016
3076
|
__name(googleFontCssUrl, "googleFontCssUrl");
|
|
3017
3077
|
function cssFontFamilyStack(family) {
|
|
3018
|
-
return [
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
'"Microsoft YaHei"',
|
|
3022
|
-
'"Segoe UI"',
|
|
3023
|
-
"sans-serif"
|
|
3024
|
-
].join(", ");
|
|
3078
|
+
return [cssString(family), '"Calibri"', '"Microsoft YaHei"', '"Segoe UI"', "sans-serif"].join(
|
|
3079
|
+
", "
|
|
3080
|
+
);
|
|
3025
3081
|
}
|
|
3026
3082
|
__name(cssFontFamilyStack, "cssFontFamilyStack");
|
|
3027
3083
|
function cssString(value) {
|
|
@@ -3524,8 +3580,7 @@ __name(firstExplicitFontSize, "firstExplicitFontSize");
|
|
|
3524
3580
|
function applyTextStyleToElement(element, style, scale) {
|
|
3525
3581
|
var _a, _b, _c;
|
|
3526
3582
|
if (style.fontSize) element.style.fontSize = `${Math.max(1, style.fontSize * 12700 * scale)}px`;
|
|
3527
|
-
if (style.fontFamily)
|
|
3528
|
-
element.style.fontFamily = cssFontFamilyStack(style.fontFamily);
|
|
3583
|
+
if (style.fontFamily) element.style.fontFamily = cssFontFamilyStack(style.fontFamily);
|
|
3529
3584
|
if (style.lineHeight) element.style.lineHeight = String(style.lineHeight);
|
|
3530
3585
|
if (style.characterSpacing !== void 0)
|
|
3531
3586
|
element.style.letterSpacing = `${style.characterSpacing * 12700 * scale}px`;
|
|
@@ -3820,7 +3875,10 @@ function renderPresetGeometry(node, scale) {
|
|
|
3820
3875
|
const fillOpacity = effectiveFillOpacity(node);
|
|
3821
3876
|
if (fillOpacity !== void 0 && node.presetGeometry !== "arc")
|
|
3822
3877
|
path.setAttribute("fill-opacity", String(fillOpacity));
|
|
3823
|
-
path.setAttribute(
|
|
3878
|
+
path.setAttribute(
|
|
3879
|
+
"stroke",
|
|
3880
|
+
lineGradientId ? `url(#${lineGradientId})` : (_c = node.lineColor) != null ? _c : "none"
|
|
3881
|
+
);
|
|
3824
3882
|
path.setAttribute("stroke-width", String(strokeWidth));
|
|
3825
3883
|
if (node.lineOpacity !== void 0)
|
|
3826
3884
|
path.setAttribute("stroke-opacity", String(Math.max(0, Math.min(1, node.lineOpacity))));
|
|
@@ -4034,14 +4092,18 @@ function customGeometryIsRectangular(geometry) {
|
|
|
4034
4092
|
{ x: 0, y: height }
|
|
4035
4093
|
];
|
|
4036
4094
|
return corners.every(
|
|
4037
|
-
(corner) => unique.some(
|
|
4095
|
+
(corner) => unique.some(
|
|
4096
|
+
(point) => geometryPointNear(point.x, corner.x) && geometryPointNear(point.y, corner.y)
|
|
4097
|
+
)
|
|
4038
4098
|
);
|
|
4039
4099
|
}
|
|
4040
4100
|
__name(customGeometryIsRectangular, "customGeometryIsRectangular");
|
|
4041
4101
|
function dedupeGeometryPoints(points) {
|
|
4042
4102
|
const result = [];
|
|
4043
4103
|
for (const point of points) {
|
|
4044
|
-
if (!result.some(
|
|
4104
|
+
if (!result.some(
|
|
4105
|
+
(existing) => geometryPointNear(existing.x, point.x) && geometryPointNear(existing.y, point.y)
|
|
4106
|
+
)) {
|
|
4045
4107
|
result.push(point);
|
|
4046
4108
|
}
|
|
4047
4109
|
}
|
|
@@ -4067,7 +4129,8 @@ function renderCustomGeometryPicture(node, url) {
|
|
|
4067
4129
|
for (const path of (_h = (_g = node.customGeometry) == null ? void 0 : _g.paths) != null ? _h : []) {
|
|
4068
4130
|
const clipShape = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
4069
4131
|
clipShape.setAttribute("d", customGeometryPathData(path.commands));
|
|
4070
|
-
if (customGeometryNeedsEvenOddFill(path.commands))
|
|
4132
|
+
if (customGeometryNeedsEvenOddFill(path.commands))
|
|
4133
|
+
clipShape.setAttribute("fill-rule", "evenodd");
|
|
4071
4134
|
clipPath.append(clipShape);
|
|
4072
4135
|
}
|
|
4073
4136
|
defs.append(clipPath);
|
|
@@ -4152,7 +4215,10 @@ function renderCustomGeometry(node, scale) {
|
|
|
4152
4215
|
const fillOpacity = effectiveFillOpacity(node);
|
|
4153
4216
|
if (hasFill && fillOpacity !== void 0)
|
|
4154
4217
|
shape.setAttribute("fill-opacity", String(fillOpacity));
|
|
4155
|
-
shape.setAttribute(
|
|
4218
|
+
shape.setAttribute(
|
|
4219
|
+
"stroke",
|
|
4220
|
+
lineGradientId ? `url(#${lineGradientId})` : (_j = node.lineColor) != null ? _j : "none"
|
|
4221
|
+
);
|
|
4156
4222
|
shape.setAttribute("stroke-width", String(strokeWidth));
|
|
4157
4223
|
if (node.lineOpacity !== void 0)
|
|
4158
4224
|
shape.setAttribute("stroke-opacity", String(Math.max(0, Math.min(1, node.lineOpacity))));
|
|
@@ -4176,13 +4242,7 @@ function customGeometryEllipse(path) {
|
|
|
4176
4242
|
}
|
|
4177
4243
|
const cx = width / 2;
|
|
4178
4244
|
const cy = height / 2;
|
|
4179
|
-
const endpoints = [
|
|
4180
|
-
commands[0],
|
|
4181
|
-
commands[1],
|
|
4182
|
-
commands[2],
|
|
4183
|
-
commands[3],
|
|
4184
|
-
commands[4]
|
|
4185
|
-
];
|
|
4245
|
+
const endpoints = [commands[0], commands[1], commands[2], commands[3], commands[4]];
|
|
4186
4246
|
const expected = [
|
|
4187
4247
|
{ x: width, y: cy },
|
|
4188
4248
|
{ x: cx, y: height },
|
|
@@ -4356,7 +4416,9 @@ function customGeometryPathData(commands) {
|
|
|
4356
4416
|
parts.push(`L ${command.x} ${command.y}`);
|
|
4357
4417
|
current = { x: command.x, y: command.y };
|
|
4358
4418
|
} else if (command.kind === "cubicBezierTo") {
|
|
4359
|
-
parts.push(
|
|
4419
|
+
parts.push(
|
|
4420
|
+
`C ${command.x1} ${command.y1} ${command.x2} ${command.y2} ${command.x} ${command.y}`
|
|
4421
|
+
);
|
|
4360
4422
|
current = { x: command.x, y: command.y };
|
|
4361
4423
|
} else if (command.kind === "arcTo") {
|
|
4362
4424
|
const arc = svgArcCommandForCustomGeometry(command, current);
|
|
@@ -5100,7 +5162,15 @@ function renderLineValueLabels(svg, seriesList, plot, min, max) {
|
|
|
5100
5162
|
series.values.forEach((value, pointIndex) => {
|
|
5101
5163
|
const x = plot.left + (series.values.length === 1 ? plot.width / 2 : plot.width * pointIndex / (series.values.length - 1));
|
|
5102
5164
|
const y = plot.top + plot.height - (value - min) / Math.max(1, max - min) * plot.height;
|
|
5103
|
-
appendSvgText(
|
|
5165
|
+
appendSvgText(
|
|
5166
|
+
svg,
|
|
5167
|
+
String(value),
|
|
5168
|
+
x,
|
|
5169
|
+
Math.max(plot.top + 2, y - 2.2),
|
|
5170
|
+
2.6,
|
|
5171
|
+
"#374151",
|
|
5172
|
+
"middle"
|
|
5173
|
+
);
|
|
5104
5174
|
});
|
|
5105
5175
|
});
|
|
5106
5176
|
}
|
|
@@ -5408,6 +5478,7 @@ function appendSvgMultilineText(svg, lines, x, y, size, color, anchor = "start")
|
|
|
5408
5478
|
__name(appendSvgMultilineText, "appendSvgMultilineText");
|
|
5409
5479
|
|
|
5410
5480
|
exports.DEFAULT_PPT_SLIDE_SIZE = DEFAULT_PPT_SLIDE_SIZE;
|
|
5481
|
+
exports.EditorReadOnlyError = EditorReadOnlyError;
|
|
5411
5482
|
exports.PptEditorSession = PptEditorSession;
|
|
5412
5483
|
exports.buildPptEditorViewFromModel = buildPptEditorViewFromModel;
|
|
5413
5484
|
exports.buildPptEditorViewFromPptx = buildPptEditorViewFromPptx;
|