@yudaocode/univer-boards 1.6.218 → 1.6.219
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 +6 -1
- package/lib/cjs/facade/index.js +45 -0
- package/lib/cjs/facade/index.js.map +1 -1
- package/lib/cjs/index.js +1352 -83
- package/lib/cjs/index.js.map +1 -1
- package/lib/es/facade/index.js +53 -0
- package/lib/es/facade/index.js.map +1 -1
- package/lib/es/index.js +1310 -46
- package/lib/es/index.js.map +1 -1
- package/lib/types/facade/index.d.ts +21 -1
- package/lib/types/index.d.ts +187 -2
- package/package.json +1 -1
package/lib/es/index.js
CHANGED
|
@@ -12,23 +12,23 @@ var __decorateParam = (index, decorator) => (target, key) => decorator(target, k
|
|
|
12
12
|
|
|
13
13
|
// src/plugin.ts
|
|
14
14
|
import {
|
|
15
|
-
ICommandService as
|
|
15
|
+
ICommandService as ICommandService3,
|
|
16
16
|
Inject,
|
|
17
17
|
Injector,
|
|
18
|
-
IUniverInstanceService as
|
|
18
|
+
IUniverInstanceService as IUniverInstanceService4,
|
|
19
19
|
Plugin,
|
|
20
|
-
UniverInstanceType as
|
|
20
|
+
UniverInstanceType as UniverInstanceType5
|
|
21
21
|
} from "@univerjs/core";
|
|
22
22
|
|
|
23
23
|
// src/commands/commands/board.command.ts
|
|
24
24
|
import {
|
|
25
25
|
CommandType as CommandType2,
|
|
26
|
-
generateRandomId as
|
|
27
|
-
ICommandService,
|
|
26
|
+
generateRandomId as generateRandomId4,
|
|
27
|
+
ICommandService as ICommandService2,
|
|
28
28
|
IUndoRedoService,
|
|
29
|
-
IUniverInstanceService as
|
|
29
|
+
IUniverInstanceService as IUniverInstanceService3,
|
|
30
30
|
Tools as Tools2,
|
|
31
|
-
UniverInstanceType as
|
|
31
|
+
UniverInstanceType as UniverInstanceType3
|
|
32
32
|
} from "@univerjs/core";
|
|
33
33
|
|
|
34
34
|
// src/engine/mindmap-layout.ts
|
|
@@ -60,6 +60,81 @@ function resolveStickyPalette(color) {
|
|
|
60
60
|
}
|
|
61
61
|
return BOARD_STICKY_PALETTE.yellow;
|
|
62
62
|
}
|
|
63
|
+
function isStickyMaskedForViewer(sticky, brainstorm, viewerUserId) {
|
|
64
|
+
if (!brainstorm?.active || brainstorm.revealed) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (sticky.authorId && sticky.authorId !== viewerUserId) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
function findContainingFrame(el, snapshot) {
|
|
73
|
+
if (el.frameId) {
|
|
74
|
+
const direct = snapshot.elements[el.frameId];
|
|
75
|
+
if (direct && direct.type === "frame") {
|
|
76
|
+
return direct;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const cx = el.x + el.width / 2;
|
|
80
|
+
const cy = el.y + el.height / 2;
|
|
81
|
+
const frameIds = snapshot.frameOrder.length ? snapshot.frameOrder : Object.keys(snapshot.elements).filter((id) => snapshot.elements[id]?.type === "frame");
|
|
82
|
+
for (const fid of frameIds) {
|
|
83
|
+
const frame = snapshot.elements[fid];
|
|
84
|
+
if (frame && frame.type === "frame" && cx >= frame.x && cx <= frame.x + frame.width && cy >= frame.y && cy <= frame.y + frame.height) {
|
|
85
|
+
return frame;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
function computeBoardVotingLeaderboard(snapshot, options) {
|
|
91
|
+
const orderIds = snapshot.elementOrder.length ? [...snapshot.elementOrder] : Object.keys(snapshot.elements);
|
|
92
|
+
const seen = new Set(orderIds);
|
|
93
|
+
for (const key of Object.keys(snapshot.elements)) {
|
|
94
|
+
if (!seen.has(key)) {
|
|
95
|
+
orderIds.push(key);
|
|
96
|
+
seen.add(key);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const effectiveFrameId = options?.targetFrameId ?? snapshot.votingSession?.targetFrameId;
|
|
100
|
+
const sessionTally = /* @__PURE__ */ new Map();
|
|
101
|
+
if (snapshot.votingSession) {
|
|
102
|
+
for (const votedIds of Object.values(snapshot.votingSession.votesByUser)) {
|
|
103
|
+
for (const sid of votedIds) {
|
|
104
|
+
sessionTally.set(sid, (sessionTally.get(sid) ?? 0) + 1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const candidates = [];
|
|
109
|
+
orderIds.forEach((id, orderIndex) => {
|
|
110
|
+
const el = snapshot.elements[id];
|
|
111
|
+
if (!el || el.type !== "sticky" || el.hidden) return;
|
|
112
|
+
const frame = findContainingFrame(el, snapshot);
|
|
113
|
+
if (effectiveFrameId && snapshot.elements[effectiveFrameId]?.type === "frame") {
|
|
114
|
+
if (frame?.id !== effectiveFrameId) return;
|
|
115
|
+
}
|
|
116
|
+
const voteCount = snapshot.votingSession ? sessionTally.get(el.id) ?? 0 : el.votes.length;
|
|
117
|
+
candidates.push({
|
|
118
|
+
sticky: el,
|
|
119
|
+
voteCount,
|
|
120
|
+
frameTitle: frame?.title ?? "",
|
|
121
|
+
orderIndex
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
candidates.sort((a, b) => {
|
|
125
|
+
if (b.voteCount !== a.voteCount) return b.voteCount - a.voteCount;
|
|
126
|
+
return a.orderIndex - b.orderIndex;
|
|
127
|
+
});
|
|
128
|
+
return candidates.map((item, idx) => ({
|
|
129
|
+
rank: idx + 1,
|
|
130
|
+
elementId: item.sticky.id,
|
|
131
|
+
text: item.sticky.text,
|
|
132
|
+
voteCount: item.voteCount,
|
|
133
|
+
frameTitle: item.frameTitle,
|
|
134
|
+
color: item.sticky.color,
|
|
135
|
+
...item.sticky.author ? { author: item.sticky.author } : {}
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
63
138
|
var MINDMAP_BRANCH_PALETTE = [
|
|
64
139
|
"#2563EB",
|
|
65
140
|
"#7C3AED",
|
|
@@ -121,6 +196,7 @@ function createDefaultBoardElement(type, partial) {
|
|
|
121
196
|
text: partial?.text ?? "\u53CC\u51FB\u8F93\u5165\u4FBF\u7B7E\u60F3\u6CD5...",
|
|
122
197
|
color: partial?.color ?? "yellow",
|
|
123
198
|
author: partial?.author ?? "\u534F\u4F5C\u6210\u5458",
|
|
199
|
+
...typeof partial?.authorId === "string" && partial.authorId ? { authorId: partial.authorId } : {},
|
|
124
200
|
votes: Array.isArray(partial?.votes) ? [...partial.votes] : [],
|
|
125
201
|
tags: Array.isArray(partial?.tags) ? [...partial.tags] : [],
|
|
126
202
|
x,
|
|
@@ -560,8 +636,781 @@ function layoutBoardMindmap(elements, rootId, options) {
|
|
|
560
636
|
return fullMap;
|
|
561
637
|
}
|
|
562
638
|
|
|
563
|
-
// src/
|
|
639
|
+
// src/exporter/board-doc-tiler.ts
|
|
564
640
|
import { generateRandomId as generateRandomId2 } from "@univerjs/core";
|
|
641
|
+
import { PDFArray, PDFDocument, PDFName, PDFRawStream } from "pdf-lib";
|
|
642
|
+
var BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
643
|
+
function uint8ToBase64(bytes) {
|
|
644
|
+
let out = "";
|
|
645
|
+
const len = bytes.length;
|
|
646
|
+
for (let i = 0; i < len; i += 3) {
|
|
647
|
+
const b0 = bytes[i];
|
|
648
|
+
const b1 = i + 1 < len ? bytes[i + 1] : 0;
|
|
649
|
+
const b2 = i + 2 < len ? bytes[i + 2] : 0;
|
|
650
|
+
const triplet = b0 << 16 | b1 << 8 | b2;
|
|
651
|
+
out += BASE64_ALPHABET[triplet >>> 18 & 63];
|
|
652
|
+
out += BASE64_ALPHABET[triplet >>> 12 & 63];
|
|
653
|
+
out += i + 1 < len ? BASE64_ALPHABET[triplet >>> 6 & 63] : "=";
|
|
654
|
+
out += i + 2 < len ? BASE64_ALPHABET[triplet & 63] : "=";
|
|
655
|
+
}
|
|
656
|
+
return out;
|
|
657
|
+
}
|
|
658
|
+
function unescapeXml(raw) {
|
|
659
|
+
return raw.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code))).replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => String.fromCharCode(parseInt(hex, 16))).replace(/&/g, "&");
|
|
660
|
+
}
|
|
661
|
+
async function decompressBytesIfSupported(compressed, format) {
|
|
662
|
+
const DecompCtor = globalThis.DecompressionStream;
|
|
663
|
+
if (typeof DecompCtor !== "function") {
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
try {
|
|
667
|
+
const copy = compressed.slice().buffer;
|
|
668
|
+
const stream = new Blob([copy]).stream().pipeThrough(new DecompCtor(format));
|
|
669
|
+
const ab = await new Response(stream).arrayBuffer();
|
|
670
|
+
return new Uint8Array(ab);
|
|
671
|
+
} catch {
|
|
672
|
+
return null;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
async function readZipArchiveEntries(zipBytes) {
|
|
676
|
+
const entries = /* @__PURE__ */ new Map();
|
|
677
|
+
if (zipBytes.length < 22) return entries;
|
|
678
|
+
const view = new DataView(zipBytes.buffer, zipBytes.byteOffset, zipBytes.byteLength);
|
|
679
|
+
const decoder = new TextDecoder("utf-8", { fatal: false });
|
|
680
|
+
let eocdOffset = -1;
|
|
681
|
+
const minSearch = Math.max(0, zipBytes.length - 65557);
|
|
682
|
+
for (let pos = zipBytes.length - 22; pos >= minSearch; pos -= 1) {
|
|
683
|
+
if (view.getUint32(pos, true) === 101010256) {
|
|
684
|
+
eocdOffset = pos;
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (eocdOffset >= 0) {
|
|
689
|
+
const totalRecords = view.getUint16(eocdOffset + 10, true);
|
|
690
|
+
const centralDirOffset = view.getUint32(eocdOffset + 16, true);
|
|
691
|
+
let cursor = centralDirOffset;
|
|
692
|
+
for (let i = 0; i < totalRecords && cursor + 46 <= zipBytes.length; i += 1) {
|
|
693
|
+
if (view.getUint32(cursor, true) !== 33639248) break;
|
|
694
|
+
const compressionMethod = view.getUint16(cursor + 10, true);
|
|
695
|
+
const compressedSize = view.getUint32(cursor + 20, true);
|
|
696
|
+
const fileNameLen = view.getUint16(cursor + 28, true);
|
|
697
|
+
const extraLen = view.getUint16(cursor + 30, true);
|
|
698
|
+
const commentLen = view.getUint16(cursor + 32, true);
|
|
699
|
+
const localHeaderOffset = view.getUint32(cursor + 42, true);
|
|
700
|
+
const rawName = decoder.decode(zipBytes.subarray(cursor + 46, cursor + 46 + fileNameLen));
|
|
701
|
+
const cleanName = rawName.replace(/^\/+/, "");
|
|
702
|
+
cursor += 46 + fileNameLen + extraLen + commentLen;
|
|
703
|
+
if (!cleanName || cleanName.endsWith("/") || localHeaderOffset + 30 > zipBytes.length || view.getUint32(localHeaderOffset, true) !== 67324752) {
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
const localNameLen = view.getUint16(localHeaderOffset + 26, true);
|
|
707
|
+
const localExtraLen = view.getUint16(localHeaderOffset + 28, true);
|
|
708
|
+
const dataStart = localHeaderOffset + 30 + localNameLen + localExtraLen;
|
|
709
|
+
if (dataStart + compressedSize > zipBytes.length) continue;
|
|
710
|
+
const rawSlice = zipBytes.subarray(dataStart, dataStart + compressedSize);
|
|
711
|
+
if (compressionMethod === 0) {
|
|
712
|
+
entries.set(cleanName, rawSlice);
|
|
713
|
+
} else if (compressionMethod === 8) {
|
|
714
|
+
const inflated = await decompressBytesIfSupported(rawSlice, "deflate-raw");
|
|
715
|
+
if (inflated) {
|
|
716
|
+
entries.set(cleanName, inflated);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return entries;
|
|
721
|
+
}
|
|
722
|
+
let offset = 0;
|
|
723
|
+
while (offset + 30 <= zipBytes.length) {
|
|
724
|
+
if (view.getUint32(offset, true) !== 67324752) break;
|
|
725
|
+
const method = view.getUint16(offset + 8, true);
|
|
726
|
+
const compSize = view.getUint32(offset + 18, true);
|
|
727
|
+
const nameLen = view.getUint16(offset + 26, true);
|
|
728
|
+
const extraLen = view.getUint16(offset + 28, true);
|
|
729
|
+
const name = decoder.decode(zipBytes.subarray(offset + 30, offset + 30 + nameLen)).replace(/^\/+/, "");
|
|
730
|
+
const dataStart = offset + 30 + nameLen + extraLen;
|
|
731
|
+
if (dataStart + compSize > zipBytes.length) break;
|
|
732
|
+
const slice = zipBytes.subarray(dataStart, dataStart + compSize);
|
|
733
|
+
if (name && !name.endsWith("/")) {
|
|
734
|
+
if (method === 0) {
|
|
735
|
+
entries.set(name, slice);
|
|
736
|
+
} else if (method === 8) {
|
|
737
|
+
const inflated = await decompressBytesIfSupported(slice, "deflate-raw");
|
|
738
|
+
if (inflated) entries.set(name, inflated);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
offset = dataStart + compSize;
|
|
742
|
+
}
|
|
743
|
+
return entries;
|
|
744
|
+
}
|
|
745
|
+
function findXmlBlocks(xml, tagName) {
|
|
746
|
+
const results = [];
|
|
747
|
+
const openToken = `<${tagName}`;
|
|
748
|
+
const closeToken = `</${tagName}>`;
|
|
749
|
+
let searchFrom = 0;
|
|
750
|
+
while (searchFrom < xml.length) {
|
|
751
|
+
const idx = xml.indexOf(openToken, searchFrom);
|
|
752
|
+
if (idx === -1) break;
|
|
753
|
+
const nextCh = xml[idx + openToken.length];
|
|
754
|
+
const isTagBoundary = nextCh === ">" || nextCh === "/" || nextCh === " " || nextCh === " " || nextCh === "\r" || nextCh === "\n";
|
|
755
|
+
if (!isTagBoundary) {
|
|
756
|
+
searchFrom = idx + openToken.length;
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
const openTagEnd = xml.indexOf(">", idx + openToken.length);
|
|
760
|
+
if (openTagEnd === -1) break;
|
|
761
|
+
if (xml[openTagEnd - 1] === "/") {
|
|
762
|
+
results.push(xml.slice(idx, openTagEnd + 1));
|
|
763
|
+
searchFrom = openTagEnd + 1;
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
let depth = 1;
|
|
767
|
+
let cursor = openTagEnd + 1;
|
|
768
|
+
while (depth > 0 && cursor < xml.length) {
|
|
769
|
+
const nextOpen = xml.indexOf(openToken, cursor);
|
|
770
|
+
const nextClose = xml.indexOf(closeToken, cursor);
|
|
771
|
+
if (nextClose === -1) {
|
|
772
|
+
cursor = xml.length;
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
if (nextOpen !== -1 && nextOpen < nextClose) {
|
|
776
|
+
const ch = xml[nextOpen + openToken.length];
|
|
777
|
+
if (ch === ">" || ch === "/" || ch === " " || ch === " " || ch === "\r" || ch === "\n") {
|
|
778
|
+
const subEnd = xml.indexOf(">", nextOpen + openToken.length);
|
|
779
|
+
if (subEnd !== -1 && xml[subEnd - 1] !== "/") {
|
|
780
|
+
depth += 1;
|
|
781
|
+
}
|
|
782
|
+
cursor = subEnd !== -1 ? subEnd + 1 : nextOpen + openToken.length;
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
cursor = nextOpen + openToken.length;
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
788
|
+
depth -= 1;
|
|
789
|
+
cursor = nextClose + closeToken.length;
|
|
790
|
+
}
|
|
791
|
+
results.push(xml.slice(idx, cursor));
|
|
792
|
+
searchFrom = cursor;
|
|
793
|
+
}
|
|
794
|
+
return results;
|
|
795
|
+
}
|
|
796
|
+
function resolveOpcPath(baseDir, target) {
|
|
797
|
+
const clean = target.trim();
|
|
798
|
+
if (clean.startsWith("/")) {
|
|
799
|
+
return clean.replace(/^\/+/, "");
|
|
800
|
+
}
|
|
801
|
+
const parts = [...baseDir.split("/").filter(Boolean), ...clean.split("/").filter(Boolean)];
|
|
802
|
+
const stack = [];
|
|
803
|
+
for (const seg of parts) {
|
|
804
|
+
if (seg === ".") continue;
|
|
805
|
+
if (seg === "..") {
|
|
806
|
+
stack.pop();
|
|
807
|
+
} else {
|
|
808
|
+
stack.push(seg);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return stack.join("/");
|
|
812
|
+
}
|
|
813
|
+
function parseRelationshipsMap(relsXml, baseDir) {
|
|
814
|
+
const map = /* @__PURE__ */ new Map();
|
|
815
|
+
const relRegex = /<Relationship\b[^>]*>/g;
|
|
816
|
+
let match;
|
|
817
|
+
while ((match = relRegex.exec(relsXml)) !== null) {
|
|
818
|
+
const tag = match[0];
|
|
819
|
+
const idMatch = /\bId="([^"]+)"/.exec(tag);
|
|
820
|
+
const targetMatch = /\bTarget="([^"]+)"/.exec(tag);
|
|
821
|
+
if (idMatch && targetMatch) {
|
|
822
|
+
map.set(idMatch[1], resolveOpcPath(baseDir, targetMatch[1]));
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
return map;
|
|
826
|
+
}
|
|
827
|
+
function mapPresetGeomToBoardShape(prst) {
|
|
828
|
+
switch (prst) {
|
|
829
|
+
case "roundRect":
|
|
830
|
+
case "foldedCorner":
|
|
831
|
+
return "roundRect";
|
|
832
|
+
case "ellipse":
|
|
833
|
+
return "ellipse";
|
|
834
|
+
case "diamond":
|
|
835
|
+
case "flowChartDecision":
|
|
836
|
+
return "diamond";
|
|
837
|
+
case "parallelogram":
|
|
838
|
+
case "flowChartInputOutput":
|
|
839
|
+
return "parallelogram";
|
|
840
|
+
case "can":
|
|
841
|
+
case "flowChartMagneticDisk":
|
|
842
|
+
return "cylinder";
|
|
843
|
+
case "hexagon":
|
|
844
|
+
case "flowChartPreparation":
|
|
845
|
+
return "hexagon";
|
|
846
|
+
case "cloud":
|
|
847
|
+
return "cloud";
|
|
848
|
+
case "flowChartDocument":
|
|
849
|
+
return "document";
|
|
850
|
+
case "wedgeRectCallout":
|
|
851
|
+
case "wedgeRoundRectCallout":
|
|
852
|
+
return "callout";
|
|
853
|
+
default:
|
|
854
|
+
return "rect";
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
function extractXfrmBox(xmlBlock) {
|
|
858
|
+
const xfrmMatch = /<(?:a|p):xfrm\b([^>]*)>([\s\S]*?)<\/(?:a|p):xfrm>/.exec(xmlBlock);
|
|
859
|
+
if (!xfrmMatch) return null;
|
|
860
|
+
const attrs = xfrmMatch[1] ?? "";
|
|
861
|
+
const inner = xfrmMatch[2] ?? "";
|
|
862
|
+
const offMatch = /<a:off\b[^>]*\bx="(-?\d+)"[^>]*\by="(-?\d+)"/.exec(inner);
|
|
863
|
+
const extMatch = /<a:ext\b[^>]*\bcx="(-?\d+)"[^>]*\bcy="(-?\d+)"/.exec(inner);
|
|
864
|
+
if (!offMatch || !extMatch) return null;
|
|
865
|
+
return {
|
|
866
|
+
xEmu: Number(offMatch[1]),
|
|
867
|
+
yEmu: Number(offMatch[2]),
|
|
868
|
+
cxEmu: Math.max(0, Number(extMatch[1])),
|
|
869
|
+
cyEmu: Math.max(0, Number(extMatch[2])),
|
|
870
|
+
flipH: /\bflipH="1"|\bflipH="true"/.test(attrs),
|
|
871
|
+
flipV: /\bflipV="1"|\bflipV="true"/.test(attrs)
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
function extractParagraphText(xmlBlock) {
|
|
875
|
+
const paragraphs = findXmlBlocks(xmlBlock, "a:p");
|
|
876
|
+
if (paragraphs.length === 0) {
|
|
877
|
+
const runs = [];
|
|
878
|
+
const tRegex = /<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/g;
|
|
879
|
+
let m;
|
|
880
|
+
while ((m = tRegex.exec(xmlBlock)) !== null) {
|
|
881
|
+
runs.push(unescapeXml(m[1]));
|
|
882
|
+
}
|
|
883
|
+
return runs.join("").trim();
|
|
884
|
+
}
|
|
885
|
+
const lines = [];
|
|
886
|
+
for (const pXml of paragraphs) {
|
|
887
|
+
const runs = [];
|
|
888
|
+
const tRegex = /<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/g;
|
|
889
|
+
let m;
|
|
890
|
+
while ((m = tRegex.exec(pXml)) !== null) {
|
|
891
|
+
runs.push(unescapeXml(m[1]));
|
|
892
|
+
}
|
|
893
|
+
lines.push(runs.join(""));
|
|
894
|
+
}
|
|
895
|
+
return lines.join("\n").trim();
|
|
896
|
+
}
|
|
897
|
+
function resolveMediaMimeType(path) {
|
|
898
|
+
const lower = path.toLowerCase();
|
|
899
|
+
if (lower.endsWith(".svg")) return "image/svg+xml";
|
|
900
|
+
if (lower.endsWith(".jpg") || lower.endsWith(".jpeg")) return "image/jpeg";
|
|
901
|
+
if (lower.endsWith(".gif")) return "image/gif";
|
|
902
|
+
if (lower.endsWith(".webp")) return "image/webp";
|
|
903
|
+
return "image/png";
|
|
904
|
+
}
|
|
905
|
+
async function importPptxBytesToBoardElements(pptxBytes, options) {
|
|
906
|
+
const zipEntries = await readZipArchiveEntries(pptxBytes);
|
|
907
|
+
if (zipEntries.size === 0) return [];
|
|
908
|
+
const decoder = new TextDecoder("utf-8", { fatal: false });
|
|
909
|
+
const getTextEntry = (name) => {
|
|
910
|
+
const bytes = zipEntries.get(name);
|
|
911
|
+
return bytes ? decoder.decode(bytes) : void 0;
|
|
912
|
+
};
|
|
913
|
+
let slideWidthEmu = 12192e3;
|
|
914
|
+
let slideHeightEmu = 6858e3;
|
|
915
|
+
const orderedSlidePaths = [];
|
|
916
|
+
const presXml = getTextEntry("ppt/presentation.xml");
|
|
917
|
+
const presRelsXml = getTextEntry("ppt/_rels/presentation.xml.rels");
|
|
918
|
+
if (presXml) {
|
|
919
|
+
const szMatch = /<p:sldSz\b[^>]*\bcx="(\d+)"[^>]*\bcy="(\d+)"/.exec(presXml);
|
|
920
|
+
if (szMatch) {
|
|
921
|
+
slideWidthEmu = Math.max(914400, Number(szMatch[1]));
|
|
922
|
+
slideHeightEmu = Math.max(914400, Number(szMatch[2]));
|
|
923
|
+
}
|
|
924
|
+
if (presRelsXml) {
|
|
925
|
+
const presRels = parseRelationshipsMap(presRelsXml, "ppt");
|
|
926
|
+
const sldIdRegex = /<p:sldId\b[^>]*\br:id="([^"]+)"/g;
|
|
927
|
+
let sldMatch;
|
|
928
|
+
while ((sldMatch = sldIdRegex.exec(presXml)) !== null) {
|
|
929
|
+
const targetPath = presRels.get(sldMatch[1]);
|
|
930
|
+
if (targetPath && zipEntries.has(targetPath)) {
|
|
931
|
+
orderedSlidePaths.push(targetPath);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
if (orderedSlidePaths.length === 0) {
|
|
937
|
+
const fallbackSlides = Array.from(zipEntries.keys()).filter((k) => /^ppt\/slides\/slide\d+\.xml$/i.test(k)).sort((a, b) => {
|
|
938
|
+
const na = Number(/slide(\d+)\.xml/i.exec(a)?.[1] ?? 0);
|
|
939
|
+
const nb = Number(/slide(\d+)\.xml/i.exec(b)?.[1] ?? 0);
|
|
940
|
+
return na - nb;
|
|
941
|
+
});
|
|
942
|
+
orderedSlidePaths.push(...fallbackSlides);
|
|
943
|
+
}
|
|
944
|
+
if (orderedSlidePaths.length === 0) return [];
|
|
945
|
+
const originX = options?.originX ?? 80;
|
|
946
|
+
const originY = options?.originY ?? 80;
|
|
947
|
+
const columns = Math.max(1, options?.columns ?? (orderedSlidePaths.length <= 2 ? orderedSlidePaths.length : 2));
|
|
948
|
+
const gapX = options?.gapX ?? 64;
|
|
949
|
+
const gapY = options?.gapY ?? 64;
|
|
950
|
+
const frameW = options?.frameWidth ?? 780;
|
|
951
|
+
const headerH = 44;
|
|
952
|
+
const pad = 20;
|
|
953
|
+
const innerW = frameW - pad * 2;
|
|
954
|
+
const innerH = Math.max(240, Math.round(innerW * (slideHeightEmu / slideWidthEmu)));
|
|
955
|
+
const frameH = headerH + innerH + pad;
|
|
956
|
+
const frames = [];
|
|
957
|
+
const childElements = [];
|
|
958
|
+
orderedSlidePaths.forEach((slidePath, slideIdx) => {
|
|
959
|
+
const slideXml = getTextEntry(slidePath);
|
|
960
|
+
if (!slideXml) return;
|
|
961
|
+
const slideFileName = slidePath.split("/").pop() ?? `slide${slideIdx + 1}.xml`;
|
|
962
|
+
const slideDir = slidePath.slice(0, Math.max(0, slidePath.lastIndexOf("/")));
|
|
963
|
+
const slideRelsPath = `${slideDir}/_rels/${slideFileName}.rels`;
|
|
964
|
+
const slideRels = zipEntries.has(slideRelsPath) ? parseRelationshipsMap(getTextEntry(slideRelsPath) ?? "", slideDir) : /* @__PURE__ */ new Map();
|
|
965
|
+
const col = slideIdx % columns;
|
|
966
|
+
const row = Math.floor(slideIdx / columns);
|
|
967
|
+
const fx = originX + col * (frameW + gapX);
|
|
968
|
+
const fy = originY + row * (frameH + gapY);
|
|
969
|
+
const frameId = `frame-pptx-${slideIdx + 1}-${generateRandomId2(5)}`;
|
|
970
|
+
const toBoardX = (xEmu) => Math.round(fx + pad + Math.max(0, xEmu) / slideWidthEmu * innerW);
|
|
971
|
+
const toBoardY = (yEmu) => Math.round(fy + headerH + Math.max(0, yEmu) / slideHeightEmu * innerH);
|
|
972
|
+
const toBoardW = (wEmu) => Math.max(32, Math.round(Math.max(12700, wEmu) / slideWidthEmu * innerW));
|
|
973
|
+
const toBoardH = (hEmu) => Math.max(24, Math.round(Math.max(12700, hEmu) / slideHeightEmu * innerH));
|
|
974
|
+
let slideTitle = "";
|
|
975
|
+
const slideChildren = [];
|
|
976
|
+
const spBlocks = findXmlBlocks(slideXml, "p:sp");
|
|
977
|
+
spBlocks.forEach((spXml, spIdx) => {
|
|
978
|
+
const cNvPrMatch = /<p:cNvPr\b[^>]*\bname="([^"]*)"/.exec(spXml);
|
|
979
|
+
const spName = cNvPrMatch ? unescapeXml(cNvPrMatch[1]) : "";
|
|
980
|
+
const isTitlePlaceholder = /<p:ph\b[^>]*\btype="(?:title|ctrTitle)"/.test(spXml);
|
|
981
|
+
const text = extractParagraphText(spXml);
|
|
982
|
+
if (spName === "Slide Frame Title" && text) {
|
|
983
|
+
slideTitle = text;
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
if (!slideTitle && isTitlePlaceholder && text) {
|
|
987
|
+
slideTitle = text;
|
|
988
|
+
}
|
|
989
|
+
const xfrm = extractXfrmBox(spXml);
|
|
990
|
+
const bx = xfrm ? toBoardX(xfrm.xEmu) : fx + pad + spIdx % 3 * 180;
|
|
991
|
+
const by = xfrm ? toBoardY(xfrm.yEmu) : fy + headerH + 24 + Math.floor(spIdx / 3) * 80;
|
|
992
|
+
const bw = xfrm ? toBoardW(xfrm.cxEmu) : 160;
|
|
993
|
+
const bh = xfrm ? toBoardH(xfrm.cyEmu) : 56;
|
|
994
|
+
const spPrBlock = findXmlBlocks(spXml, "p:spPr")[0] ?? "";
|
|
995
|
+
const lnBlock = findXmlBlocks(spPrBlock, "a:ln")[0] ?? "";
|
|
996
|
+
const spPrWithoutLn = lnBlock ? spPrBlock.replace(lnBlock, "") : spPrBlock;
|
|
997
|
+
const hasNoFill = /<a:noFill\s*\/>/.test(spPrWithoutLn);
|
|
998
|
+
const fillClrMatch = /<a:srgbClr\b[^>]*\bval="([0-9a-fA-F]{6})"/.exec(spPrWithoutLn);
|
|
999
|
+
const lnNoFill = !lnBlock || /<a:noFill\s*\/>/.test(lnBlock);
|
|
1000
|
+
const strokeClrMatch = /<a:srgbClr\b[^>]*\bval="([0-9a-fA-F]{6})"/.exec(lnBlock);
|
|
1001
|
+
const isTxBox = /<p:cNvSpPr\b[^>]*\btxBox="1"/.test(spXml);
|
|
1002
|
+
const txBodyBlock = findXmlBlocks(spXml, "p:txBody")[0] ?? "";
|
|
1003
|
+
const textClrMatch = /<a:srgbClr\b[^>]*\bval="([0-9a-fA-F]{6})"/.exec(txBodyBlock);
|
|
1004
|
+
const szMatch = /\bsz="(\d+)"/.exec(txBodyBlock);
|
|
1005
|
+
const fontSize = szMatch ? Math.max(10, Math.min(28, Math.round(Number(szMatch[1]) / 100))) : 13;
|
|
1006
|
+
const isBold = /\bb="1"|\bb="true"/.test(txBodyBlock);
|
|
1007
|
+
const algnMatch = /\balgn="(l|ctr|r)"/.exec(txBodyBlock);
|
|
1008
|
+
const align = algnMatch?.[1] === "ctr" ? "center" : algnMatch?.[1] === "r" ? "right" : "left";
|
|
1009
|
+
if ((hasNoFill || !fillClrMatch && isTxBox) && (lnNoFill || !strokeClrMatch)) {
|
|
1010
|
+
if (!text) return;
|
|
1011
|
+
const textEl = {
|
|
1012
|
+
id: `pptx-text-${slideIdx + 1}-${spIdx + 1}-${generateRandomId2(4)}`,
|
|
1013
|
+
type: "text",
|
|
1014
|
+
text,
|
|
1015
|
+
fontSize,
|
|
1016
|
+
fontWeight: isBold ? "bold" : "normal",
|
|
1017
|
+
color: textClrMatch ? `#${textClrMatch[1].toUpperCase()}` : "#0F172A",
|
|
1018
|
+
align,
|
|
1019
|
+
x: bx,
|
|
1020
|
+
y: by,
|
|
1021
|
+
width: bw,
|
|
1022
|
+
height: bh,
|
|
1023
|
+
frameId
|
|
1024
|
+
};
|
|
1025
|
+
slideChildren.push(textEl);
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
const prstMatch = /<a:prstGeom\b[^>]*\bprst="([^"]+)"/.exec(spPrBlock);
|
|
1029
|
+
const shapeType = mapPresetGeomToBoardShape(prstMatch?.[1]);
|
|
1030
|
+
const lnWMatch = /<a:ln\b[^>]*\bw="(\d+)"/.exec(lnBlock);
|
|
1031
|
+
const strokeWidth = lnWMatch ? Math.max(1, Math.min(6, Math.round(Number(lnWMatch[1]) / 12700))) : 1.5;
|
|
1032
|
+
const dashed = /<a:prstDash\b[^>]*\bval="(?:dash|sysDash|lgDash)"/.test(lnBlock);
|
|
1033
|
+
const shapeEl = {
|
|
1034
|
+
id: `pptx-shape-${slideIdx + 1}-${spIdx + 1}-${generateRandomId2(4)}`,
|
|
1035
|
+
type: "shape",
|
|
1036
|
+
shapeType,
|
|
1037
|
+
text: text || spName || "",
|
|
1038
|
+
fill: fillClrMatch ? `#${fillClrMatch[1].toUpperCase()}` : "#EFF6FF",
|
|
1039
|
+
stroke: strokeClrMatch ? `#${strokeClrMatch[1].toUpperCase()}` : "#2563EB",
|
|
1040
|
+
strokeWidth,
|
|
1041
|
+
textColor: textClrMatch ? `#${textClrMatch[1].toUpperCase()}` : "#1E293B",
|
|
1042
|
+
...dashed ? { dashed: true } : {},
|
|
1043
|
+
fontSize,
|
|
1044
|
+
x: bx,
|
|
1045
|
+
y: by,
|
|
1046
|
+
width: bw,
|
|
1047
|
+
height: bh,
|
|
1048
|
+
frameId
|
|
1049
|
+
};
|
|
1050
|
+
slideChildren.push(shapeEl);
|
|
1051
|
+
});
|
|
1052
|
+
const graphicFrames = findXmlBlocks(slideXml, "p:graphicFrame");
|
|
1053
|
+
graphicFrames.forEach((gfXml, gfIdx) => {
|
|
1054
|
+
const tblBlock = findXmlBlocks(gfXml, "a:tbl")[0];
|
|
1055
|
+
if (!tblBlock) return;
|
|
1056
|
+
const trBlocks = findXmlBlocks(tblBlock, "a:tr");
|
|
1057
|
+
const parsedRows = trBlocks.map(
|
|
1058
|
+
(trXml) => findXmlBlocks(trXml, "a:tc").map((tcXml) => extractParagraphText(tcXml))
|
|
1059
|
+
);
|
|
1060
|
+
if (parsedRows.length === 0) return;
|
|
1061
|
+
const xfrm = extractXfrmBox(gfXml);
|
|
1062
|
+
const cNvPrMatch = /<p:cNvPr\b[^>]*\bname="([^"]*)"/.exec(gfXml);
|
|
1063
|
+
const tblTitle = cNvPrMatch ? unescapeXml(cNvPrMatch[1]) : void 0;
|
|
1064
|
+
const headers = parsedRows[0];
|
|
1065
|
+
const rows = parsedRows.slice(1);
|
|
1066
|
+
const tableEl = {
|
|
1067
|
+
id: `pptx-table-${slideIdx + 1}-${gfIdx + 1}-${generateRandomId2(4)}`,
|
|
1068
|
+
type: "table",
|
|
1069
|
+
...tblTitle ? { title: tblTitle } : {},
|
|
1070
|
+
headers: headers.length > 0 ? headers : ["\u5217 1"],
|
|
1071
|
+
rows,
|
|
1072
|
+
headerFill: "#EFF6FF",
|
|
1073
|
+
borderColor: "#CBD5E1",
|
|
1074
|
+
x: xfrm ? toBoardX(xfrm.xEmu) : fx + pad + 24,
|
|
1075
|
+
y: xfrm ? toBoardY(xfrm.yEmu) : fy + headerH + 40,
|
|
1076
|
+
width: xfrm ? toBoardW(xfrm.cxEmu) : 360,
|
|
1077
|
+
height: xfrm ? toBoardH(xfrm.cyEmu) : 160,
|
|
1078
|
+
frameId
|
|
1079
|
+
};
|
|
1080
|
+
slideChildren.push(tableEl);
|
|
1081
|
+
});
|
|
1082
|
+
const picBlocks = findXmlBlocks(slideXml, "p:pic");
|
|
1083
|
+
picBlocks.forEach((picXml, picIdx) => {
|
|
1084
|
+
const embedMatch = /<a:blip\b[^>]*\br:embed="([^"]+)"/.exec(picXml);
|
|
1085
|
+
const mediaPath = embedMatch ? slideRels.get(embedMatch[1]) : void 0;
|
|
1086
|
+
const mediaBytes = mediaPath ? zipEntries.get(mediaPath) : void 0;
|
|
1087
|
+
let srcDataUrl = 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="240" height="160" viewBox="0 0 240 160"><rect width="240" height="160" rx="10" fill="%23EFF6FF"/><text x="120" y="86" text-anchor="middle" font-size="13" fill="%231D4ED8">PPTX Media</text></svg>';
|
|
1088
|
+
if (mediaPath && mediaBytes && mediaBytes.length > 0) {
|
|
1089
|
+
const mime = resolveMediaMimeType(mediaPath);
|
|
1090
|
+
srcDataUrl = `data:${mime};base64,${uint8ToBase64(mediaBytes)}`;
|
|
1091
|
+
}
|
|
1092
|
+
const xfrm = extractXfrmBox(picXml);
|
|
1093
|
+
const cNvPrMatch = /<p:cNvPr\b[^>]*\b(?:descr|name)="([^"]*)"/.exec(picXml);
|
|
1094
|
+
const caption = cNvPrMatch ? unescapeXml(cNvPrMatch[1]) : mediaPath?.split("/").pop();
|
|
1095
|
+
const imageEl = {
|
|
1096
|
+
id: `pptx-image-${slideIdx + 1}-${picIdx + 1}-${generateRandomId2(4)}`,
|
|
1097
|
+
type: "image",
|
|
1098
|
+
src: srcDataUrl,
|
|
1099
|
+
...caption ? { caption } : {},
|
|
1100
|
+
fit: "contain",
|
|
1101
|
+
x: xfrm ? toBoardX(xfrm.xEmu) : fx + pad + 40,
|
|
1102
|
+
y: xfrm ? toBoardY(xfrm.yEmu) : fy + headerH + 40,
|
|
1103
|
+
width: xfrm ? toBoardW(xfrm.cxEmu) : 240,
|
|
1104
|
+
height: xfrm ? toBoardH(xfrm.cyEmu) : 160,
|
|
1105
|
+
frameId
|
|
1106
|
+
};
|
|
1107
|
+
slideChildren.push(imageEl);
|
|
1108
|
+
});
|
|
1109
|
+
const cxnBlocks = findXmlBlocks(slideXml, "p:cxnSp");
|
|
1110
|
+
cxnBlocks.forEach((cxnXml, cxnIdx) => {
|
|
1111
|
+
const xfrm = extractXfrmBox(cxnXml);
|
|
1112
|
+
if (!xfrm) return;
|
|
1113
|
+
const xLeft = toBoardX(xfrm.xEmu);
|
|
1114
|
+
const yTop = toBoardY(xfrm.yEmu);
|
|
1115
|
+
const w = Math.max(4, Math.round(xfrm.cxEmu / slideWidthEmu * innerW));
|
|
1116
|
+
const h = Math.max(4, Math.round(xfrm.cyEmu / slideHeightEmu * innerH));
|
|
1117
|
+
const x1 = xfrm.flipH ? xLeft + w : xLeft;
|
|
1118
|
+
const x2 = xfrm.flipH ? xLeft : xLeft + w;
|
|
1119
|
+
const y1 = xfrm.flipV ? yTop + h : yTop;
|
|
1120
|
+
const y2 = xfrm.flipV ? yTop : yTop + h;
|
|
1121
|
+
const lnBlock = findXmlBlocks(cxnXml, "a:ln")[0] ?? "";
|
|
1122
|
+
const strokeMatch = /<a:srgbClr\b[^>]*\bval="([0-9a-fA-F]{6})"/.exec(lnBlock);
|
|
1123
|
+
const dashed = /<a:prstDash\b[^>]*\bval="(?:dash|sysDash|lgDash)"/.test(lnBlock);
|
|
1124
|
+
const hasStart = /<a:headEnd\b[^>]*\btype="(?!none)[^"]+"/.test(lnBlock);
|
|
1125
|
+
const hasEnd = /<a:tailEnd\b[^>]*\btype="(?!none)[^"]+"/.test(lnBlock);
|
|
1126
|
+
const isStraight = /<a:prstGeom\b[^>]*\bprst="straightConnector1"/.test(cxnXml);
|
|
1127
|
+
const connEl = {
|
|
1128
|
+
id: `pptx-conn-${slideIdx + 1}-${cxnIdx + 1}-${generateRandomId2(4)}`,
|
|
1129
|
+
type: "connector",
|
|
1130
|
+
routeType: isStraight ? "straight" : "orthogonal",
|
|
1131
|
+
from: { x: x1, y: y1 },
|
|
1132
|
+
to: { x: x2, y: y2 },
|
|
1133
|
+
stroke: strokeMatch ? `#${strokeMatch[1].toUpperCase()}` : "#475569",
|
|
1134
|
+
strokeWidth: 2,
|
|
1135
|
+
dashed,
|
|
1136
|
+
startMarker: hasStart ? "arrow" : "none",
|
|
1137
|
+
endMarker: hasEnd ? "arrow" : "none",
|
|
1138
|
+
x: Math.min(x1, x2),
|
|
1139
|
+
y: Math.min(y1, y2),
|
|
1140
|
+
width: Math.max(8, Math.abs(x2 - x1)),
|
|
1141
|
+
height: Math.max(8, Math.abs(y2 - y1)),
|
|
1142
|
+
frameId
|
|
1143
|
+
};
|
|
1144
|
+
slideChildren.push(connEl);
|
|
1145
|
+
});
|
|
1146
|
+
if (!slideTitle) {
|
|
1147
|
+
const firstTextChild = slideChildren.find(
|
|
1148
|
+
(c) => (c.type === "shape" || c.type === "text") && Boolean(c.text.trim())
|
|
1149
|
+
);
|
|
1150
|
+
slideTitle = firstTextChild ? firstTextChild.text.split(/\r?\n/)[0].slice(0, 36) : `\u5E7B\u706F\u7247 ${slideIdx + 1}`;
|
|
1151
|
+
}
|
|
1152
|
+
const strippedTitle = slideTitle.replace(/^\d+\s*[·.-]\s*/, "").trim() || `\u5E7B\u706F\u7247 ${slideIdx + 1}`;
|
|
1153
|
+
const numPrefix = String(slideIdx + 1).padStart(2, "0");
|
|
1154
|
+
frames.push({
|
|
1155
|
+
id: frameId,
|
|
1156
|
+
type: "frame",
|
|
1157
|
+
title: `${numPrefix} \xB7 ${strippedTitle}`,
|
|
1158
|
+
x: fx,
|
|
1159
|
+
y: fy,
|
|
1160
|
+
width: frameW,
|
|
1161
|
+
height: frameH,
|
|
1162
|
+
backgroundColor: "#FFFFFF",
|
|
1163
|
+
borderColor: "#93C5FD",
|
|
1164
|
+
metadata: {
|
|
1165
|
+
importedFrom: "pptx",
|
|
1166
|
+
slideIndex: slideIdx + 1
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
childElements.push(...slideChildren);
|
|
1170
|
+
});
|
|
1171
|
+
return [...frames, ...childElements];
|
|
1172
|
+
}
|
|
1173
|
+
function decodePdfLiteralString(raw) {
|
|
1174
|
+
let out = "";
|
|
1175
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
1176
|
+
const ch = raw[i];
|
|
1177
|
+
if (ch !== "\\") {
|
|
1178
|
+
out += ch;
|
|
1179
|
+
continue;
|
|
1180
|
+
}
|
|
1181
|
+
i += 1;
|
|
1182
|
+
if (i >= raw.length) break;
|
|
1183
|
+
const next = raw[i];
|
|
1184
|
+
if (next === "n") out += "\n";
|
|
1185
|
+
else if (next === "r") out += "\r";
|
|
1186
|
+
else if (next === "t") out += " ";
|
|
1187
|
+
else if (next >= "0" && next <= "7") {
|
|
1188
|
+
let oct = next;
|
|
1189
|
+
if (i + 1 < raw.length && raw[i + 1] >= "0" && raw[i + 1] <= "7") {
|
|
1190
|
+
oct += raw[++i];
|
|
1191
|
+
if (i + 1 < raw.length && raw[i + 1] >= "0" && raw[i + 1] <= "7") {
|
|
1192
|
+
oct += raw[++i];
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
out += String.fromCharCode(parseInt(oct, 8));
|
|
1196
|
+
} else {
|
|
1197
|
+
out += next;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return out;
|
|
1201
|
+
}
|
|
1202
|
+
function decodePdfHexString(hexRaw) {
|
|
1203
|
+
const clean = hexRaw.replace(/\s+/g, "");
|
|
1204
|
+
if (clean.length === 0) return "";
|
|
1205
|
+
const padded = clean.length % 2 === 1 ? `${clean}0` : clean;
|
|
1206
|
+
if (padded.length >= 4 && padded.slice(0, 4).toUpperCase() === "FEFF") {
|
|
1207
|
+
let text2 = "";
|
|
1208
|
+
for (let i = 4; i + 3 < padded.length; i += 4) {
|
|
1209
|
+
const code = parseInt(padded.slice(i, i + 4), 16);
|
|
1210
|
+
if (code >= 32) text2 += String.fromCharCode(code);
|
|
1211
|
+
}
|
|
1212
|
+
return text2;
|
|
1213
|
+
}
|
|
1214
|
+
let text = "";
|
|
1215
|
+
for (let i = 0; i + 1 < padded.length; i += 2) {
|
|
1216
|
+
const byte = parseInt(padded.slice(i, i + 2), 16);
|
|
1217
|
+
if (byte >= 32 && byte <= 126) {
|
|
1218
|
+
text += String.fromCharCode(byte);
|
|
1219
|
+
} else if (byte >= 160 && byte <= 255) {
|
|
1220
|
+
text += String.fromCharCode(byte);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
return text;
|
|
1224
|
+
}
|
|
1225
|
+
function parsePdfContentStreamText(streamText) {
|
|
1226
|
+
const lines = [];
|
|
1227
|
+
const btRegex = /\bBT\b([\s\S]*?)\bET\b/g;
|
|
1228
|
+
const targetChunks = [];
|
|
1229
|
+
let btMatch;
|
|
1230
|
+
while ((btMatch = btRegex.exec(streamText)) !== null) {
|
|
1231
|
+
targetChunks.push(btMatch[1]);
|
|
1232
|
+
}
|
|
1233
|
+
if (targetChunks.length === 0) {
|
|
1234
|
+
targetChunks.push(streamText);
|
|
1235
|
+
}
|
|
1236
|
+
for (const chunk of targetChunks) {
|
|
1237
|
+
const opRegex = /\(((?:\\.|[^\\()])*)\)\s*Tj|<([0-9a-fA-F\s]+)>\s*Tj|\[((?:[\s\S]*?))\]\s*TJ/g;
|
|
1238
|
+
let m;
|
|
1239
|
+
while ((m = opRegex.exec(chunk)) !== null) {
|
|
1240
|
+
let extracted = "";
|
|
1241
|
+
if (m[1] !== void 0) {
|
|
1242
|
+
extracted = decodePdfLiteralString(m[1]);
|
|
1243
|
+
} else if (m[2] !== void 0) {
|
|
1244
|
+
extracted = decodePdfHexString(m[2]);
|
|
1245
|
+
} else if (m[3] !== void 0) {
|
|
1246
|
+
const arrBody = m[3];
|
|
1247
|
+
const parts = [];
|
|
1248
|
+
const subRegex = /\(((?:\\.|[^\\()])*)\)|<([0-9a-fA-F\s]+)>/g;
|
|
1249
|
+
let sm;
|
|
1250
|
+
while ((sm = subRegex.exec(arrBody)) !== null) {
|
|
1251
|
+
if (sm[1] !== void 0) parts.push(decodePdfLiteralString(sm[1]));
|
|
1252
|
+
else if (sm[2] !== void 0) parts.push(decodePdfHexString(sm[2]));
|
|
1253
|
+
}
|
|
1254
|
+
extracted = parts.join("");
|
|
1255
|
+
}
|
|
1256
|
+
const trimmed = extracted.replace(/\s+/g, " ").trim();
|
|
1257
|
+
if (trimmed) {
|
|
1258
|
+
lines.push(trimmed);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return lines.slice(0, 12);
|
|
1263
|
+
}
|
|
1264
|
+
async function extractPdfPageTextSnippets(pdfDoc, pageIndex) {
|
|
1265
|
+
try {
|
|
1266
|
+
const page = pdfDoc.getPages()[pageIndex];
|
|
1267
|
+
if (!page) return [];
|
|
1268
|
+
const rawContents = page.node.Contents();
|
|
1269
|
+
if (!rawContents) return [];
|
|
1270
|
+
const lookedUp = pdfDoc.context.lookup(rawContents);
|
|
1271
|
+
const refsOrStreams = lookedUp instanceof PDFArray ? lookedUp.asArray() : [rawContents];
|
|
1272
|
+
const latin1 = new TextDecoder("latin1");
|
|
1273
|
+
const collected = [];
|
|
1274
|
+
for (const item of refsOrStreams) {
|
|
1275
|
+
const streamObj = pdfDoc.context.lookup(item);
|
|
1276
|
+
if (!(streamObj instanceof PDFRawStream)) continue;
|
|
1277
|
+
const filterObj = streamObj.dict.get(PDFName.of("Filter"));
|
|
1278
|
+
const filterStr = filterObj ? filterObj.toString() : "";
|
|
1279
|
+
let decodedBytes = null;
|
|
1280
|
+
if (!filterStr) {
|
|
1281
|
+
decodedBytes = streamObj.contents;
|
|
1282
|
+
} else if (filterStr.includes("FlateDecode")) {
|
|
1283
|
+
decodedBytes = await decompressBytesIfSupported(streamObj.contents, "deflate");
|
|
1284
|
+
}
|
|
1285
|
+
if (decodedBytes && decodedBytes.length > 0) {
|
|
1286
|
+
const contentStr = latin1.decode(decodedBytes);
|
|
1287
|
+
collected.push(...parsePdfContentStreamText(contentStr));
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
return Array.from(new Set(collected)).slice(0, 10);
|
|
1291
|
+
} catch {
|
|
1292
|
+
return [];
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
async function importPdfBytesToBoardElements(pdfBytes, options) {
|
|
1296
|
+
const pdfDoc = await PDFDocument.load(pdfBytes, { ignoreEncryption: true });
|
|
1297
|
+
const pages = pdfDoc.getPages();
|
|
1298
|
+
if (pages.length === 0) return [];
|
|
1299
|
+
const docTitle = pdfDoc.getTitle()?.trim() || "PDF \u6587\u6863\u8BC4\u5BA1";
|
|
1300
|
+
const originX = options?.originX ?? 80;
|
|
1301
|
+
const originY = options?.originY ?? 80;
|
|
1302
|
+
const columns = Math.max(1, options?.columns ?? (pages.length <= 2 ? pages.length : 3));
|
|
1303
|
+
const gapX = options?.gapX ?? 56;
|
|
1304
|
+
const gapY = options?.gapY ?? 56;
|
|
1305
|
+
const headerH = 44;
|
|
1306
|
+
const pad = 20;
|
|
1307
|
+
const pageSpecs = pages.map((p) => {
|
|
1308
|
+
const { width, height } = p.getSize();
|
|
1309
|
+
const wPt = Math.max(72, Math.round(width || 595));
|
|
1310
|
+
const hPt = Math.max(72, Math.round(height || 842));
|
|
1311
|
+
const targetSheetW = options?.frameWidth ? Math.max(240, options.frameWidth - pad * 2) : wPt >= hPt ? 560 : 440;
|
|
1312
|
+
const scale = targetSheetW / wPt;
|
|
1313
|
+
const sheetW = Math.round(wPt * scale);
|
|
1314
|
+
const sheetH = Math.max(200, Math.round(hPt * scale));
|
|
1315
|
+
return {
|
|
1316
|
+
wPt,
|
|
1317
|
+
hPt,
|
|
1318
|
+
sheetW,
|
|
1319
|
+
sheetH,
|
|
1320
|
+
frameW: sheetW + pad * 2,
|
|
1321
|
+
frameH: headerH + sheetH + pad
|
|
1322
|
+
};
|
|
1323
|
+
});
|
|
1324
|
+
const cellW = Math.max(...pageSpecs.map((s) => s.frameW));
|
|
1325
|
+
const cellH = Math.max(...pageSpecs.map((s) => s.frameH));
|
|
1326
|
+
const frames = [];
|
|
1327
|
+
const children = [];
|
|
1328
|
+
for (let idx = 0; idx < pageSpecs.length; idx += 1) {
|
|
1329
|
+
const spec = pageSpecs[idx];
|
|
1330
|
+
const col = idx % columns;
|
|
1331
|
+
const row = Math.floor(idx / columns);
|
|
1332
|
+
const fx = originX + col * (cellW + gapX);
|
|
1333
|
+
const fy = originY + row * (cellH + gapY);
|
|
1334
|
+
const frameId = `frame-pdf-${idx + 1}-${generateRandomId2(5)}`;
|
|
1335
|
+
const frameTitle = `PDF \u7B2C ${idx + 1} \u9875 (${spec.wPt}\xD7${spec.hPt})`;
|
|
1336
|
+
frames.push({
|
|
1337
|
+
id: frameId,
|
|
1338
|
+
type: "frame",
|
|
1339
|
+
title: frameTitle,
|
|
1340
|
+
x: fx,
|
|
1341
|
+
y: fy,
|
|
1342
|
+
width: spec.frameW,
|
|
1343
|
+
height: spec.frameH,
|
|
1344
|
+
backgroundColor: "#F8FAFC",
|
|
1345
|
+
borderColor: "#94A3B8",
|
|
1346
|
+
metadata: {
|
|
1347
|
+
importedFrom: "pdf",
|
|
1348
|
+
pageNumber: idx + 1,
|
|
1349
|
+
pageWidthPt: spec.wPt,
|
|
1350
|
+
pageHeightPt: spec.hPt
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
const snippets = await extractPdfPageTextSnippets(pdfDoc, idx);
|
|
1354
|
+
const sheetX = fx + pad;
|
|
1355
|
+
const sheetY = fy + headerH;
|
|
1356
|
+
const sheetCard = {
|
|
1357
|
+
id: `pdf-sheet-${idx + 1}-${generateRandomId2(4)}`,
|
|
1358
|
+
type: "shape",
|
|
1359
|
+
shapeType: "rect",
|
|
1360
|
+
text: snippets.length > 0 ? "" : `${docTitle}
|
|
1361
|
+
\u7B2C ${idx + 1} / ${pages.length} \u9875 (${spec.wPt}\xD7${spec.hPt} pt)
|
|
1362
|
+
\u5728\u6B64\u5904\u8D34\u4E0A\u4FBF\u7B7E\u6216\u753B\u7B14\u6279\u6CE8`,
|
|
1363
|
+
fill: "#FFFFFF",
|
|
1364
|
+
stroke: "#CBD5E1",
|
|
1365
|
+
strokeWidth: 1.5,
|
|
1366
|
+
textColor: "#64748B",
|
|
1367
|
+
fontSize: 12,
|
|
1368
|
+
x: sheetX,
|
|
1369
|
+
y: sheetY,
|
|
1370
|
+
width: spec.sheetW,
|
|
1371
|
+
height: spec.sheetH,
|
|
1372
|
+
frameId
|
|
1373
|
+
};
|
|
1374
|
+
children.push(sheetCard);
|
|
1375
|
+
if (snippets.length > 0) {
|
|
1376
|
+
const textEl = {
|
|
1377
|
+
id: `pdf-text-${idx + 1}-${generateRandomId2(4)}`,
|
|
1378
|
+
type: "text",
|
|
1379
|
+
text: snippets.join("\n"),
|
|
1380
|
+
fontSize: 13,
|
|
1381
|
+
fontWeight: "normal",
|
|
1382
|
+
color: "#1E293B",
|
|
1383
|
+
align: "left",
|
|
1384
|
+
x: sheetX + 20,
|
|
1385
|
+
y: sheetY + 20,
|
|
1386
|
+
width: Math.max(120, spec.sheetW - 40),
|
|
1387
|
+
height: Math.min(spec.sheetH - 40, Math.max(48, snippets.length * 24)),
|
|
1388
|
+
frameId
|
|
1389
|
+
};
|
|
1390
|
+
children.push(textEl);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
return [...frames, ...children];
|
|
1394
|
+
}
|
|
1395
|
+
async function importDeckOrPdfToBoardFrames(fileBytes, fileNameOrFormat, options) {
|
|
1396
|
+
if (!fileBytes || fileBytes.length < 4) return [];
|
|
1397
|
+
const hint = (fileNameOrFormat ?? "").trim().toLowerCase();
|
|
1398
|
+
const isPdfHeader = fileBytes[0] === 37 && fileBytes[1] === 80 && fileBytes[2] === 68 && fileBytes[3] === 70;
|
|
1399
|
+
const isZipHeader = fileBytes[0] === 80 && fileBytes[1] === 75 && (fileBytes[2] === 3 || fileBytes[2] === 5);
|
|
1400
|
+
if (hint === "pdf" || hint.endsWith(".pdf") || isPdfHeader && !hint.endsWith(".pptx")) {
|
|
1401
|
+
return await importPdfBytesToBoardElements(fileBytes, options);
|
|
1402
|
+
}
|
|
1403
|
+
if (hint === "pptx" || hint.endsWith(".pptx") || isZipHeader) {
|
|
1404
|
+
return await importPptxBytesToBoardElements(fileBytes, options);
|
|
1405
|
+
}
|
|
1406
|
+
if (isPdfHeader) {
|
|
1407
|
+
return await importPdfBytesToBoardElements(fileBytes, options);
|
|
1408
|
+
}
|
|
1409
|
+
return [];
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
// src/mermaid/mermaid-codec.ts
|
|
1413
|
+
import { generateRandomId as generateRandomId3 } from "@univerjs/core";
|
|
565
1414
|
|
|
566
1415
|
// src/engine/connector-router.ts
|
|
567
1416
|
var PORT_STUB_DISTANCE = 24;
|
|
@@ -1242,7 +2091,7 @@ function findNextFlowEdge(stmt, startIndex) {
|
|
|
1242
2091
|
return null;
|
|
1243
2092
|
}
|
|
1244
2093
|
function parseFlowchartDiagram(lines, options) {
|
|
1245
|
-
const prefix = options?.idPrefix || `mmf-${
|
|
2094
|
+
const prefix = options?.idPrefix || `mmf-${generateRandomId3(4)}`;
|
|
1246
2095
|
const originX = options?.originX ?? 80;
|
|
1247
2096
|
const originY = options?.originY ?? 80;
|
|
1248
2097
|
let direction = options?.direction ?? "TD";
|
|
@@ -1616,7 +2465,7 @@ function parseFlowchartDiagram(lines, options) {
|
|
|
1616
2465
|
return [...frameElements, ...shapeElements, ...connectorElements];
|
|
1617
2466
|
}
|
|
1618
2467
|
function parseSequenceDiagram(lines, options) {
|
|
1619
|
-
const prefix = options?.idPrefix || `mms-${
|
|
2468
|
+
const prefix = options?.idPrefix || `mms-${generateRandomId3(4)}`;
|
|
1620
2469
|
const originX = options?.originX ?? 80;
|
|
1621
2470
|
const originY = options?.originY ?? 80;
|
|
1622
2471
|
const participants = /* @__PURE__ */ new Map();
|
|
@@ -1890,7 +2739,7 @@ function mapUmlOperatorToMarkers(op) {
|
|
|
1890
2739
|
}
|
|
1891
2740
|
}
|
|
1892
2741
|
function parseClassDiagram(lines, options) {
|
|
1893
|
-
const prefix = options?.idPrefix || `mmc-${
|
|
2742
|
+
const prefix = options?.idPrefix || `mmc-${generateRandomId3(4)}`;
|
|
1894
2743
|
const originX = options?.originX ?? 80;
|
|
1895
2744
|
const originY = options?.originY ?? 80;
|
|
1896
2745
|
const classes = /* @__PURE__ */ new Map();
|
|
@@ -2024,7 +2873,7 @@ function parseClassDiagram(lines, options) {
|
|
|
2024
2873
|
return [...cards, ...connectors];
|
|
2025
2874
|
}
|
|
2026
2875
|
function parseErDiagram(lines, options) {
|
|
2027
|
-
const prefix = options?.idPrefix || `mme-${
|
|
2876
|
+
const prefix = options?.idPrefix || `mme-${generateRandomId3(4)}`;
|
|
2028
2877
|
const originX = options?.originX ?? 80;
|
|
2029
2878
|
const originY = options?.originY ?? 80;
|
|
2030
2879
|
const entities = /* @__PURE__ */ new Map();
|
|
@@ -2179,7 +3028,7 @@ function unwrapMindmapLabel(raw) {
|
|
|
2179
3028
|
return unquoteLabel(s);
|
|
2180
3029
|
}
|
|
2181
3030
|
function parseMindmapDiagram(lines, options) {
|
|
2182
|
-
const prefix = options?.idPrefix || `mmm-${
|
|
3031
|
+
const prefix = options?.idPrefix || `mmm-${generateRandomId3(4)}`;
|
|
2183
3032
|
const originX = options?.originX ?? 340;
|
|
2184
3033
|
const originY = options?.originY ?? 220;
|
|
2185
3034
|
const rawNodes = [];
|
|
@@ -2614,14 +3463,24 @@ function exportBoardToMermaid(snapshot, options) {
|
|
|
2614
3463
|
}
|
|
2615
3464
|
|
|
2616
3465
|
// src/services/board-selection.service.ts
|
|
2617
|
-
import {
|
|
3466
|
+
import {
|
|
3467
|
+
createIdentifier,
|
|
3468
|
+
Disposable,
|
|
3469
|
+
ICommandService,
|
|
3470
|
+
IUniverInstanceService,
|
|
3471
|
+
Optional,
|
|
3472
|
+
UniverInstanceType
|
|
3473
|
+
} from "@univerjs/core";
|
|
2618
3474
|
import { BehaviorSubject } from "rxjs";
|
|
3475
|
+
var SET_VIEWPORT_CMD_ID = "boards.command.set-viewport";
|
|
2619
3476
|
var IBoardSelectionService = createIdentifier(
|
|
2620
3477
|
"yudao.boards.selection-service"
|
|
2621
3478
|
);
|
|
2622
3479
|
var BoardSelectionService = class extends Disposable {
|
|
2623
|
-
constructor() {
|
|
2624
|
-
super(
|
|
3480
|
+
constructor(_commandService, _univerInstanceService) {
|
|
3481
|
+
super();
|
|
3482
|
+
this._commandService = _commandService;
|
|
3483
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2625
3484
|
this._selectedIds$ = new BehaviorSubject([]);
|
|
2626
3485
|
this.selectedIds$ = this._selectedIds$.asObservable();
|
|
2627
3486
|
this._editingElementId$ = new BehaviorSubject(null);
|
|
@@ -2634,6 +3493,10 @@ var BoardSelectionService = class extends Disposable {
|
|
|
2634
3493
|
this.activeStickyColor$ = this._activeStickyColor$.asObservable();
|
|
2635
3494
|
this._mermaidModalOpen$ = new BehaviorSubject(false);
|
|
2636
3495
|
this.mermaidModalOpen$ = this._mermaidModalOpen$.asObservable();
|
|
3496
|
+
this._votingModalOpen$ = new BehaviorSubject(false);
|
|
3497
|
+
this.votingModalOpen$ = this._votingModalOpen$.asObservable();
|
|
3498
|
+
this._docImportModalOpen$ = new BehaviorSubject(false);
|
|
3499
|
+
this.docImportModalOpen$ = this._docImportModalOpen$.asObservable();
|
|
2637
3500
|
this._presentation$ = new BehaviorSubject({
|
|
2638
3501
|
active: false,
|
|
2639
3502
|
frameIndex: 0,
|
|
@@ -2646,6 +3509,16 @@ var BoardSelectionService = class extends Disposable {
|
|
|
2646
3509
|
running: false
|
|
2647
3510
|
});
|
|
2648
3511
|
this.timer$ = this._timer$.asObservable();
|
|
3512
|
+
this._currentUserId$ = new BehaviorSubject("user-local");
|
|
3513
|
+
this.currentUserId$ = this._currentUserId$.asObservable();
|
|
3514
|
+
this._currentUserName = "\u5F53\u524D\u6210\u5458";
|
|
3515
|
+
this._collaborators$ = new BehaviorSubject([]);
|
|
3516
|
+
this.collaborators$ = this._collaborators$.asObservable();
|
|
3517
|
+
this._spotlight$ = new BehaviorSubject({
|
|
3518
|
+
spotlightHostId: null,
|
|
3519
|
+
followingUserId: null
|
|
3520
|
+
});
|
|
3521
|
+
this.spotlight$ = this._spotlight$.asObservable();
|
|
2649
3522
|
}
|
|
2650
3523
|
dispose() {
|
|
2651
3524
|
super.dispose();
|
|
@@ -2655,8 +3528,13 @@ var BoardSelectionService = class extends Disposable {
|
|
|
2655
3528
|
this._activeShapeType$.complete();
|
|
2656
3529
|
this._activeStickyColor$.complete();
|
|
2657
3530
|
this._mermaidModalOpen$.complete();
|
|
3531
|
+
this._votingModalOpen$.complete();
|
|
3532
|
+
this._docImportModalOpen$.complete();
|
|
2658
3533
|
this._presentation$.complete();
|
|
2659
3534
|
this._timer$.complete();
|
|
3535
|
+
this._currentUserId$.complete();
|
|
3536
|
+
this._collaborators$.complete();
|
|
3537
|
+
this._spotlight$.complete();
|
|
2660
3538
|
}
|
|
2661
3539
|
getSelectedIds() {
|
|
2662
3540
|
return [...this._selectedIds$.getValue()];
|
|
@@ -2708,6 +3586,18 @@ var BoardSelectionService = class extends Disposable {
|
|
|
2708
3586
|
setMermaidModalOpen(open) {
|
|
2709
3587
|
this._mermaidModalOpen$.next(open);
|
|
2710
3588
|
}
|
|
3589
|
+
isVotingModalOpen() {
|
|
3590
|
+
return this._votingModalOpen$.getValue();
|
|
3591
|
+
}
|
|
3592
|
+
setVotingModalOpen(open) {
|
|
3593
|
+
this._votingModalOpen$.next(open);
|
|
3594
|
+
}
|
|
3595
|
+
isDocImportModalOpen() {
|
|
3596
|
+
return this._docImportModalOpen$.getValue();
|
|
3597
|
+
}
|
|
3598
|
+
setDocImportModalOpen(open) {
|
|
3599
|
+
this._docImportModalOpen$.next(open);
|
|
3600
|
+
}
|
|
2711
3601
|
getPresentationState() {
|
|
2712
3602
|
return { ...this._presentation$.getValue() };
|
|
2713
3603
|
}
|
|
@@ -2726,23 +3616,130 @@ var BoardSelectionService = class extends Disposable {
|
|
|
2726
3616
|
...patch
|
|
2727
3617
|
});
|
|
2728
3618
|
}
|
|
3619
|
+
getCurrentUserId() {
|
|
3620
|
+
return this._currentUserId$.getValue();
|
|
3621
|
+
}
|
|
3622
|
+
getCurrentUserName() {
|
|
3623
|
+
return this._currentUserName;
|
|
3624
|
+
}
|
|
3625
|
+
setCurrentUserId(userId, userName) {
|
|
3626
|
+
if (userName) {
|
|
3627
|
+
this._currentUserName = userName;
|
|
3628
|
+
}
|
|
3629
|
+
this._currentUserId$.next(userId);
|
|
3630
|
+
this._syncViewportToActiveLeader();
|
|
3631
|
+
}
|
|
3632
|
+
getCollaborators() {
|
|
3633
|
+
return this._collaborators$.getValue().map((c) => ({
|
|
3634
|
+
...c,
|
|
3635
|
+
viewport: { ...c.viewport },
|
|
3636
|
+
...c.cursor ? { cursor: { ...c.cursor } } : {}
|
|
3637
|
+
}));
|
|
3638
|
+
}
|
|
3639
|
+
updateRemoteCollaborator(presence) {
|
|
3640
|
+
const normalized = {
|
|
3641
|
+
userId: presence.userId,
|
|
3642
|
+
userName: presence.userName,
|
|
3643
|
+
color: presence.color,
|
|
3644
|
+
viewport: { ...presence.viewport },
|
|
3645
|
+
...presence.cursor ? { cursor: { ...presence.cursor } } : {},
|
|
3646
|
+
updatedAt: presence.updatedAt ?? Date.now()
|
|
3647
|
+
};
|
|
3648
|
+
const current = this._collaborators$.getValue();
|
|
3649
|
+
const idx = current.findIndex((item) => item.userId === normalized.userId);
|
|
3650
|
+
const next = idx >= 0 ? current.map((item, i) => i === idx ? normalized : item) : [...current, normalized];
|
|
3651
|
+
this._collaborators$.next(next);
|
|
3652
|
+
this._syncViewportToActiveLeader();
|
|
3653
|
+
}
|
|
3654
|
+
removeRemoteCollaborator(userId) {
|
|
3655
|
+
const current = this._collaborators$.getValue();
|
|
3656
|
+
if (current.some((c) => c.userId === userId)) {
|
|
3657
|
+
this._collaborators$.next(current.filter((c) => c.userId !== userId));
|
|
3658
|
+
}
|
|
3659
|
+
const spot = this._spotlight$.getValue();
|
|
3660
|
+
if (spot.followingUserId === userId || spot.spotlightHostId === userId) {
|
|
3661
|
+
this._spotlight$.next({
|
|
3662
|
+
spotlightHostId: spot.spotlightHostId === userId ? null : spot.spotlightHostId,
|
|
3663
|
+
followingUserId: spot.followingUserId === userId ? null : spot.followingUserId
|
|
3664
|
+
});
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
getSpotlightState() {
|
|
3668
|
+
return { ...this._spotlight$.getValue() };
|
|
3669
|
+
}
|
|
3670
|
+
setFollowingUser(userId) {
|
|
3671
|
+
this._spotlight$.next({
|
|
3672
|
+
...this._spotlight$.getValue(),
|
|
3673
|
+
followingUserId: userId
|
|
3674
|
+
});
|
|
3675
|
+
this._syncViewportToActiveLeader();
|
|
3676
|
+
}
|
|
3677
|
+
setSpotlightHost(hostUserId) {
|
|
3678
|
+
const current = this._spotlight$.getValue();
|
|
3679
|
+
this._spotlight$.next({
|
|
3680
|
+
spotlightHostId: hostUserId,
|
|
3681
|
+
followingUserId: hostUserId ? null : current.followingUserId
|
|
3682
|
+
});
|
|
3683
|
+
this._syncViewportToActiveLeader();
|
|
3684
|
+
}
|
|
3685
|
+
resolveEffectiveViewport(localViewport) {
|
|
3686
|
+
const leader = this._resolveActiveLeader();
|
|
3687
|
+
if (leader) {
|
|
3688
|
+
return { ...leader.viewport };
|
|
3689
|
+
}
|
|
3690
|
+
return { ...localViewport };
|
|
3691
|
+
}
|
|
3692
|
+
_resolveActiveLeader() {
|
|
3693
|
+
const { followingUserId, spotlightHostId } = this._spotlight$.getValue();
|
|
3694
|
+
const myId = this._currentUserId$.getValue();
|
|
3695
|
+
const collaborators = this._collaborators$.getValue();
|
|
3696
|
+
if (followingUserId && followingUserId !== myId) {
|
|
3697
|
+
const target = collaborators.find((c) => c.userId === followingUserId);
|
|
3698
|
+
if (target) return target;
|
|
3699
|
+
}
|
|
3700
|
+
if (spotlightHostId && spotlightHostId !== myId) {
|
|
3701
|
+
const host = collaborators.find((c) => c.userId === spotlightHostId);
|
|
3702
|
+
if (host) return host;
|
|
3703
|
+
}
|
|
3704
|
+
return void 0;
|
|
3705
|
+
}
|
|
3706
|
+
_syncViewportToActiveLeader() {
|
|
3707
|
+
const leader = this._resolveActiveLeader();
|
|
3708
|
+
if (!leader || !this._commandService || !this._univerInstanceService) {
|
|
3709
|
+
return;
|
|
3710
|
+
}
|
|
3711
|
+
const activeUnit = this._univerInstanceService.getCurrentUnitOfType(
|
|
3712
|
+
UniverInstanceType.UNIVER_BOARD
|
|
3713
|
+
);
|
|
3714
|
+
if (!activeUnit) {
|
|
3715
|
+
return;
|
|
3716
|
+
}
|
|
3717
|
+
this._commandService.syncExecuteCommand(SET_VIEWPORT_CMD_ID, {
|
|
3718
|
+
unitId: activeUnit.getUnitId(),
|
|
3719
|
+
viewport: { ...leader.viewport }
|
|
3720
|
+
});
|
|
3721
|
+
}
|
|
2729
3722
|
};
|
|
3723
|
+
BoardSelectionService = __decorateClass([
|
|
3724
|
+
__decorateParam(0, Optional(ICommandService)),
|
|
3725
|
+
__decorateParam(1, Optional(IUniverInstanceService))
|
|
3726
|
+
], BoardSelectionService);
|
|
2730
3727
|
|
|
2731
3728
|
// src/commands/mutations/board.mutation.ts
|
|
2732
3729
|
import {
|
|
2733
3730
|
CommandType,
|
|
2734
|
-
IUniverInstanceService,
|
|
2735
|
-
UniverInstanceType
|
|
3731
|
+
IUniverInstanceService as IUniverInstanceService2,
|
|
3732
|
+
UniverInstanceType as UniverInstanceType2
|
|
2736
3733
|
} from "@univerjs/core";
|
|
2737
3734
|
var ApplyBoardSnapshotMutation = {
|
|
2738
3735
|
id: "boards.mutation.apply-snapshot",
|
|
2739
3736
|
type: CommandType.MUTATION,
|
|
2740
3737
|
handler: (accessor, params) => {
|
|
2741
3738
|
if (!params?.unitId || !params.snapshot) return false;
|
|
2742
|
-
const instanceService = accessor.get(
|
|
3739
|
+
const instanceService = accessor.get(IUniverInstanceService2);
|
|
2743
3740
|
const unit = instanceService.getUnit(
|
|
2744
3741
|
params.unitId,
|
|
2745
|
-
|
|
3742
|
+
UniverInstanceType2.UNIVER_BOARD
|
|
2746
3743
|
);
|
|
2747
3744
|
if (!unit) return false;
|
|
2748
3745
|
unit.__applySnapshot(params.snapshot);
|
|
@@ -2754,10 +3751,10 @@ var SetBoardViewportMutation = {
|
|
|
2754
3751
|
type: CommandType.MUTATION,
|
|
2755
3752
|
handler: (accessor, params) => {
|
|
2756
3753
|
if (!params?.unitId || !params.viewport) return false;
|
|
2757
|
-
const instanceService = accessor.get(
|
|
3754
|
+
const instanceService = accessor.get(IUniverInstanceService2);
|
|
2758
3755
|
const unit = instanceService.getUnit(
|
|
2759
3756
|
params.unitId,
|
|
2760
|
-
|
|
3757
|
+
UniverInstanceType2.UNIVER_BOARD
|
|
2761
3758
|
);
|
|
2762
3759
|
if (!unit) return false;
|
|
2763
3760
|
unit.__setViewport(params.viewport);
|
|
@@ -2767,12 +3764,12 @@ var SetBoardViewportMutation = {
|
|
|
2767
3764
|
|
|
2768
3765
|
// src/commands/commands/board.command.ts
|
|
2769
3766
|
function resolveBoardUnit(accessor, explicitUnitId) {
|
|
2770
|
-
const instanceService = accessor.get(
|
|
2771
|
-
const resolved = explicitUnitId ? instanceService.getUnit(explicitUnitId,
|
|
3767
|
+
const instanceService = accessor.get(IUniverInstanceService3);
|
|
3768
|
+
const resolved = explicitUnitId ? instanceService.getUnit(explicitUnitId, UniverInstanceType3.UNIVER_BOARD) : instanceService.getCurrentUnitOfType(UniverInstanceType3.UNIVER_BOARD);
|
|
2772
3769
|
return resolved ?? null;
|
|
2773
3770
|
}
|
|
2774
3771
|
function commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot) {
|
|
2775
|
-
const commandService = accessor.get(
|
|
3772
|
+
const commandService = accessor.get(ICommandService2);
|
|
2776
3773
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
2777
3774
|
const unitId = unit.getUnitId();
|
|
2778
3775
|
const ok = commandService.syncExecuteCommand(ApplyBoardSnapshotMutation.id, {
|
|
@@ -2997,7 +3994,7 @@ var GroupBoardElementsInFrameCommand = {
|
|
|
2997
3994
|
}
|
|
2998
3995
|
const pad = params?.padding ?? 32;
|
|
2999
3996
|
const topHeader = 48;
|
|
3000
|
-
const frameId = params?.frameId || `frame-${
|
|
3997
|
+
const frameId = params?.frameId || `frame-${generateRandomId4(6)}`;
|
|
3001
3998
|
const frameIndex = afterSnapshot.frameOrder.length + 1;
|
|
3002
3999
|
const frame = {
|
|
3003
4000
|
id: frameId,
|
|
@@ -3060,7 +4057,7 @@ var AddMindmapChildCommand = {
|
|
|
3060
4057
|
const existingChildren = Object.values(afterSnapshot.elements).filter(
|
|
3061
4058
|
(el) => el.type === "mindmap" && el.parentId === parentId
|
|
3062
4059
|
);
|
|
3063
|
-
const childId = params?.id || `mindmap-${
|
|
4060
|
+
const childId = params?.id || `mindmap-${generateRandomId4(6)}`;
|
|
3064
4061
|
const color = !parent.parentId ? MINDMAP_BRANCH_PALETTE[existingChildren.length % MINDMAP_BRANCH_PALETTE.length] : parent.branchColor || "#2563EB";
|
|
3065
4062
|
const child = {
|
|
3066
4063
|
id: childId,
|
|
@@ -3101,7 +4098,7 @@ var AddMindmapSiblingCommand = {
|
|
|
3101
4098
|
const node = unit.getElement(nodeId);
|
|
3102
4099
|
if (!node || node.type !== "mindmap") return false;
|
|
3103
4100
|
const targetParentId = node.parentId ?? node.id;
|
|
3104
|
-
return accessor.get(
|
|
4101
|
+
return accessor.get(ICommandService2).syncExecuteCommand(AddMindmapChildCommand.id, {
|
|
3105
4102
|
unitId: unit.getUnitId(),
|
|
3106
4103
|
parentId: targetParentId,
|
|
3107
4104
|
text: params?.text ?? "\u540C\u7EA7\u4E3B\u9898",
|
|
@@ -3209,7 +4206,7 @@ var SetBoardViewportCommand = {
|
|
|
3209
4206
|
...params?.panY !== void 0 ? { panY: params.panY } : {},
|
|
3210
4207
|
...params?.zoom !== void 0 ? { zoom: params.zoom } : {}
|
|
3211
4208
|
};
|
|
3212
|
-
return accessor.get(
|
|
4209
|
+
return accessor.get(ICommandService2).syncExecuteCommand(SetBoardViewportMutation.id, {
|
|
3213
4210
|
unitId: unit.getUnitId(),
|
|
3214
4211
|
viewport: patch
|
|
3215
4212
|
});
|
|
@@ -3225,7 +4222,7 @@ var AddBoardCommentCommand = {
|
|
|
3225
4222
|
const beforeSnapshot = unit.save();
|
|
3226
4223
|
const afterSnapshot = unit.save();
|
|
3227
4224
|
const comment = {
|
|
3228
|
-
id: params.id || `comment-${
|
|
4225
|
+
id: params.id || `comment-${generateRandomId4(6)}`,
|
|
3229
4226
|
x: Math.round(params.x),
|
|
3230
4227
|
y: Math.round(params.y),
|
|
3231
4228
|
author: params.author ?? "\u534F\u4F5C\u6210\u5458",
|
|
@@ -3277,18 +4274,232 @@ var UpdateBoardPropsCommand = {
|
|
|
3277
4274
|
...params.patch.viewport
|
|
3278
4275
|
};
|
|
3279
4276
|
}
|
|
4277
|
+
if (params.patch.brainstorm !== void 0) {
|
|
4278
|
+
if (params.patch.brainstorm === null) {
|
|
4279
|
+
delete afterSnapshot.brainstorm;
|
|
4280
|
+
} else {
|
|
4281
|
+
afterSnapshot.brainstorm = Tools2.deepClone(params.patch.brainstorm);
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
if (params.patch.votingSession !== void 0) {
|
|
4285
|
+
if (params.patch.votingSession === null) {
|
|
4286
|
+
delete afterSnapshot.votingSession;
|
|
4287
|
+
} else {
|
|
4288
|
+
afterSnapshot.votingSession = Tools2.deepClone(params.patch.votingSession);
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
return commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
4292
|
+
}
|
|
4293
|
+
};
|
|
4294
|
+
var StartPrivateBrainstormCommand = {
|
|
4295
|
+
id: "boards.command.start-private-brainstorm",
|
|
4296
|
+
type: CommandType2.COMMAND,
|
|
4297
|
+
handler: (accessor, params) => {
|
|
4298
|
+
const unit = resolveBoardUnit(accessor, params?.unitId);
|
|
4299
|
+
if (!unit) return false;
|
|
4300
|
+
const beforeSnapshot = unit.save();
|
|
4301
|
+
const afterSnapshot = unit.save();
|
|
4302
|
+
const defaultFacilitator = accessor.has(IBoardSelectionService) ? accessor.get(IBoardSelectionService).getCurrentUserId() : void 0;
|
|
4303
|
+
const facilitatorId = params?.facilitatorId ?? defaultFacilitator;
|
|
4304
|
+
afterSnapshot.brainstorm = {
|
|
4305
|
+
active: true,
|
|
4306
|
+
hideAuthorNames: params?.hideAuthorNames ?? false,
|
|
4307
|
+
revealed: false,
|
|
4308
|
+
...facilitatorId ? { facilitatorId } : {}
|
|
4309
|
+
};
|
|
4310
|
+
return commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
4311
|
+
}
|
|
4312
|
+
};
|
|
4313
|
+
var RevealPrivateBrainstormCommand = {
|
|
4314
|
+
id: "boards.command.reveal-private-brainstorm",
|
|
4315
|
+
type: CommandType2.COMMAND,
|
|
4316
|
+
handler: (accessor, params) => {
|
|
4317
|
+
const unit = resolveBoardUnit(accessor, params?.unitId);
|
|
4318
|
+
if (!unit) return false;
|
|
4319
|
+
const beforeSnapshot = unit.save();
|
|
4320
|
+
const afterSnapshot = unit.save();
|
|
4321
|
+
afterSnapshot.brainstorm = {
|
|
4322
|
+
...afterSnapshot.brainstorm ?? { active: true },
|
|
4323
|
+
revealed: true
|
|
4324
|
+
};
|
|
4325
|
+
return commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
4326
|
+
}
|
|
4327
|
+
};
|
|
4328
|
+
var StopPrivateBrainstormCommand = {
|
|
4329
|
+
id: "boards.command.stop-private-brainstorm",
|
|
4330
|
+
type: CommandType2.COMMAND,
|
|
4331
|
+
handler: (accessor, params) => {
|
|
4332
|
+
const unit = resolveBoardUnit(accessor, params?.unitId);
|
|
4333
|
+
if (!unit) return false;
|
|
4334
|
+
const beforeSnapshot = unit.save();
|
|
4335
|
+
const afterSnapshot = unit.save();
|
|
4336
|
+
afterSnapshot.brainstorm = {
|
|
4337
|
+
...afterSnapshot.brainstorm ?? {},
|
|
4338
|
+
active: false,
|
|
4339
|
+
revealed: true
|
|
4340
|
+
};
|
|
4341
|
+
return commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
4342
|
+
}
|
|
4343
|
+
};
|
|
4344
|
+
var StartBoardVotingSessionCommand = {
|
|
4345
|
+
id: "boards.command.start-voting-session",
|
|
4346
|
+
type: CommandType2.COMMAND,
|
|
4347
|
+
handler: (accessor, params) => {
|
|
4348
|
+
const unit = resolveBoardUnit(accessor, params?.unitId);
|
|
4349
|
+
if (!unit) return false;
|
|
4350
|
+
const beforeSnapshot = unit.save();
|
|
4351
|
+
const afterSnapshot = unit.save();
|
|
4352
|
+
const maxVotesPerUser = Math.max(1, Math.floor(params?.maxVotesPerUser ?? 5));
|
|
4353
|
+
if (params?.resetExistingStickyVotes) {
|
|
4354
|
+
for (const el of Object.values(afterSnapshot.elements)) {
|
|
4355
|
+
if (el.type === "sticky") {
|
|
4356
|
+
el.votes = [];
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
afterSnapshot.votingSession = {
|
|
4361
|
+
id: params?.id || `voting-${generateRandomId4(6)}`,
|
|
4362
|
+
title: params?.title?.trim() || "\u56E2\u961F\u65B9\u6848\u4F18\u5148\u7EA7\u6295\u7968",
|
|
4363
|
+
active: true,
|
|
4364
|
+
maxVotesPerUser,
|
|
4365
|
+
allowMultiplePerSticky: params?.allowMultiplePerSticky ?? true,
|
|
4366
|
+
...params?.targetFrameId ? { targetFrameId: params.targetFrameId } : {},
|
|
4367
|
+
votesByUser: {},
|
|
4368
|
+
startedAt: params?.startedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
4369
|
+
};
|
|
3280
4370
|
return commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
3281
4371
|
}
|
|
3282
4372
|
};
|
|
4373
|
+
var CastBoardSessionVoteCommand = {
|
|
4374
|
+
id: "boards.command.cast-session-vote",
|
|
4375
|
+
type: CommandType2.COMMAND,
|
|
4376
|
+
handler: (accessor, params) => {
|
|
4377
|
+
if (!params?.elementId) return false;
|
|
4378
|
+
const unit = resolveBoardUnit(accessor, params.unitId);
|
|
4379
|
+
if (!unit) return false;
|
|
4380
|
+
const beforeSnapshot = unit.save();
|
|
4381
|
+
const afterSnapshot = unit.save();
|
|
4382
|
+
const session = afterSnapshot.votingSession;
|
|
4383
|
+
if (!session || !session.active) return false;
|
|
4384
|
+
const sticky = afterSnapshot.elements[params.elementId];
|
|
4385
|
+
if (!sticky || sticky.type !== "sticky") return false;
|
|
4386
|
+
if (session.targetFrameId) {
|
|
4387
|
+
const targetFrame = afterSnapshot.elements[session.targetFrameId];
|
|
4388
|
+
if (targetFrame && targetFrame.type === "frame") {
|
|
4389
|
+
const cx = sticky.x + sticky.width / 2;
|
|
4390
|
+
const cy = sticky.y + sticky.height / 2;
|
|
4391
|
+
const insideFrame = sticky.frameId === targetFrame.id || cx >= targetFrame.x && cx <= targetFrame.x + targetFrame.width && cy >= targetFrame.y && cy <= targetFrame.y + targetFrame.height;
|
|
4392
|
+
if (!insideFrame) return false;
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
const voterId = params.voterId || (accessor.has(IBoardSelectionService) ? accessor.get(IBoardSelectionService).getCurrentUserId() : "anonymous");
|
|
4396
|
+
const userVotes = session.votesByUser[voterId] ?? (session.votesByUser[voterId] = []);
|
|
4397
|
+
if (params.unvote) {
|
|
4398
|
+
const lastVoteIdx = userVotes.lastIndexOf(params.elementId);
|
|
4399
|
+
if (lastVoteIdx === -1) return false;
|
|
4400
|
+
userVotes.splice(lastVoteIdx, 1);
|
|
4401
|
+
for (let i = sticky.votes.length - 1; i >= 0; i -= 1) {
|
|
4402
|
+
if (sticky.votes[i] === voterId || sticky.votes[i].startsWith(`${voterId}#`)) {
|
|
4403
|
+
sticky.votes.splice(i, 1);
|
|
4404
|
+
break;
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
return commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
4408
|
+
}
|
|
4409
|
+
if (userVotes.length >= session.maxVotesPerUser) {
|
|
4410
|
+
return false;
|
|
4411
|
+
}
|
|
4412
|
+
if (session.allowMultiplePerSticky === false && userVotes.includes(params.elementId)) {
|
|
4413
|
+
return false;
|
|
4414
|
+
}
|
|
4415
|
+
userVotes.push(params.elementId);
|
|
4416
|
+
if (!sticky.votes.includes(voterId)) {
|
|
4417
|
+
sticky.votes.push(voterId);
|
|
4418
|
+
} else {
|
|
4419
|
+
const countOnSticky = userVotes.filter((id) => id === params.elementId).length;
|
|
4420
|
+
sticky.votes.push(`${voterId}#${countOnSticky}`);
|
|
4421
|
+
}
|
|
4422
|
+
return commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
4423
|
+
}
|
|
4424
|
+
};
|
|
4425
|
+
var EndBoardVotingSessionCommand = {
|
|
4426
|
+
id: "boards.command.end-voting-session",
|
|
4427
|
+
type: CommandType2.COMMAND,
|
|
4428
|
+
handler: (accessor, params) => {
|
|
4429
|
+
const unit = resolveBoardUnit(accessor, params?.unitId);
|
|
4430
|
+
if (!unit) return false;
|
|
4431
|
+
const beforeSnapshot = unit.save();
|
|
4432
|
+
const afterSnapshot = unit.save();
|
|
4433
|
+
if (!afterSnapshot.votingSession) return false;
|
|
4434
|
+
afterSnapshot.votingSession = {
|
|
4435
|
+
...afterSnapshot.votingSession,
|
|
4436
|
+
active: false,
|
|
4437
|
+
endedAt: params?.endedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
4438
|
+
};
|
|
4439
|
+
return commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
4440
|
+
}
|
|
4441
|
+
};
|
|
4442
|
+
var ImportDocumentPagesToBoardCommand = {
|
|
4443
|
+
id: "boards.command.import-document-pages",
|
|
4444
|
+
type: CommandType2.COMMAND,
|
|
4445
|
+
handler: async (accessor, params) => {
|
|
4446
|
+
if (!params?.fileBytes || params.fileBytes.length === 0) return false;
|
|
4447
|
+
const unit = resolveBoardUnit(accessor, params.unitId);
|
|
4448
|
+
if (!unit) return false;
|
|
4449
|
+
const parsedElements = await importDeckOrPdfToBoardFrames(
|
|
4450
|
+
params.fileBytes,
|
|
4451
|
+
params.format ?? params.fileName,
|
|
4452
|
+
{
|
|
4453
|
+
originX: params.originX ?? 80,
|
|
4454
|
+
originY: params.originY ?? 80,
|
|
4455
|
+
columns: params.columns
|
|
4456
|
+
}
|
|
4457
|
+
);
|
|
4458
|
+
if (parsedElements.length === 0) return false;
|
|
4459
|
+
const beforeSnapshot = unit.save();
|
|
4460
|
+
const afterSnapshot = unit.save();
|
|
4461
|
+
if (params.replaceExisting) {
|
|
4462
|
+
afterSnapshot.elements = {};
|
|
4463
|
+
afterSnapshot.elementOrder = [];
|
|
4464
|
+
afterSnapshot.frameOrder = [];
|
|
4465
|
+
}
|
|
4466
|
+
const importedFrameIds = [];
|
|
4467
|
+
for (const el of parsedElements) {
|
|
4468
|
+
afterSnapshot.elements[el.id] = el;
|
|
4469
|
+
afterSnapshot.elementOrder = afterSnapshot.elementOrder.filter((id) => id !== el.id);
|
|
4470
|
+
if (el.type === "frame") {
|
|
4471
|
+
const firstNonFrame = afterSnapshot.elementOrder.findIndex(
|
|
4472
|
+
(id) => afterSnapshot.elements[id]?.type !== "frame"
|
|
4473
|
+
);
|
|
4474
|
+
if (firstNonFrame === -1) {
|
|
4475
|
+
afterSnapshot.elementOrder.push(el.id);
|
|
4476
|
+
} else {
|
|
4477
|
+
afterSnapshot.elementOrder.splice(firstNonFrame, 0, el.id);
|
|
4478
|
+
}
|
|
4479
|
+
if (!afterSnapshot.frameOrder.includes(el.id)) {
|
|
4480
|
+
afterSnapshot.frameOrder.push(el.id);
|
|
4481
|
+
}
|
|
4482
|
+
importedFrameIds.push(el.id);
|
|
4483
|
+
} else {
|
|
4484
|
+
afterSnapshot.elementOrder.push(el.id);
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
const ok = commitUndoableSnapshot(accessor, unit, beforeSnapshot, afterSnapshot);
|
|
4488
|
+
if (ok && accessor.has(IBoardSelectionService) && importedFrameIds.length > 0) {
|
|
4489
|
+
accessor.get(IBoardSelectionService).selectElements(importedFrameIds);
|
|
4490
|
+
}
|
|
4491
|
+
return ok;
|
|
4492
|
+
}
|
|
4493
|
+
};
|
|
3283
4494
|
|
|
3284
4495
|
// src/models/board-unit-model.ts
|
|
3285
|
-
import { Tools as Tools4, UnitModel, UniverInstanceType as
|
|
4496
|
+
import { Tools as Tools4, UnitModel, UniverInstanceType as UniverInstanceType4 } from "@univerjs/core";
|
|
3286
4497
|
import { BehaviorSubject as BehaviorSubject2, Subject } from "rxjs";
|
|
3287
4498
|
|
|
3288
4499
|
// src/presets/board-presets.ts
|
|
3289
|
-
import { generateRandomId as
|
|
4500
|
+
import { generateRandomId as generateRandomId5, Tools as Tools3 } from "@univerjs/core";
|
|
3290
4501
|
function createDefaultBoardUnitData(partial) {
|
|
3291
|
-
const id = partial?.id || `board-${
|
|
4502
|
+
const id = partial?.id || `board-${generateRandomId5(6)}`;
|
|
3292
4503
|
const rawElements = partial?.elements ? Tools3.deepClone(partial.elements) : {};
|
|
3293
4504
|
const elementOrder = partial?.elementOrder ? [...partial.elementOrder] : Object.keys(rawElements);
|
|
3294
4505
|
const frameOrder = partial?.frameOrder ? [...partial.frameOrder] : elementOrder.filter((eid) => rawElements[eid]?.type === "frame");
|
|
@@ -3303,7 +4514,9 @@ function createDefaultBoardUnitData(partial) {
|
|
|
3303
4514
|
elementOrder,
|
|
3304
4515
|
elements: rawElements,
|
|
3305
4516
|
frameOrder,
|
|
3306
|
-
comments: partial?.comments ? Tools3.deepClone(partial.comments) : []
|
|
4517
|
+
comments: partial?.comments ? Tools3.deepClone(partial.comments) : [],
|
|
4518
|
+
...partial?.brainstorm ? { brainstorm: Tools3.deepClone(partial.brainstorm) } : {},
|
|
4519
|
+
...partial?.votingSession ? { votingSession: Tools3.deepClone(partial.votingSession) } : {}
|
|
3307
4520
|
};
|
|
3308
4521
|
}
|
|
3309
4522
|
function createSampleArchitectureBoardData(partial) {
|
|
@@ -3754,6 +4967,7 @@ function createSampleArchitectureBoardData(partial) {
|
|
|
3754
4967
|
text: "\u7F51\u5173\u7070\u5EA6\u81EA\u52A8\u5316\u53D1\u5E03\u96F6\u6545\u969C\u5B8C\u6210",
|
|
3755
4968
|
color: "green",
|
|
3756
4969
|
author: "\u6797\u5DE5",
|
|
4970
|
+
authorId: "user-lin",
|
|
3757
4971
|
votes: ["u1", "u2", "u3"],
|
|
3758
4972
|
tags: ["DevOps"],
|
|
3759
4973
|
x: 936,
|
|
@@ -3768,6 +4982,7 @@ function createSampleArchitectureBoardData(partial) {
|
|
|
3768
4982
|
text: "\u5927\u4FC3\u538B\u6D4B\u6162 SQL \u9700\u63D0\u524D\u4E00\u5468\u5DE1\u68C0",
|
|
3769
4983
|
color: "yellow",
|
|
3770
4984
|
author: "\u9648\u5DE5",
|
|
4985
|
+
authorId: "user-chen",
|
|
3771
4986
|
votes: ["u1", "u4"],
|
|
3772
4987
|
tags: ["DBA"],
|
|
3773
4988
|
x: 1086,
|
|
@@ -3782,6 +4997,7 @@ function createSampleArchitectureBoardData(partial) {
|
|
|
3782
4997
|
text: "\u63A5\u5165 Mermaid \u4EE3\u7801\u4E00\u952E\u751F\u6210\u67B6\u6784\u56FE\u6587\u6863",
|
|
3783
4998
|
color: "blue",
|
|
3784
4999
|
author: "\u5468\u5DE5",
|
|
5000
|
+
authorId: "user-zhou",
|
|
3785
5001
|
votes: ["u1", "u2", "u3", "u4", "u5"],
|
|
3786
5002
|
tags: ["P0"],
|
|
3787
5003
|
x: 1236,
|
|
@@ -3842,7 +5058,7 @@ function createSampleArchitectureBoardData(partial) {
|
|
|
3842
5058
|
var BoardUnitModel = class extends UnitModel {
|
|
3843
5059
|
constructor(snapshot) {
|
|
3844
5060
|
super();
|
|
3845
|
-
this.type =
|
|
5061
|
+
this.type = UniverInstanceType4.UNIVER_BOARD;
|
|
3846
5062
|
this._snapshotChanged$ = new Subject();
|
|
3847
5063
|
this.snapshotChanged$ = this._snapshotChanged$.asObservable();
|
|
3848
5064
|
this._snapshot = createDefaultBoardUnitData(snapshot);
|
|
@@ -3943,6 +5159,12 @@ var BoardUnitModel = class extends UnitModel {
|
|
|
3943
5159
|
getComments() {
|
|
3944
5160
|
return Tools4.deepClone(this._snapshot.comments);
|
|
3945
5161
|
}
|
|
5162
|
+
getBrainstormConfig() {
|
|
5163
|
+
return this._snapshot.brainstorm ? Tools4.deepClone(this._snapshot.brainstorm) : void 0;
|
|
5164
|
+
}
|
|
5165
|
+
getVotingSession() {
|
|
5166
|
+
return this._snapshot.votingSession ? Tools4.deepClone(this._snapshot.votingSession) : void 0;
|
|
5167
|
+
}
|
|
3946
5168
|
/** Internal synchronous mutators called exclusively by registered IMutation handlers */
|
|
3947
5169
|
__applySnapshot(nextSnapshot) {
|
|
3948
5170
|
const prevUnitId = this._snapshot.id;
|
|
@@ -4041,6 +5263,20 @@ var BoardUnitModel = class extends UnitModel {
|
|
|
4041
5263
|
if (patch.elementOrder !== void 0) {
|
|
4042
5264
|
this._snapshot.elementOrder = [...patch.elementOrder];
|
|
4043
5265
|
}
|
|
5266
|
+
if (patch.brainstorm !== void 0) {
|
|
5267
|
+
if (patch.brainstorm === null) {
|
|
5268
|
+
delete this._snapshot.brainstorm;
|
|
5269
|
+
} else {
|
|
5270
|
+
this._snapshot.brainstorm = Tools4.deepClone(patch.brainstorm);
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5273
|
+
if (patch.votingSession !== void 0) {
|
|
5274
|
+
if (patch.votingSession === null) {
|
|
5275
|
+
delete this._snapshot.votingSession;
|
|
5276
|
+
} else {
|
|
5277
|
+
this._snapshot.votingSession = Tools4.deepClone(patch.votingSession);
|
|
5278
|
+
}
|
|
5279
|
+
}
|
|
4044
5280
|
this.incrementRev();
|
|
4045
5281
|
this._notifyChange();
|
|
4046
5282
|
}
|
|
@@ -4059,7 +5295,7 @@ import { createIdentifier as createIdentifier2, Disposable as Disposable2 } from
|
|
|
4059
5295
|
import { Subject as Subject2 } from "rxjs";
|
|
4060
5296
|
|
|
4061
5297
|
// src/exporter/board-csv-exporter.ts
|
|
4062
|
-
import { generateRandomId as
|
|
5298
|
+
import { generateRandomId as generateRandomId6 } from "@univerjs/core";
|
|
4063
5299
|
var STICKY_COLORS_CYCLE = [
|
|
4064
5300
|
"yellow",
|
|
4065
5301
|
"blue",
|
|
@@ -4199,7 +5435,7 @@ function importCsvToBoardStickies(csvText, options) {
|
|
|
4199
5435
|
const PAD_X = 32;
|
|
4200
5436
|
const PAD_TOP = 54;
|
|
4201
5437
|
const PAD_BOTTOM = 32;
|
|
4202
|
-
const frameId = `frame-csv-${
|
|
5438
|
+
const frameId = `frame-csv-${generateRandomId6(5)}`;
|
|
4203
5439
|
const stickies = [];
|
|
4204
5440
|
dataRows.forEach((r, idx) => {
|
|
4205
5441
|
const col = idx % cols;
|
|
@@ -4212,7 +5448,7 @@ function importCsvToBoardStickies(csvText, options) {
|
|
|
4212
5448
|
const votes = Array.from({ length: Math.min(50, voteNum) }, (_, vIdx) => `csv-voter-${vIdx + 1}`);
|
|
4213
5449
|
const tags = tagsCol >= 0 && r[tagsCol]?.trim() ? r[tagsCol].split(/[;|]/).map((t) => t.trim()).filter(Boolean) : void 0;
|
|
4214
5450
|
stickies.push({
|
|
4215
|
-
id: `sticky-csv-${
|
|
5451
|
+
id: `sticky-csv-${generateRandomId6(5)}`,
|
|
4216
5452
|
type: "sticky",
|
|
4217
5453
|
text: primaryText,
|
|
4218
5454
|
color,
|
|
@@ -4243,7 +5479,7 @@ function importCsvToBoardStickies(csvText, options) {
|
|
|
4243
5479
|
}
|
|
4244
5480
|
|
|
4245
5481
|
// src/exporter/board-pdf-exporter.ts
|
|
4246
|
-
import { PDFDocument, rgb, StandardFonts } from "pdf-lib";
|
|
5482
|
+
import { PDFDocument as PDFDocument2, rgb, StandardFonts } from "pdf-lib";
|
|
4247
5483
|
|
|
4248
5484
|
// src/exporter/board-svg-exporter.ts
|
|
4249
5485
|
function escapeXml(raw) {
|
|
@@ -5156,7 +6392,7 @@ function renderElementsToPdfPage(page, bounds, elements, snapshot, fontRegular,
|
|
|
5156
6392
|
}
|
|
5157
6393
|
}
|
|
5158
6394
|
async function exportBoardToPdfBytes(snapshot, options) {
|
|
5159
|
-
const pdfDoc = await
|
|
6395
|
+
const pdfDoc = await PDFDocument2.create();
|
|
5160
6396
|
pdfDoc.setTitle(toWinAnsiSafe(snapshot.name || "Univer Board") || "Univer Board");
|
|
5161
6397
|
pdfDoc.setCreator("Univer Boards");
|
|
5162
6398
|
const fontRegular = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
@@ -5932,6 +7168,15 @@ var BoardIoService = class extends Disposable2 {
|
|
|
5932
7168
|
importCsvStickies(csvText, options) {
|
|
5933
7169
|
return importCsvToBoardStickies(csvText, options);
|
|
5934
7170
|
}
|
|
7171
|
+
async importPptx(pptxBytes, options) {
|
|
7172
|
+
return await importPptxBytesToBoardElements(pptxBytes, options);
|
|
7173
|
+
}
|
|
7174
|
+
async importPdf(pdfBytes, options) {
|
|
7175
|
+
return await importPdfBytesToBoardElements(pdfBytes, options);
|
|
7176
|
+
}
|
|
7177
|
+
async importDocumentFrames(fileBytes, fileNameOrFormat, options) {
|
|
7178
|
+
return await importDeckOrPdfToBoardFrames(fileBytes, fileNameOrFormat, options);
|
|
7179
|
+
}
|
|
5935
7180
|
};
|
|
5936
7181
|
|
|
5937
7182
|
// src/plugin.ts
|
|
@@ -5953,11 +7198,11 @@ var UniverBoardsPlugin = class extends Plugin {
|
|
|
5953
7198
|
onStarting() {
|
|
5954
7199
|
this.disposeWithMe(
|
|
5955
7200
|
this._univerInstanceService.registerCtorForType(
|
|
5956
|
-
|
|
7201
|
+
UniverInstanceType5.UNIVER_BOARD,
|
|
5957
7202
|
BoardUnitModel
|
|
5958
7203
|
)
|
|
5959
7204
|
);
|
|
5960
|
-
const focusSub = this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
7205
|
+
const focusSub = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType5.UNIVER_BOARD).subscribe((unit) => {
|
|
5961
7206
|
if (unit && this._univerInstanceService.getFocusedUnit()?.getUnitId() !== unit.getUnitId()) {
|
|
5962
7207
|
this._univerInstanceService.focusUnit(unit.getUnitId());
|
|
5963
7208
|
}
|
|
@@ -5989,7 +7234,14 @@ var UniverBoardsPlugin = class extends Plugin {
|
|
|
5989
7234
|
SetBoardViewportCommand,
|
|
5990
7235
|
AddBoardCommentCommand,
|
|
5991
7236
|
ReplaceBoardSnapshotCommand,
|
|
5992
|
-
UpdateBoardPropsCommand
|
|
7237
|
+
UpdateBoardPropsCommand,
|
|
7238
|
+
StartPrivateBrainstormCommand,
|
|
7239
|
+
RevealPrivateBrainstormCommand,
|
|
7240
|
+
StopPrivateBrainstormCommand,
|
|
7241
|
+
StartBoardVotingSessionCommand,
|
|
7242
|
+
CastBoardSessionVoteCommand,
|
|
7243
|
+
EndBoardVotingSessionCommand,
|
|
7244
|
+
ImportDocumentPagesToBoardCommand
|
|
5993
7245
|
];
|
|
5994
7246
|
for (const cmd of commands) {
|
|
5995
7247
|
this.disposeWithMe(this._commandService.registerCommand(cmd));
|
|
@@ -5998,12 +7250,12 @@ var UniverBoardsPlugin = class extends Plugin {
|
|
|
5998
7250
|
};
|
|
5999
7251
|
UniverBoardsPlugin = __decorateClass([
|
|
6000
7252
|
__decorateParam(1, Inject(Injector)),
|
|
6001
|
-
__decorateParam(2,
|
|
6002
|
-
__decorateParam(3,
|
|
7253
|
+
__decorateParam(2, IUniverInstanceService4),
|
|
7254
|
+
__decorateParam(3, ICommandService3)
|
|
6003
7255
|
], UniverBoardsPlugin);
|
|
6004
7256
|
|
|
6005
7257
|
// src/index.ts
|
|
6006
|
-
var VERSION = "1.6.
|
|
7258
|
+
var VERSION = "1.6.219";
|
|
6007
7259
|
export {
|
|
6008
7260
|
AddBoardCommentCommand,
|
|
6009
7261
|
AddBoardElementsCommand,
|
|
@@ -6015,17 +7267,24 @@ export {
|
|
|
6015
7267
|
BoardIoService,
|
|
6016
7268
|
BoardSelectionService,
|
|
6017
7269
|
BoardUnitModel,
|
|
7270
|
+
CastBoardSessionVoteCommand,
|
|
6018
7271
|
DeleteBoardElementsCommand,
|
|
7272
|
+
EndBoardVotingSessionCommand,
|
|
6019
7273
|
GroupBoardElementsInFrameCommand,
|
|
6020
7274
|
IBoardIoService,
|
|
6021
7275
|
IBoardSelectionService,
|
|
7276
|
+
ImportDocumentPagesToBoardCommand,
|
|
6022
7277
|
ImportMermaidToBoardCommand,
|
|
6023
7278
|
LayoutBoardMindmapCommand,
|
|
6024
7279
|
MERMAID_PRESET_TEMPLATES,
|
|
6025
7280
|
MINDMAP_BRANCH_PALETTE,
|
|
6026
7281
|
ReplaceBoardSnapshotCommand,
|
|
7282
|
+
RevealPrivateBrainstormCommand,
|
|
6027
7283
|
SetBoardViewportCommand,
|
|
6028
7284
|
SetBoardViewportMutation,
|
|
7285
|
+
StartBoardVotingSessionCommand,
|
|
7286
|
+
StartPrivateBrainstormCommand,
|
|
7287
|
+
StopPrivateBrainstormCommand,
|
|
6029
7288
|
UNIVER_BOARDS_PLUGIN_NAME,
|
|
6030
7289
|
UniverBoardsPlugin,
|
|
6031
7290
|
UpdateBoardElementsCommand,
|
|
@@ -6035,6 +7294,7 @@ export {
|
|
|
6035
7294
|
buildShapeSvgPath,
|
|
6036
7295
|
computeBoardBounds,
|
|
6037
7296
|
computeBoardConnectorPath,
|
|
7297
|
+
computeBoardVotingLeaderboard,
|
|
6038
7298
|
createDefaultBoardElement,
|
|
6039
7299
|
createDefaultBoardUnitData,
|
|
6040
7300
|
createSampleArchitectureBoardData,
|
|
@@ -6049,7 +7309,11 @@ export {
|
|
|
6049
7309
|
getElementPortPoint,
|
|
6050
7310
|
getMindmapDescendantIds,
|
|
6051
7311
|
importCsvToBoardStickies,
|
|
7312
|
+
importDeckOrPdfToBoardFrames,
|
|
7313
|
+
importPdfBytesToBoardElements,
|
|
7314
|
+
importPptxBytesToBoardElements,
|
|
6052
7315
|
isMindmapNodeCollapsedHidden,
|
|
7316
|
+
isStickyMaskedForViewer,
|
|
6053
7317
|
layoutBoardMindmap,
|
|
6054
7318
|
parseMermaidToBoardElements,
|
|
6055
7319
|
parseRfc4180Csv,
|