@memberjunction/core-entities 6.3.0-edge.0 → 6.3.0-edge.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/dist/.tsbuildinfo +1 -1
- package/dist/custom/AnchoredConversationSecurity.d.ts +10 -1
- package/dist/custom/AnchoredConversationSecurity.d.ts.map +1 -1
- package/dist/custom/AnchoredConversationSecurity.js +15 -0
- package/dist/custom/AnchoredConversationSecurity.js.map +1 -1
- package/dist/custom/ArtifactLockValidation.d.ts +28 -0
- package/dist/custom/ArtifactLockValidation.d.ts.map +1 -0
- package/dist/custom/ArtifactLockValidation.js +867 -0
- package/dist/custom/ArtifactLockValidation.js.map +1 -0
- package/dist/custom/ArtifactPermissionDelegate.d.ts +288 -0
- package/dist/custom/ArtifactPermissionDelegate.d.ts.map +1 -0
- package/dist/custom/ArtifactPermissionDelegate.js +1779 -0
- package/dist/custom/ArtifactPermissionDelegate.js.map +1 -0
- package/dist/custom/ArtifactPreviewSnapshot.d.ts +199 -0
- package/dist/custom/ArtifactPreviewSnapshot.d.ts.map +1 -0
- package/dist/custom/ArtifactPreviewSnapshot.js +772 -0
- package/dist/custom/ArtifactPreviewSnapshot.js.map +1 -0
- package/dist/custom/ArtifactSynthesisEngine.d.ts +151 -0
- package/dist/custom/ArtifactSynthesisEngine.d.ts.map +1 -0
- package/dist/custom/ArtifactSynthesisEngine.js +1124 -0
- package/dist/custom/ArtifactSynthesisEngine.js.map +1 -0
- package/dist/custom/ConversationWriteAccess.d.ts +36 -0
- package/dist/custom/ConversationWriteAccess.d.ts.map +1 -1
- package/dist/custom/ConversationWriteAccess.js +109 -1
- package/dist/custom/ConversationWriteAccess.js.map +1 -1
- package/dist/custom/DocumentLiveBlockEngine.d.ts +612 -0
- package/dist/custom/DocumentLiveBlockEngine.d.ts.map +1 -0
- package/dist/custom/DocumentLiveBlockEngine.js +2352 -0
- package/dist/custom/DocumentLiveBlockEngine.js.map +1 -0
- package/dist/custom/MJQueryEntityExtended.d.ts.map +1 -1
- package/dist/custom/MJQueryEntityExtended.js +27 -11
- package/dist/custom/MJQueryEntityExtended.js.map +1 -1
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.d.ts.map +1 -1
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.js +31 -7
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.js.map +1 -1
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.d.ts +3 -4
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.d.ts.map +1 -1
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.js +334 -47
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.js.map +1 -1
- package/dist/custom/Permissions/BaseShareEntityExtended.d.ts +28 -3
- package/dist/custom/Permissions/BaseShareEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/BaseShareEntityExtended.js +150 -13
- package/dist/custom/Permissions/BaseShareEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts +8 -6
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js +107 -43
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts +13 -5
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js +284 -49
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.d.ts +3 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.js +83 -19
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/shareNotification.d.ts +14 -1
- package/dist/custom/Permissions/shareNotification.d.ts.map +1 -1
- package/dist/custom/Permissions/shareNotification.js +62 -8
- package/dist/custom/Permissions/shareNotification.js.map +1 -1
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js +120 -38
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js.map +1 -1
- package/dist/custom/SlideDeckEngine.d.ts +469 -0
- package/dist/custom/SlideDeckEngine.d.ts.map +1 -0
- package/dist/custom/SlideDeckEngine.js +2168 -0
- package/dist/custom/SlideDeckEngine.js.map +1 -0
- package/dist/custom/SlideDeckPptxEngine.d.ts +25 -0
- package/dist/custom/SlideDeckPptxEngine.d.ts.map +1 -0
- package/dist/custom/SlideDeckPptxEngine.js +1311 -0
- package/dist/custom/SlideDeckPptxEngine.js.map +1 -0
- package/dist/custom/SpreadsheetEngine.d.ts +1377 -0
- package/dist/custom/SpreadsheetEngine.d.ts.map +1 -0
- package/dist/custom/SpreadsheetEngine.js +17652 -0
- package/dist/custom/SpreadsheetEngine.js.map +1 -0
- package/dist/custom/approvals.d.ts +31 -1
- package/dist/custom/approvals.d.ts.map +1 -1
- package/dist/custom/approvals.js +42 -2
- package/dist/custom/approvals.js.map +1 -1
- package/dist/custom/operations/ArtifactComplianceAuditOperation.d.ts +7 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.js +7 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.js.map +1 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.d.ts +7 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.js +7 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.js.map +1 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.d.ts +60 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.js +6 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.js.map +1 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.d.ts +7 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.d.ts.map +1 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.js +7 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.js.map +1 -0
- package/dist/custom/typedQuery.d.ts +162 -0
- package/dist/custom/typedQuery.d.ts.map +1 -0
- package/dist/custom/typedQuery.js +296 -0
- package/dist/custom/typedQuery.js.map +1 -0
- package/dist/engines/CanonGraphEngine.d.ts +115 -2
- package/dist/engines/CanonGraphEngine.d.ts.map +1 -1
- package/dist/engines/CanonGraphEngine.js +259 -34
- package/dist/engines/CanonGraphEngine.js.map +1 -1
- package/dist/engines/EncryptionEngineBase.js +2 -2
- package/dist/engines/EncryptionEngineBase.js.map +1 -1
- package/dist/engines/QueryEngine.js +2 -2
- package/dist/engines/QueryEngine.js.map +1 -1
- package/dist/engines/SearchEngineBase.d.ts +17 -3
- package/dist/engines/SearchEngineBase.d.ts.map +1 -1
- package/dist/engines/SearchEngineBase.js +100 -28
- package/dist/engines/SearchEngineBase.js.map +1 -1
- package/dist/engines/UserInfoEngine.d.ts +8 -0
- package/dist/engines/UserInfoEngine.d.ts.map +1 -1
- package/dist/engines/UserInfoEngine.js +50 -3
- package/dist/engines/UserInfoEngine.js.map +1 -1
- package/dist/engines/conversations.d.ts +74 -6
- package/dist/engines/conversations.d.ts.map +1 -1
- package/dist/engines/conversations.js +205 -24
- package/dist/engines/conversations.js.map +1 -1
- package/dist/generated/entities/__mj.d.ts +25652 -43408
- package/dist/generated/entities/__mj.d.ts.map +1 -1
- package/dist/generated/entities/__mj.js +50800 -83602
- package/dist/generated/entities/__mj.js.map +1 -1
- package/dist/generated/queries/__mj.d.ts +12 -12
- package/dist/generated/queries/__mj.d.ts.map +1 -1
- package/dist/generated/queries/__mj.js +1 -1
- package/dist/generated/queries/__mj.js.map +1 -1
- package/dist/generated/remote_operations.d.ts +970 -65
- package/dist/generated/remote_operations.d.ts.map +1 -1
- package/dist/generated/remote_operations.js +343 -8
- package/dist/generated/remote_operations.js.map +1 -1
- package/dist/generated/schemas/__mj.d.ts +27415 -0
- package/dist/generated/schemas/__mj.d.ts.map +1 -0
- package/dist/generated/schemas/__mj.js +45127 -0
- package/dist/generated/schemas/__mj.js.map +1 -0
- package/dist/generated/schemas.d.ts +2 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +2 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/graph/BaseGraphEdgeProvider.d.ts +33 -1
- package/dist/graph/BaseGraphEdgeProvider.d.ts.map +1 -1
- package/dist/graph/BaseGraphEdgeProvider.js +18 -3
- package/dist/graph/BaseGraphEdgeProvider.js.map +1 -1
- package/dist/graph/CanonDocumentRenderer.d.ts +43 -0
- package/dist/graph/CanonDocumentRenderer.d.ts.map +1 -0
- package/dist/graph/CanonDocumentRenderer.js +627 -0
- package/dist/graph/CanonDocumentRenderer.js.map +1 -0
- package/dist/graph/DomainClustering.d.ts +88 -0
- package/dist/graph/DomainClustering.d.ts.map +1 -0
- package/dist/graph/DomainClustering.js +327 -0
- package/dist/graph/DomainClustering.js.map +1 -0
- package/dist/graph/DomainProposalWriter.d.ts +25 -0
- package/dist/graph/DomainProposalWriter.d.ts.map +1 -0
- package/dist/graph/DomainProposalWriter.js +107 -0
- package/dist/graph/DomainProposalWriter.js.map +1 -0
- package/dist/graph/GraphAccessPolicy.d.ts +111 -0
- package/dist/graph/GraphAccessPolicy.d.ts.map +1 -0
- package/dist/graph/GraphAccessPolicy.js +123 -0
- package/dist/graph/GraphAccessPolicy.js.map +1 -0
- package/dist/graph/GraphEngine.d.ts +115 -7
- package/dist/graph/GraphEngine.d.ts.map +1 -1
- package/dist/graph/GraphEngine.js +432 -36
- package/dist/graph/GraphEngine.js.map +1 -1
- package/dist/graph/RecordRelations.d.ts +52 -0
- package/dist/graph/RecordRelations.d.ts.map +1 -0
- package/dist/graph/RecordRelations.js +90 -0
- package/dist/graph/RecordRelations.js.map +1 -0
- package/dist/graph/index.d.ts +9 -1
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +13 -1
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/policies/ProvenanceAccessPolicies.d.ts +56 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.d.ts.map +1 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.js +228 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.js.map +1 -0
- package/dist/graph/providers/QueryEdgeProvider.d.ts.map +1 -1
- package/dist/graph/providers/QueryEdgeProvider.js +2 -2
- package/dist/graph/providers/QueryEdgeProvider.js.map +1 -1
- package/dist/graph/providers/RecordLinkEdgeProvider.d.ts.map +1 -1
- package/dist/graph/providers/RecordLinkEdgeProvider.js +2 -2
- package/dist/graph/providers/RecordLinkEdgeProvider.js.map +1 -1
- package/dist/graph/providers/SharedConceptEdgeProvider.d.ts +54 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.js +282 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/schemas.d.ts +6 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +6 -0
- package/dist/schemas.js.map +1 -0
- package/package.json +17 -6
|
@@ -0,0 +1,1311 @@
|
|
|
1
|
+
import { BuildBlockIdentityBinding, DocumentLiveBlockEngine, ValidateFrozenBlockSnapshot } from './DocumentLiveBlockEngine.js';
|
|
2
|
+
import { SpreadsheetEngine } from './SpreadsheetEngine.js';
|
|
3
|
+
const SLIDE_W_16_9 = 12192000;
|
|
4
|
+
const SLIDE_W_4_3 = 9144000;
|
|
5
|
+
const SLIDE_H_STD = 6858000;
|
|
6
|
+
const REL_TYPE_SLIDE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide';
|
|
7
|
+
const REL_TYPE_SLIDE_LAYOUT = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout';
|
|
8
|
+
const REL_TYPE_SLIDE_MASTER = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster';
|
|
9
|
+
const REL_TYPE_NOTES_SLIDE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide';
|
|
10
|
+
const REL_TYPE_NOTES_MASTER = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster';
|
|
11
|
+
const REL_TYPE_THEME = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme';
|
|
12
|
+
const REL_TYPE_CHART = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart';
|
|
13
|
+
const REL_TYPE_OFFICE_DOC = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument';
|
|
14
|
+
const REL_TYPE_CORE_PROPS = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties';
|
|
15
|
+
const REL_TYPE_EXT_PROPS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties';
|
|
16
|
+
const REL_TYPE_CUSTOM_PROPS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties';
|
|
17
|
+
/**
|
|
18
|
+
* Strips illegal XML 1.0 control characters (`U+0000`–`U+0008`, `U+000B`, `U+000C`,
|
|
19
|
+
* `U+000E`–`U+001F`, `U+FFFE`, `U+FFFF`) and escapes XML predefined entities.
|
|
20
|
+
*/
|
|
21
|
+
function escapePptxXml(raw) {
|
|
22
|
+
const cleaned = String(raw ?? '').replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g, '');
|
|
23
|
+
return cleaned
|
|
24
|
+
.replace(/&/g, '&')
|
|
25
|
+
.replace(/</g, '<')
|
|
26
|
+
.replace(/>/g, '>')
|
|
27
|
+
.replace(/"/g, '"')
|
|
28
|
+
.replace(/'/g, ''');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Unescapes XML predefined entities, numeric entities (` `, `
`, etc.), and OOXML `_xHHHH_` escapes.
|
|
32
|
+
*/
|
|
33
|
+
function unescapePptxXml(raw) {
|
|
34
|
+
const withOoxml = String(raw ?? '').replace(/_x([0-9A-Fa-f]{4})_/g, (_m, hex) => {
|
|
35
|
+
const code = parseInt(hex, 16);
|
|
36
|
+
if (code === 0x005f)
|
|
37
|
+
return '_';
|
|
38
|
+
if (code === 0x0009 || code === 0x000a || code === 0x000d) {
|
|
39
|
+
return String.fromCharCode(code);
|
|
40
|
+
}
|
|
41
|
+
return code >= 0x20 ? String.fromCharCode(code) : '';
|
|
42
|
+
});
|
|
43
|
+
const withNumeric = withOoxml
|
|
44
|
+
.replace(/&#x([0-9A-Fa-f]+);/gi, (_m, hex) => {
|
|
45
|
+
const cp = parseInt(hex, 16);
|
|
46
|
+
if (!Number.isFinite(cp) || cp < 0 || cp > 0x10ffff)
|
|
47
|
+
return '';
|
|
48
|
+
if ((cp < 0x20 && cp !== 0x09 && cp !== 0x0a && cp !== 0x0d) || cp === 0xfffe || cp === 0xffff) {
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
return String.fromCodePoint(cp);
|
|
52
|
+
})
|
|
53
|
+
.replace(/&#(\d+);/g, (_m, dec) => {
|
|
54
|
+
const cp = parseInt(dec, 10);
|
|
55
|
+
if (!Number.isFinite(cp) || cp < 0 || cp > 0x10ffff)
|
|
56
|
+
return '';
|
|
57
|
+
if ((cp < 0x20 && cp !== 0x09 && cp !== 0x0a && cp !== 0x0d) || cp === 0xfffe || cp === 0xffff) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
return String.fromCodePoint(cp);
|
|
61
|
+
});
|
|
62
|
+
return withNumeric
|
|
63
|
+
.replace(/'/g, "'")
|
|
64
|
+
.replace(/"/g, '"')
|
|
65
|
+
.replace(/>/g, '>')
|
|
66
|
+
.replace(/</g, '<')
|
|
67
|
+
.replace(/&/g, '&');
|
|
68
|
+
}
|
|
69
|
+
function toDrawingHexColor(cssColor, fallbackHex) {
|
|
70
|
+
const trimmed = String(cssColor ?? '').trim();
|
|
71
|
+
const m = /^#([0-9a-f]{3}|[0-9a-f]{6})(?:[0-9a-f]{2})?$/i.exec(trimmed);
|
|
72
|
+
if (!m)
|
|
73
|
+
return fallbackHex;
|
|
74
|
+
const raw = m[1].toUpperCase();
|
|
75
|
+
if (raw.length === 3) {
|
|
76
|
+
return `${raw[0]}${raw[0]}${raw[1]}${raw[1]}${raw[2]}${raw[2]}`;
|
|
77
|
+
}
|
|
78
|
+
return raw;
|
|
79
|
+
}
|
|
80
|
+
function primaryFontName(fontStack, fallback) {
|
|
81
|
+
const first = String(fontStack ?? '')
|
|
82
|
+
.split(',')[0]
|
|
83
|
+
?.trim()
|
|
84
|
+
.replace(/^['"]|['"]$/g, '');
|
|
85
|
+
return first && /^[A-Za-z0-9\s._-]+$/.test(first) ? first : fallback;
|
|
86
|
+
}
|
|
87
|
+
function normalizePptxRelTarget(baseDir, target) {
|
|
88
|
+
const cleaned = String(target ?? '').replace(/\\/g, '/').trim();
|
|
89
|
+
if (!cleaned || /^https?:\/\//i.test(cleaned) || cleaned.startsWith('//')) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const rawSegments = cleaned.startsWith('/')
|
|
93
|
+
? cleaned.slice(1).split('/')
|
|
94
|
+
: [...(baseDir ? baseDir.split('/').filter(Boolean) : []), ...cleaned.split('/')];
|
|
95
|
+
const resolved = [];
|
|
96
|
+
for (const seg of rawSegments) {
|
|
97
|
+
if (!seg || seg === '.')
|
|
98
|
+
continue;
|
|
99
|
+
if (seg === '..') {
|
|
100
|
+
if (resolved.length === 0) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
resolved.pop();
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
resolved.push(seg);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return resolved.join('/');
|
|
110
|
+
}
|
|
111
|
+
function parseRelsXml(xml) {
|
|
112
|
+
const rels = [];
|
|
113
|
+
const relRe = /<Relationship\b([^>]*?)\/?>(?:<\/Relationship>)?/gi;
|
|
114
|
+
let m;
|
|
115
|
+
while ((m = relRe.exec(xml)) !== null) {
|
|
116
|
+
const attrs = m[1];
|
|
117
|
+
const id = /\bId="([^"]*)"/i.exec(attrs)?.[1] ?? '';
|
|
118
|
+
const type = /\bType="([^"]*)"/i.exec(attrs)?.[1] ?? '';
|
|
119
|
+
const target = /\bTarget="([^"]*)"/i.exec(attrs)?.[1] ?? '';
|
|
120
|
+
if (id && target) {
|
|
121
|
+
rels.push({
|
|
122
|
+
Id: unescapePptxXml(id),
|
|
123
|
+
Type: unescapePptxXml(type),
|
|
124
|
+
Target: unescapePptxXml(target)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return rels;
|
|
129
|
+
}
|
|
130
|
+
function buildTextParagraphsXml(text, options) {
|
|
131
|
+
const lines = String(text ?? '')
|
|
132
|
+
.replace(/\r\n/g, '\n')
|
|
133
|
+
.split('\n');
|
|
134
|
+
if (lines.length === 0) {
|
|
135
|
+
return `<a:p><a:pPr algn="${options.align ?? 'l'}"/><a:endParaRPr lang="en-US" sz="${options.fontSizeHundredthsPt}"/></a:p>`;
|
|
136
|
+
}
|
|
137
|
+
return lines
|
|
138
|
+
.map((line) => {
|
|
139
|
+
const trimmed = line.trim();
|
|
140
|
+
const isBullet = options.bullet && /^[-*]\s+/.test(trimmed);
|
|
141
|
+
const cleanLine = isBullet ? trimmed.replace(/^[-*]\s+/, '') : line;
|
|
142
|
+
const boldFlag = options.bold ? ' b="1"' : '';
|
|
143
|
+
const italicFlag = options.italic ? ' i="1"' : '';
|
|
144
|
+
const bulletXml = isBullet ? '<a:buChar char="•"/>' : '<a:buNone/>';
|
|
145
|
+
const rPr = `<a:rPr lang="en-US" sz="${options.fontSizeHundredthsPt}"${boldFlag}${italicFlag} dirty="0">` +
|
|
146
|
+
`<a:solidFill><a:srgbClr val="${options.colorHex}"/></a:solidFill>` +
|
|
147
|
+
`<a:latin typeface="${escapePptxXml(options.fontFace)}"/>` +
|
|
148
|
+
`</a:rPr>`;
|
|
149
|
+
if (!cleanLine) {
|
|
150
|
+
return `<a:p><a:pPr algn="${options.align ?? 'l'}">${bulletXml}</a:pPr><a:endParaRPr lang="en-US" sz="${options.fontSizeHundredthsPt}"/></a:p>`;
|
|
151
|
+
}
|
|
152
|
+
return (`<a:p>` +
|
|
153
|
+
`<a:pPr algn="${options.align ?? 'l'}">${bulletXml}</a:pPr>` +
|
|
154
|
+
`<a:r>${rPr}<a:t>${escapePptxXml(cleanLine)}</a:t></a:r>` +
|
|
155
|
+
`<a:endParaRPr lang="en-US" sz="${options.fontSizeHundredthsPt}"/>` +
|
|
156
|
+
`</a:p>`);
|
|
157
|
+
})
|
|
158
|
+
.join('');
|
|
159
|
+
}
|
|
160
|
+
function buildTextShapeXml(params) {
|
|
161
|
+
const phXml = params.placeholderType ? `<p:nvPr><p:ph type="${params.placeholderType}"/></p:nvPr>` : '<p:nvPr/>';
|
|
162
|
+
const fillXml = params.fillHex
|
|
163
|
+
? `<a:solidFill><a:srgbClr val="${params.fillHex}"/></a:solidFill>`
|
|
164
|
+
: '<a:noFill/>';
|
|
165
|
+
const lnXml = params.borderHex
|
|
166
|
+
? `<a:ln w="12700"><a:solidFill><a:srgbClr val="${params.borderHex}"/></a:solidFill></a:ln>`
|
|
167
|
+
: '<a:ln><a:noFill/></a:ln>';
|
|
168
|
+
const bodyXml = buildTextParagraphsXml(params.text, {
|
|
169
|
+
fontSizeHundredthsPt: Math.round(params.fontSizePt * 100),
|
|
170
|
+
bold: params.bold,
|
|
171
|
+
italic: params.italic,
|
|
172
|
+
colorHex: params.colorHex,
|
|
173
|
+
fontFace: params.fontFace,
|
|
174
|
+
align: params.align,
|
|
175
|
+
bullet: params.bullet
|
|
176
|
+
});
|
|
177
|
+
return [
|
|
178
|
+
'<p:sp>',
|
|
179
|
+
'<p:nvSpPr>',
|
|
180
|
+
`<p:cNvPr id="${params.shapeId}" name="${escapePptxXml(params.name)}"/>`,
|
|
181
|
+
'<p:cNvSpPr/>',
|
|
182
|
+
phXml,
|
|
183
|
+
'</p:nvSpPr>',
|
|
184
|
+
'<p:spPr>',
|
|
185
|
+
`<a:xfrm><a:off x="${Math.round(params.x)}" y="${Math.round(params.y)}"/><a:ext cx="${Math.round(params.cx)}" cy="${Math.round(params.cy)}"/></a:xfrm>`,
|
|
186
|
+
'<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>',
|
|
187
|
+
fillXml,
|
|
188
|
+
lnXml,
|
|
189
|
+
'</p:spPr>',
|
|
190
|
+
'<p:txBody>',
|
|
191
|
+
'<a:bodyPr wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720"/>',
|
|
192
|
+
'<a:lstStyle/>',
|
|
193
|
+
bodyXml,
|
|
194
|
+
'</p:txBody>',
|
|
195
|
+
'</p:sp>'
|
|
196
|
+
].join('');
|
|
197
|
+
}
|
|
198
|
+
function parseMarkdownTableRows(markdown) {
|
|
199
|
+
const lines = String(markdown ?? '')
|
|
200
|
+
.replace(/\r\n/g, '\n')
|
|
201
|
+
.split('\n')
|
|
202
|
+
.map((l) => l.trim())
|
|
203
|
+
.filter((l) => l.length > 0);
|
|
204
|
+
if (lines.length < 2)
|
|
205
|
+
return null;
|
|
206
|
+
if (!lines.every((l) => l.startsWith('|')))
|
|
207
|
+
return null;
|
|
208
|
+
if (!/^\|[\s:|-]+\|?$/.test(lines[1]))
|
|
209
|
+
return null;
|
|
210
|
+
const rows = [];
|
|
211
|
+
for (let i = 0; i < lines.length; i++) {
|
|
212
|
+
if (i === 1 && /^\|[\s:|-]+\|?$/.test(lines[i]))
|
|
213
|
+
continue;
|
|
214
|
+
const cells = lines[i]
|
|
215
|
+
.replace(/^\|/, '')
|
|
216
|
+
.replace(/\|$/, '')
|
|
217
|
+
.split('|')
|
|
218
|
+
.map((c) => c.trim());
|
|
219
|
+
rows.push(cells);
|
|
220
|
+
}
|
|
221
|
+
return rows.length > 0 ? rows : null;
|
|
222
|
+
}
|
|
223
|
+
function buildTableGraphicFrameXml(params) {
|
|
224
|
+
const colCount = Math.max(1, params.headers.length);
|
|
225
|
+
const colWidth = Math.max(457200, Math.floor(params.cx / colCount));
|
|
226
|
+
const gridColsXml = Array.from({ length: colCount }, () => `<a:gridCol w="${colWidth}"/>`).join('');
|
|
227
|
+
const buildCell = (cellText, isHeader, rowIdx) => {
|
|
228
|
+
const bgHex = isHeader ? params.primaryHex : rowIdx % 2 === 0 ? 'FFFFFF' : params.surfaceHex;
|
|
229
|
+
const fgHex = isHeader ? 'FFFFFF' : params.textHex;
|
|
230
|
+
const pXml = buildTextParagraphsXml(cellText, {
|
|
231
|
+
fontSizeHundredthsPt: isHeader ? 1200 : 1100,
|
|
232
|
+
bold: isHeader,
|
|
233
|
+
colorHex: fgHex,
|
|
234
|
+
fontFace: params.fontFace
|
|
235
|
+
});
|
|
236
|
+
return (`<a:tc>` +
|
|
237
|
+
`<a:txBody><a:bodyPr/><a:lstStyle/>${pXml}</a:txBody>` +
|
|
238
|
+
`<a:tcPr><a:solidFill><a:srgbClr val="${bgHex}"/></a:solidFill></a:tcPr>` +
|
|
239
|
+
`</a:tc>`);
|
|
240
|
+
};
|
|
241
|
+
const headerRowXml = `<a:tr h="370840">` +
|
|
242
|
+
Array.from({ length: colCount }, (_, idx) => buildCell(params.headers[idx] ?? '', true, -1)).join('') +
|
|
243
|
+
`</a:tr>`;
|
|
244
|
+
const bodyRowsXml = params.rows
|
|
245
|
+
.slice(0, 25)
|
|
246
|
+
.map((r, rIdx) => `<a:tr h="340000">` +
|
|
247
|
+
Array.from({ length: colCount }, (_, idx) => buildCell(r[idx] ?? '', false, rIdx)).join('') +
|
|
248
|
+
`</a:tr>`)
|
|
249
|
+
.join('');
|
|
250
|
+
return [
|
|
251
|
+
'<p:graphicFrame>',
|
|
252
|
+
'<p:nvGraphicFramePr>',
|
|
253
|
+
`<p:cNvPr id="${params.shapeId}" name="${escapePptxXml(params.name)}"/>`,
|
|
254
|
+
'<p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr>',
|
|
255
|
+
'<p:nvPr/>',
|
|
256
|
+
'</p:nvGraphicFramePr>',
|
|
257
|
+
`<p:xfrm><a:off x="${Math.round(params.x)}" y="${Math.round(params.y)}"/><a:ext cx="${Math.round(params.cx)}" cy="${Math.round(params.cy)}"/></p:xfrm>`,
|
|
258
|
+
'<a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">',
|
|
259
|
+
`<a:tbl><a:tblPr firstRow="1" bandRow="1"/><a:tblGrid>${gridColsXml}</a:tblGrid>${headerRowXml}${bodyRowsXml}</a:tbl>`,
|
|
260
|
+
'</a:graphicData></a:graphic>',
|
|
261
|
+
'</p:graphicFrame>'
|
|
262
|
+
].join('');
|
|
263
|
+
}
|
|
264
|
+
function tryExtractChartDataFromSnapshot(block, regionLabel) {
|
|
265
|
+
const snap = block.FrozenSnapshot;
|
|
266
|
+
if (!snap || !Array.isArray(snap.Columns) || !Array.isArray(snap.Rows) || snap.Rows.length === 0) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
const wantsChart = block.DisplayMode === 'chart' ||
|
|
270
|
+
Boolean(block.ChartType) ||
|
|
271
|
+
Boolean(block.SheetChartID);
|
|
272
|
+
if (!wantsChart) {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
const numericCols = [];
|
|
276
|
+
let categoryCol = null;
|
|
277
|
+
for (const col of snap.Columns) {
|
|
278
|
+
const vals = snap.Rows.map((r) => r[col.Name]);
|
|
279
|
+
const numericCount = vals.filter((v) => typeof v === 'number' && Number.isFinite(v)).length;
|
|
280
|
+
if (numericCount > 0 && numericCount >= Math.ceil(snap.Rows.length * 0.5)) {
|
|
281
|
+
numericCols.push(col);
|
|
282
|
+
}
|
|
283
|
+
else if (!categoryCol) {
|
|
284
|
+
categoryCol = col;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (numericCols.length === 0) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
const resolvedCategoryCol = categoryCol ?? snap.Columns[0];
|
|
291
|
+
const seriesCols = numericCols.filter((c) => c.Name !== resolvedCategoryCol.Name || numericCols.length === 1);
|
|
292
|
+
if (seriesCols.length === 0) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
const categories = snap.Rows.slice(0, 40).map((r, idx) => {
|
|
296
|
+
const raw = r[resolvedCategoryCol.Name];
|
|
297
|
+
return raw !== null && raw !== undefined && String(raw).trim() !== '' ? String(raw) : `Item ${idx + 1}`;
|
|
298
|
+
});
|
|
299
|
+
const series = seriesCols.map((sc) => ({
|
|
300
|
+
Name: sc.DisplayName || sc.Name,
|
|
301
|
+
Values: snap.Rows.slice(0, 40).map((r) => {
|
|
302
|
+
const v = r[sc.Name];
|
|
303
|
+
return typeof v === 'number' && Number.isFinite(v) ? v : 0;
|
|
304
|
+
})
|
|
305
|
+
}));
|
|
306
|
+
return {
|
|
307
|
+
Title: block.Title || regionLabel || 'Chart',
|
|
308
|
+
ChartType: block.ChartType ?? 'bar',
|
|
309
|
+
Categories: categories,
|
|
310
|
+
Series: series
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function buildDrawingMlChartXml(chart, paletteHex) {
|
|
314
|
+
const chartTag = chart.ChartType === 'line'
|
|
315
|
+
? 'lineChart'
|
|
316
|
+
: chart.ChartType === 'pie'
|
|
317
|
+
? 'pieChart'
|
|
318
|
+
: chart.ChartType === 'area'
|
|
319
|
+
? 'areaChart'
|
|
320
|
+
: 'barChart';
|
|
321
|
+
const catPts = chart.Categories.map((cat, idx) => `<c:pt idx="${idx}"><c:v>${escapePptxXml(cat)}</c:v></c:pt>`).join('');
|
|
322
|
+
const catCount = chart.Categories.length;
|
|
323
|
+
const seriesXml = chart.Series.map((ser, sIdx) => {
|
|
324
|
+
const colorHex = paletteHex[sIdx % paletteHex.length] || '4F46E5';
|
|
325
|
+
const valPts = ser.Values.map((v, idx) => `<c:pt idx="${idx}"><c:v>${Number.isFinite(v) ? v : 0}</c:v></c:pt>`).join('');
|
|
326
|
+
return [
|
|
327
|
+
'<c:ser>',
|
|
328
|
+
`<c:idx val="${sIdx}"/>`,
|
|
329
|
+
`<c:order val="${sIdx}"/>`,
|
|
330
|
+
`<c:tx><c:v>${escapePptxXml(ser.Name)}</c:v></c:tx>`,
|
|
331
|
+
`<c:spPr><a:solidFill><a:srgbClr val="${colorHex}"/></a:solidFill></c:spPr>`,
|
|
332
|
+
`<c:cat><c:strLit><c:ptCount val="${catCount}"/>${catPts}</c:strLit></c:cat>`,
|
|
333
|
+
`<c:val><c:numLit><c:formatCode>General</c:formatCode><c:ptCount val="${ser.Values.length}"/>${valPts}</c:numLit></c:val>`,
|
|
334
|
+
'</c:ser>'
|
|
335
|
+
].join('');
|
|
336
|
+
}).join('');
|
|
337
|
+
const barExtra = chartTag === 'barChart' ? '<c:barDir val="col"/><c:grouping val="clustered"/>' : '';
|
|
338
|
+
const lineAreaExtra = chartTag === 'lineChart' || chartTag === 'areaChart' ? '<c:grouping val="standard"/>' : '';
|
|
339
|
+
const axesDecl = chartTag === 'pieChart'
|
|
340
|
+
? ''
|
|
341
|
+
: '<c:axId val="1001"/><c:axId val="1002"/>';
|
|
342
|
+
const axesXml = chartTag === 'pieChart'
|
|
343
|
+
? ''
|
|
344
|
+
: '<c:catAx><c:axId val="1001"/><c:scaling><c:orientation val="minMax"/></c:scaling><c:delete val="0"/><c:axPos val="b"/><c:crossAx val="1002"/></c:catAx>' +
|
|
345
|
+
'<c:valAx><c:axId val="1002"/><c:scaling><c:orientation val="minMax"/></c:scaling><c:delete val="0"/><c:axPos val="l"/><c:crossAx val="1001"/></c:valAx>';
|
|
346
|
+
return [
|
|
347
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
348
|
+
'<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">',
|
|
349
|
+
'<c:lang val="en-US"/>',
|
|
350
|
+
'<c:chart>',
|
|
351
|
+
`<c:title><c:tx><c:rich><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>${escapePptxXml(chart.Title)}</a:t></a:r></a:p></c:rich></c:tx><c:overlay val="0"/></c:title>`,
|
|
352
|
+
'<c:plotArea>',
|
|
353
|
+
'<c:layout/>',
|
|
354
|
+
`<c:${chartTag}>${barExtra}${lineAreaExtra}${seriesXml}${axesDecl}</c:${chartTag}>`,
|
|
355
|
+
axesXml,
|
|
356
|
+
'</c:plotArea>',
|
|
357
|
+
'<c:legend><c:legendPos val="b"/><c:overlay val="0"/></c:legend>',
|
|
358
|
+
'</c:chart>',
|
|
359
|
+
'</c:chartSpace>'
|
|
360
|
+
].join('');
|
|
361
|
+
}
|
|
362
|
+
function buildChartGraphicFrameXml(params) {
|
|
363
|
+
return [
|
|
364
|
+
'<p:graphicFrame>',
|
|
365
|
+
'<p:nvGraphicFramePr>',
|
|
366
|
+
`<p:cNvPr id="${params.shapeId}" name="${escapePptxXml(params.name)}"/>`,
|
|
367
|
+
'<p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr>',
|
|
368
|
+
'<p:nvPr/>',
|
|
369
|
+
'</p:nvGraphicFramePr>',
|
|
370
|
+
`<p:xfrm><a:off x="${Math.round(params.x)}" y="${Math.round(params.y)}"/><a:ext cx="${Math.round(params.cx)}" cy="${Math.round(params.cy)}"/></p:xfrm>`,
|
|
371
|
+
'<a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">',
|
|
372
|
+
`<c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="${escapePptxXml(params.relId)}"/>`,
|
|
373
|
+
'</a:graphicData></a:graphic>',
|
|
374
|
+
'</p:graphicFrame>'
|
|
375
|
+
].join('');
|
|
376
|
+
}
|
|
377
|
+
function buildTheme1Xml(theme) {
|
|
378
|
+
const primary = toDrawingHexColor(theme.PrimaryColor, '4F46E5');
|
|
379
|
+
const accent = toDrawingHexColor(theme.AccentColor, '0EA5E9');
|
|
380
|
+
const bg = toDrawingHexColor(theme.BackgroundColor, 'FFFFFF');
|
|
381
|
+
const surface = toDrawingHexColor(theme.SurfaceColor, 'F8FAFC');
|
|
382
|
+
const text = toDrawingHexColor(theme.TextColor, '0F172A');
|
|
383
|
+
const muted = toDrawingHexColor(theme.MutedTextColor, '475569');
|
|
384
|
+
const headingFont = primaryFontName(theme.HeadingFont, 'Calibri');
|
|
385
|
+
const bodyFont = primaryFontName(theme.BodyFont, 'Calibri');
|
|
386
|
+
return [
|
|
387
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
388
|
+
`<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="${escapePptxXml(theme.Name || 'MJTheme')}">`,
|
|
389
|
+
'<a:themeElements>',
|
|
390
|
+
`<a:clrScheme name="${escapePptxXml(theme.ThemeID || 'MJColors')}">`,
|
|
391
|
+
`<a:dk1><a:srgbClr val="${text}"/></a:dk1>`,
|
|
392
|
+
`<a:lt1><a:srgbClr val="${bg}"/></a:lt1>`,
|
|
393
|
+
`<a:dk2><a:srgbClr val="${muted}"/></a:dk2>`,
|
|
394
|
+
`<a:lt2><a:srgbClr val="${surface}"/></a:lt2>`,
|
|
395
|
+
`<a:accent1><a:srgbClr val="${primary}"/></a:accent1>`,
|
|
396
|
+
`<a:accent2><a:srgbClr val="${accent}"/></a:accent2>`,
|
|
397
|
+
'<a:accent3><a:srgbClr val="10B981"/></a:accent3>',
|
|
398
|
+
'<a:accent4><a:srgbClr val="F59E0B"/></a:accent4>',
|
|
399
|
+
'<a:accent5><a:srgbClr val="8B5CF6"/></a:accent5>',
|
|
400
|
+
'<a:accent6><a:srgbClr val="EC4899"/></a:accent6>',
|
|
401
|
+
`<a:hlink><a:srgbClr val="${accent}"/></a:hlink>`,
|
|
402
|
+
`<a:folHlink><a:srgbClr val="${primary}"/></a:folHlink>`,
|
|
403
|
+
'</a:clrScheme>',
|
|
404
|
+
'<a:fontScheme name="MJFonts">',
|
|
405
|
+
`<a:majorFont><a:latin typeface="${escapePptxXml(headingFont)}"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont>`,
|
|
406
|
+
`<a:minorFont><a:latin typeface="${escapePptxXml(bodyFont)}"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont>`,
|
|
407
|
+
'</a:fontScheme>',
|
|
408
|
+
// ECMA-376 requires exactly 3 items in each fmtScheme list (fill, ln, effect, bgFill)
|
|
409
|
+
'<a:fmtScheme name="MJFormat">',
|
|
410
|
+
'<a:fillStyleLst>',
|
|
411
|
+
'<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>',
|
|
412
|
+
'<a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="50000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill>',
|
|
413
|
+
'<a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill>',
|
|
414
|
+
'</a:fillStyleLst>',
|
|
415
|
+
'<a:lnStyleLst>',
|
|
416
|
+
'<a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln>',
|
|
417
|
+
'<a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln>',
|
|
418
|
+
'<a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln>',
|
|
419
|
+
'</a:lnStyleLst>',
|
|
420
|
+
'<a:effectStyleLst>',
|
|
421
|
+
'<a:effectStyle><a:effectLst/></a:effectStyle>',
|
|
422
|
+
'<a:effectStyle><a:effectLst/></a:effectStyle>',
|
|
423
|
+
'<a:effectStyle><a:effectLst/></a:effectStyle>',
|
|
424
|
+
'</a:effectStyleLst>',
|
|
425
|
+
'<a:bgFillStyleLst>',
|
|
426
|
+
'<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>',
|
|
427
|
+
'<a:solidFill><a:schemeClr val="phClr"><a:tint val="95000"/></a:schemeClr></a:solidFill>',
|
|
428
|
+
'<a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="60000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill>',
|
|
429
|
+
'</a:bgFillStyleLst>',
|
|
430
|
+
'</a:fmtScheme>',
|
|
431
|
+
'</a:themeElements>',
|
|
432
|
+
'</a:theme>'
|
|
433
|
+
].join('');
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Exports a {@link SlideDeckSpec} headlessly to valid ECMA-376 `.pptx` archive bytes (`NW-4`).
|
|
437
|
+
*/
|
|
438
|
+
export function ExportDeckToPptxBytesInternal(deck, options) {
|
|
439
|
+
const encoder = new TextEncoder();
|
|
440
|
+
const isFourByThree = deck.AspectRatio === '4:3';
|
|
441
|
+
const slideW = isFourByThree ? SLIDE_W_4_3 : SLIDE_W_16_9;
|
|
442
|
+
const slideH = SLIDE_H_STD;
|
|
443
|
+
const sldSzType = isFourByThree ? 'screen4x3' : 'screen16x9';
|
|
444
|
+
const includeHidden = options?.IncludeHiddenSlides === true;
|
|
445
|
+
const slidesToExport = (deck.Slides ?? []).filter((s) => includeHidden || !s.Hidden);
|
|
446
|
+
const primaryHex = toDrawingHexColor(deck.Theme?.PrimaryColor, '4F46E5');
|
|
447
|
+
const accentHex = toDrawingHexColor(deck.Theme?.AccentColor, '0EA5E9');
|
|
448
|
+
const bgHex = toDrawingHexColor(deck.Theme?.BackgroundColor, 'FFFFFF');
|
|
449
|
+
const surfaceHex = toDrawingHexColor(deck.Theme?.SurfaceColor, 'F8FAFC');
|
|
450
|
+
const textHex = toDrawingHexColor(deck.Theme?.TextColor, '0F172A');
|
|
451
|
+
const mutedHex = toDrawingHexColor(deck.Theme?.MutedTextColor, '475569');
|
|
452
|
+
const headingFont = primaryFontName(deck.Theme?.HeadingFont, 'Calibri');
|
|
453
|
+
const bodyFont = primaryFontName(deck.Theme?.BodyFont, 'Calibri');
|
|
454
|
+
const entries = [];
|
|
455
|
+
const chartPartNames = [];
|
|
456
|
+
const notesPartNames = [];
|
|
457
|
+
let chartCounter = 0;
|
|
458
|
+
const addXmlEntry = (name, xml) => {
|
|
459
|
+
entries.push({ Name: name, Data: encoder.encode(xml) });
|
|
460
|
+
};
|
|
461
|
+
// Core structural parts
|
|
462
|
+
addXmlEntry('ppt/theme/theme1.xml', buildTheme1Xml(deck.Theme));
|
|
463
|
+
addXmlEntry('ppt/slideLayouts/slideLayout1.xml', [
|
|
464
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
465
|
+
'<p:sldLayout xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" type="blank" preserve="1">',
|
|
466
|
+
'<p:cSld name="Blank"><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr></p:spTree></p:cSld>',
|
|
467
|
+
'<p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr>',
|
|
468
|
+
'</p:sldLayout>'
|
|
469
|
+
].join(''));
|
|
470
|
+
addXmlEntry('ppt/slideLayouts/_rels/slideLayout1.xml.rels', [
|
|
471
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
472
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">',
|
|
473
|
+
`<Relationship Id="rId1" Type="${REL_TYPE_SLIDE_MASTER}" Target="../slideMasters/slideMaster1.xml"/>`,
|
|
474
|
+
'</Relationships>'
|
|
475
|
+
].join(''));
|
|
476
|
+
addXmlEntry('ppt/slideMasters/slideMaster1.xml', [
|
|
477
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
478
|
+
'<p:sldMaster xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">',
|
|
479
|
+
'<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr></p:spTree></p:cSld>',
|
|
480
|
+
'<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>',
|
|
481
|
+
'<p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst>',
|
|
482
|
+
'</p:sldMaster>'
|
|
483
|
+
].join(''));
|
|
484
|
+
addXmlEntry('ppt/slideMasters/_rels/slideMaster1.xml.rels', [
|
|
485
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
486
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">',
|
|
487
|
+
`<Relationship Id="rId1" Type="${REL_TYPE_SLIDE_LAYOUT}" Target="../slideLayouts/slideLayout1.xml"/>`,
|
|
488
|
+
`<Relationship Id="rId2" Type="${REL_TYPE_THEME}" Target="../theme/theme1.xml"/>`,
|
|
489
|
+
'</Relationships>'
|
|
490
|
+
].join(''));
|
|
491
|
+
// Emit each slide
|
|
492
|
+
const marginX = 548640; // 0.6 in
|
|
493
|
+
const contentW = slideW - marginX * 2;
|
|
494
|
+
slidesToExport.forEach((slide, slideIdx) => {
|
|
495
|
+
const slideOrd = slideIdx + 1;
|
|
496
|
+
const slideRels = [
|
|
497
|
+
{ Id: 'rId1', Type: REL_TYPE_SLIDE_LAYOUT, Target: '../slideLayouts/slideLayout1.xml' }
|
|
498
|
+
];
|
|
499
|
+
let nextRelIdx = 2;
|
|
500
|
+
let nextShapeId = 2;
|
|
501
|
+
const shapeXmlParts = [];
|
|
502
|
+
// Title & Subtitle shapes
|
|
503
|
+
shapeXmlParts.push(buildTextShapeXml({
|
|
504
|
+
shapeId: nextShapeId++,
|
|
505
|
+
name: 'Title',
|
|
506
|
+
x: marginX,
|
|
507
|
+
y: 365760,
|
|
508
|
+
cx: contentW,
|
|
509
|
+
cy: 640080,
|
|
510
|
+
text: slide.Title || `Slide ${slideOrd}`,
|
|
511
|
+
fontSizePt: slide.Layout === 'Title' || slide.Layout === 'SectionHeader' ? 32 : 24,
|
|
512
|
+
bold: true,
|
|
513
|
+
colorHex: primaryHex,
|
|
514
|
+
fontFace: headingFont,
|
|
515
|
+
placeholderType: 'title',
|
|
516
|
+
align: slide.Layout === 'Title' || slide.Layout === 'SectionHeader' ? 'ctr' : 'l'
|
|
517
|
+
}));
|
|
518
|
+
let cursorY = 1097280;
|
|
519
|
+
if (slide.Subtitle) {
|
|
520
|
+
shapeXmlParts.push(buildTextShapeXml({
|
|
521
|
+
shapeId: nextShapeId++,
|
|
522
|
+
name: 'Subtitle',
|
|
523
|
+
x: marginX,
|
|
524
|
+
y: cursorY,
|
|
525
|
+
cx: contentW,
|
|
526
|
+
cy: 411480,
|
|
527
|
+
text: slide.Subtitle,
|
|
528
|
+
fontSizePt: 15,
|
|
529
|
+
colorHex: mutedHex,
|
|
530
|
+
fontFace: bodyFont,
|
|
531
|
+
placeholderType: 'subTitle',
|
|
532
|
+
align: slide.Layout === 'Title' || slide.Layout === 'SectionHeader' ? 'ctr' : 'l'
|
|
533
|
+
}));
|
|
534
|
+
cursorY += 480000;
|
|
535
|
+
}
|
|
536
|
+
// Regions layout calculation
|
|
537
|
+
const regions = slide.Regions ?? [];
|
|
538
|
+
const regionCount = Math.max(1, regions.length);
|
|
539
|
+
const availH = Math.max(1828800, slideH - cursorY - 640080);
|
|
540
|
+
regions.forEach((region, rIdx) => {
|
|
541
|
+
const { x: rx, y: ry, cx: rcx, cy: rcy } = computePptxRegionBounds(slide.Layout, rIdx, regionCount, marginX, cursorY, contentW, availH);
|
|
542
|
+
const parsedDirectiveBlock = !region.BlockSpec && region.MarkdownContent
|
|
543
|
+
? DocumentLiveBlockEngine.Instance.ParseMarkdownDirectives(region.MarkdownContent).find((seg) => seg.Type === 'mj-block')?.BlockSpec
|
|
544
|
+
: undefined;
|
|
545
|
+
const block = region.BlockSpec ?? parsedDirectiveBlock;
|
|
546
|
+
if (region.Kind === 'mj-block' || block) {
|
|
547
|
+
const verifiedIds = options?.VerifiedBlockIds;
|
|
548
|
+
const isPreVerified = Boolean(block?.FrozenSnapshot &&
|
|
549
|
+
verifiedIds &&
|
|
550
|
+
((block.BlockID && verifiedIds.has(block.BlockID)) ||
|
|
551
|
+
(region.RegionID && verifiedIds.has(region.RegionID)) ||
|
|
552
|
+
(slide.SlideID && region.RegionID && verifiedIds.has(`${slide.SlideID}:${region.RegionID}`))));
|
|
553
|
+
const snapValidation = block?.FrozenSnapshot
|
|
554
|
+
? isPreVerified
|
|
555
|
+
? { Valid: true, SnapshotVerified: true }
|
|
556
|
+
: ValidateFrozenBlockSnapshot(block.FrozenSnapshot, undefined, BuildBlockIdentityBinding(block))
|
|
557
|
+
: { Valid: false, SnapshotVerified: false, ErrorMessage: 'FrozenSnapshot missing.' };
|
|
558
|
+
const canRenderFrozenData = Boolean(block && snapValidation.Valid);
|
|
559
|
+
const chartData = block && canRenderFrozenData ? tryExtractChartDataFromSnapshot(block, region.Label) : null;
|
|
560
|
+
if (chartData) {
|
|
561
|
+
chartCounter++;
|
|
562
|
+
const chartFileName = `ppt/charts/chart${chartCounter}.xml`;
|
|
563
|
+
const relId = `rId${nextRelIdx++}`;
|
|
564
|
+
slideRels.push({
|
|
565
|
+
Id: relId,
|
|
566
|
+
Type: REL_TYPE_CHART,
|
|
567
|
+
Target: `../charts/chart${chartCounter}.xml`
|
|
568
|
+
});
|
|
569
|
+
chartPartNames.push(chartFileName);
|
|
570
|
+
addXmlEntry(chartFileName, buildDrawingMlChartXml(chartData, [primaryHex, accentHex, '10B981', 'F59E0B', '8B5CF6']));
|
|
571
|
+
shapeXmlParts.push(buildChartGraphicFrameXml({
|
|
572
|
+
shapeId: nextShapeId++,
|
|
573
|
+
name: region.Label || chartData.Title,
|
|
574
|
+
relId,
|
|
575
|
+
x: rx,
|
|
576
|
+
y: ry,
|
|
577
|
+
cx: rcx,
|
|
578
|
+
cy: rcy
|
|
579
|
+
}));
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const snap = canRenderFrozenData ? block?.FrozenSnapshot : undefined;
|
|
583
|
+
if (snap && Array.isArray(snap.Columns) && snap.Columns.length > 0 && Array.isArray(snap.Rows)) {
|
|
584
|
+
const headers = snap.Columns.map((c) => c.DisplayName || c.Name);
|
|
585
|
+
const tableRows = snap.Rows.map((row) => snap.Columns.map((col) => {
|
|
586
|
+
const v = row[col.Name];
|
|
587
|
+
return v === null || v === undefined ? '' : String(v);
|
|
588
|
+
}));
|
|
589
|
+
shapeXmlParts.push(buildTableGraphicFrameXml({
|
|
590
|
+
shapeId: nextShapeId++,
|
|
591
|
+
name: region.Label || block?.Title || 'Block Table',
|
|
592
|
+
x: rx,
|
|
593
|
+
y: ry,
|
|
594
|
+
cx: rcx,
|
|
595
|
+
cy: rcy,
|
|
596
|
+
headers,
|
|
597
|
+
rows: tableRows,
|
|
598
|
+
primaryHex,
|
|
599
|
+
surfaceHex,
|
|
600
|
+
textHex,
|
|
601
|
+
fontFace: bodyFont
|
|
602
|
+
}));
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const fallbackBlockText = block
|
|
606
|
+
? block.FrozenSnapshot && !snapValidation.Valid
|
|
607
|
+
? `${block.Title || region.Label}\n[${block.Kind} • Frozen snapshot unverified]`
|
|
608
|
+
: `${block.Title || region.Label}\n[${block.Kind} • ${block.Mode}]`
|
|
609
|
+
: region.MarkdownContent || region.Label;
|
|
610
|
+
shapeXmlParts.push(buildTextShapeXml({
|
|
611
|
+
shapeId: nextShapeId++,
|
|
612
|
+
name: region.Label || region.RegionID,
|
|
613
|
+
x: rx,
|
|
614
|
+
y: ry,
|
|
615
|
+
cx: rcx,
|
|
616
|
+
cy: rcy,
|
|
617
|
+
text: fallbackBlockText,
|
|
618
|
+
fontSizePt: 14,
|
|
619
|
+
colorHex: textHex,
|
|
620
|
+
fontFace: bodyFont,
|
|
621
|
+
fillHex: surfaceHex,
|
|
622
|
+
borderHex: accentHex
|
|
623
|
+
}));
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
if (region.Kind === 'big-number') {
|
|
627
|
+
const lines = [];
|
|
628
|
+
if (region.BigNumberValue)
|
|
629
|
+
lines.push(region.BigNumberValue);
|
|
630
|
+
if (region.BigNumberLabel)
|
|
631
|
+
lines.push(region.BigNumberLabel);
|
|
632
|
+
if (region.BigNumberDelta)
|
|
633
|
+
lines.push(region.BigNumberDelta);
|
|
634
|
+
if (lines.length === 0 && region.MarkdownContent)
|
|
635
|
+
lines.push(region.MarkdownContent);
|
|
636
|
+
shapeXmlParts.push(buildTextShapeXml({
|
|
637
|
+
shapeId: nextShapeId++,
|
|
638
|
+
name: region.Label || region.RegionID,
|
|
639
|
+
x: rx,
|
|
640
|
+
y: ry,
|
|
641
|
+
cx: rcx,
|
|
642
|
+
cy: rcy,
|
|
643
|
+
text: lines.join('\n'),
|
|
644
|
+
fontSizePt: 26,
|
|
645
|
+
bold: true,
|
|
646
|
+
colorHex: primaryHex,
|
|
647
|
+
fontFace: headingFont,
|
|
648
|
+
fillHex: surfaceHex,
|
|
649
|
+
align: 'ctr'
|
|
650
|
+
}));
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (region.Kind === 'quote') {
|
|
654
|
+
const quoteLines = [region.MarkdownContent || region.Label];
|
|
655
|
+
if (region.QuoteAttribution)
|
|
656
|
+
quoteLines.push(`— ${region.QuoteAttribution}`);
|
|
657
|
+
shapeXmlParts.push(buildTextShapeXml({
|
|
658
|
+
shapeId: nextShapeId++,
|
|
659
|
+
name: region.Label || region.RegionID,
|
|
660
|
+
x: rx,
|
|
661
|
+
y: ry,
|
|
662
|
+
cx: rcx,
|
|
663
|
+
cy: rcy,
|
|
664
|
+
text: quoteLines.join('\n'),
|
|
665
|
+
fontSizePt: 18,
|
|
666
|
+
italic: true,
|
|
667
|
+
colorHex: textHex,
|
|
668
|
+
fontFace: headingFont,
|
|
669
|
+
fillHex: surfaceHex
|
|
670
|
+
}));
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
if (region.Kind === 'image') {
|
|
674
|
+
const safeImg = options?.SanitizeImageUrl ? options.SanitizeImageUrl(region.ImageUrl) : region.ImageUrl;
|
|
675
|
+
const imgText = [region.ImageAlt || region.Label || 'Image', safeImg ? `Source: ${safeImg}` : '']
|
|
676
|
+
.filter(Boolean)
|
|
677
|
+
.join('\n');
|
|
678
|
+
shapeXmlParts.push(buildTextShapeXml({
|
|
679
|
+
shapeId: nextShapeId++,
|
|
680
|
+
name: region.Label || region.RegionID,
|
|
681
|
+
x: rx,
|
|
682
|
+
y: ry,
|
|
683
|
+
cx: rcx,
|
|
684
|
+
cy: rcy,
|
|
685
|
+
text: imgText,
|
|
686
|
+
fontSizePt: 13,
|
|
687
|
+
colorHex: mutedHex,
|
|
688
|
+
fontFace: bodyFont,
|
|
689
|
+
fillHex: surfaceHex
|
|
690
|
+
}));
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const mdTable = parseMarkdownTableRows(region.MarkdownContent);
|
|
694
|
+
if (mdTable && mdTable.length >= 2) {
|
|
695
|
+
shapeXmlParts.push(buildTableGraphicFrameXml({
|
|
696
|
+
shapeId: nextShapeId++,
|
|
697
|
+
name: region.Label || region.RegionID,
|
|
698
|
+
x: rx,
|
|
699
|
+
y: ry,
|
|
700
|
+
cx: rcx,
|
|
701
|
+
cy: rcy,
|
|
702
|
+
headers: mdTable[0],
|
|
703
|
+
rows: mdTable.slice(1),
|
|
704
|
+
primaryHex,
|
|
705
|
+
surfaceHex,
|
|
706
|
+
textHex,
|
|
707
|
+
fontFace: bodyFont
|
|
708
|
+
}));
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
shapeXmlParts.push(buildTextShapeXml({
|
|
712
|
+
shapeId: nextShapeId++,
|
|
713
|
+
name: region.Label || region.RegionID,
|
|
714
|
+
x: rx,
|
|
715
|
+
y: ry,
|
|
716
|
+
cx: rcx,
|
|
717
|
+
cy: rcy,
|
|
718
|
+
text: region.MarkdownContent || '',
|
|
719
|
+
fontSizePt: 14,
|
|
720
|
+
colorHex: textHex,
|
|
721
|
+
fontFace: bodyFont,
|
|
722
|
+
placeholderType: 'body',
|
|
723
|
+
bullet: true,
|
|
724
|
+
fillHex: region.Kind === 'callout' ? surfaceHex : undefined,
|
|
725
|
+
borderHex: region.Kind === 'callout' ? accentHex : undefined
|
|
726
|
+
}));
|
|
727
|
+
});
|
|
728
|
+
// Footer caption if configured
|
|
729
|
+
const footerBits = [];
|
|
730
|
+
if (deck.Master?.FooterText)
|
|
731
|
+
footerBits.push(deck.Master.FooterText);
|
|
732
|
+
if (deck.Master?.ShowSlideNumbers)
|
|
733
|
+
footerBits.push(`${slideOrd} / ${slidesToExport.length}`);
|
|
734
|
+
if (footerBits.length > 0) {
|
|
735
|
+
shapeXmlParts.push(buildTextShapeXml({
|
|
736
|
+
shapeId: nextShapeId++,
|
|
737
|
+
name: 'Footer',
|
|
738
|
+
x: marginX,
|
|
739
|
+
y: slideH - 457200,
|
|
740
|
+
cx: contentW,
|
|
741
|
+
cy: 320040,
|
|
742
|
+
text: footerBits.join(' • '),
|
|
743
|
+
fontSizePt: 10,
|
|
744
|
+
colorHex: mutedHex,
|
|
745
|
+
fontFace: bodyFont,
|
|
746
|
+
align: 'r'
|
|
747
|
+
}));
|
|
748
|
+
}
|
|
749
|
+
// Speaker notes part if non-empty
|
|
750
|
+
if (slide.SpeakerNotes && slide.SpeakerNotes.trim().length > 0) {
|
|
751
|
+
const notesPath = `ppt/notesSlides/notesSlide${slideOrd}.xml`;
|
|
752
|
+
const notesRelId = `rId${nextRelIdx++}`;
|
|
753
|
+
slideRels.push({
|
|
754
|
+
Id: notesRelId,
|
|
755
|
+
Type: REL_TYPE_NOTES_SLIDE,
|
|
756
|
+
Target: `../notesSlides/notesSlide${slideOrd}.xml`
|
|
757
|
+
});
|
|
758
|
+
notesPartNames.push(notesPath);
|
|
759
|
+
addXmlEntry(notesPath, [
|
|
760
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
761
|
+
'<p:notes xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">',
|
|
762
|
+
'<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>',
|
|
763
|
+
buildTextShapeXml({
|
|
764
|
+
shapeId: 2,
|
|
765
|
+
name: 'Notes',
|
|
766
|
+
x: 685800,
|
|
767
|
+
y: 4343400,
|
|
768
|
+
cx: 5486400,
|
|
769
|
+
cy: 4114800,
|
|
770
|
+
text: slide.SpeakerNotes,
|
|
771
|
+
fontSizePt: 12,
|
|
772
|
+
colorHex: '000000',
|
|
773
|
+
fontFace: bodyFont,
|
|
774
|
+
placeholderType: 'body'
|
|
775
|
+
}),
|
|
776
|
+
'</p:spTree></p:cSld>',
|
|
777
|
+
'</p:notes>'
|
|
778
|
+
].join(''));
|
|
779
|
+
addXmlEntry(`ppt/notesSlides/_rels/notesSlide${slideOrd}.xml.rels`, [
|
|
780
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
781
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">',
|
|
782
|
+
`<Relationship Id="rId1" Type="${REL_TYPE_SLIDE}" Target="../slides/slide${slideOrd}.xml"/>`,
|
|
783
|
+
'</Relationships>'
|
|
784
|
+
].join(''));
|
|
785
|
+
}
|
|
786
|
+
const showAttr = slide.Hidden ? ' show="0"' : '';
|
|
787
|
+
const secondaryBgHex = toDrawingHexColor(deck.Theme?.SecondaryGradientColor, bgHex);
|
|
788
|
+
const bgFillXml = deck.Theme?.BackgroundStyle === 'gradient' || deck.Theme?.BackgroundStyle === 'mesh'
|
|
789
|
+
? `<p:bg><p:bgPr><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:srgbClr val="${bgHex}"/></a:gs><a:gs pos="100000"><a:srgbClr val="${secondaryBgHex}"/></a:gs></a:gsLst><a:lin ang="2700000" scaled="1"/></a:gradFill><a:effectLst/></p:bgPr></p:bg>`
|
|
790
|
+
: `<p:bg><p:bgPr><a:solidFill><a:srgbClr val="${bgHex}"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>`;
|
|
791
|
+
const slideXml = [
|
|
792
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
793
|
+
`<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"${showAttr}>`,
|
|
794
|
+
'<p:cSld>',
|
|
795
|
+
bgFillXml,
|
|
796
|
+
'<p:spTree>',
|
|
797
|
+
'<p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>',
|
|
798
|
+
'<p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>',
|
|
799
|
+
shapeXmlParts.join(''),
|
|
800
|
+
'</p:spTree>',
|
|
801
|
+
'</p:cSld>',
|
|
802
|
+
'<p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr>',
|
|
803
|
+
'</p:sld>'
|
|
804
|
+
].join('');
|
|
805
|
+
addXmlEntry(`ppt/slides/slide${slideOrd}.xml`, slideXml);
|
|
806
|
+
addXmlEntry(`ppt/slides/_rels/slide${slideOrd}.xml.rels`, [
|
|
807
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
808
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">',
|
|
809
|
+
...slideRels.map((rel) => `<Relationship Id="${escapePptxXml(rel.Id)}" Type="${escapePptxXml(rel.Type)}" Target="${escapePptxXml(rel.Target)}"/>`),
|
|
810
|
+
'</Relationships>'
|
|
811
|
+
].join(''));
|
|
812
|
+
});
|
|
813
|
+
// ppt/presentation.xml + rels
|
|
814
|
+
const sldIdListXml = slidesToExport
|
|
815
|
+
.map((_s, idx) => `<p:sldId id="${256 + idx}" r:id="rId${idx + 3}"/>`)
|
|
816
|
+
.join('');
|
|
817
|
+
addXmlEntry('ppt/presentation.xml', [
|
|
818
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
819
|
+
'<p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" saveSubsetFonts="1">',
|
|
820
|
+
'<p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst>',
|
|
821
|
+
`<p:sldIdLst>${sldIdListXml}</p:sldIdLst>`,
|
|
822
|
+
`<p:sldSz cx="${slideW}" cy="${slideH}" type="${sldSzType}"/>`,
|
|
823
|
+
'<p:notesSz cx="6858000" cy="9144000"/>',
|
|
824
|
+
'</p:presentation>'
|
|
825
|
+
].join(''));
|
|
826
|
+
addXmlEntry('ppt/_rels/presentation.xml.rels', [
|
|
827
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
828
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">',
|
|
829
|
+
`<Relationship Id="rId1" Type="${REL_TYPE_SLIDE_MASTER}" Target="slideMasters/slideMaster1.xml"/>`,
|
|
830
|
+
`<Relationship Id="rId2" Type="${REL_TYPE_THEME}" Target="theme/theme1.xml"/>`,
|
|
831
|
+
...slidesToExport.map((_s, idx) => `<Relationship Id="rId${idx + 3}" Type="${REL_TYPE_SLIDE}" Target="slides/slide${idx + 1}.xml"/>`),
|
|
832
|
+
'</Relationships>'
|
|
833
|
+
].join(''));
|
|
834
|
+
// Metadata properties (core, app, custom)
|
|
835
|
+
const customMeta = {
|
|
836
|
+
DeckID: deck.DeckID,
|
|
837
|
+
Subtitle: deck.Subtitle,
|
|
838
|
+
Master: deck.Master,
|
|
839
|
+
Theme: {
|
|
840
|
+
ThemeID: deck.Theme?.ThemeID,
|
|
841
|
+
Name: deck.Theme?.Name
|
|
842
|
+
},
|
|
843
|
+
Slides: slidesToExport.map((s) => ({
|
|
844
|
+
SlideID: s.SlideID,
|
|
845
|
+
Layout: s.Layout,
|
|
846
|
+
Transition: s.Transition,
|
|
847
|
+
Hidden: Boolean(s.Hidden)
|
|
848
|
+
}))
|
|
849
|
+
};
|
|
850
|
+
addXmlEntry('docProps/core.xml', [
|
|
851
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
852
|
+
'<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">',
|
|
853
|
+
`<dc:title>${escapePptxXml(deck.Title || 'Presentation')}</dc:title>`,
|
|
854
|
+
`<dc:creator>${escapePptxXml(deck.Master?.OrganizationName || 'MemberJunction')}</dc:creator>`,
|
|
855
|
+
'</cp:coreProperties>'
|
|
856
|
+
].join(''));
|
|
857
|
+
addXmlEntry('docProps/app.xml', [
|
|
858
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
859
|
+
'<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">',
|
|
860
|
+
'<Application>MemberJunction SlideDeckEngine</Application>',
|
|
861
|
+
`<Slides>${slidesToExport.length}</Slides>`,
|
|
862
|
+
'</Properties>'
|
|
863
|
+
].join(''));
|
|
864
|
+
addXmlEntry('docProps/custom.xml', [
|
|
865
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
866
|
+
'<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">',
|
|
867
|
+
'<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" name="MJSlideDeckMeta">',
|
|
868
|
+
`<vt:lpwstr>${escapePptxXml(JSON.stringify(customMeta))}</vt:lpwstr>`,
|
|
869
|
+
'</property>',
|
|
870
|
+
'</Properties>'
|
|
871
|
+
].join(''));
|
|
872
|
+
addXmlEntry('_rels/.rels', [
|
|
873
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
874
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">',
|
|
875
|
+
`<Relationship Id="rId1" Type="${REL_TYPE_OFFICE_DOC}" Target="ppt/presentation.xml"/>`,
|
|
876
|
+
`<Relationship Id="rId2" Type="${REL_TYPE_CORE_PROPS}" Target="docProps/core.xml"/>`,
|
|
877
|
+
`<Relationship Id="rId3" Type="${REL_TYPE_EXT_PROPS}" Target="docProps/app.xml"/>`,
|
|
878
|
+
`<Relationship Id="rId4" Type="${REL_TYPE_CUSTOM_PROPS}" Target="docProps/custom.xml"/>`,
|
|
879
|
+
'</Relationships>'
|
|
880
|
+
].join(''));
|
|
881
|
+
const overrides = [
|
|
882
|
+
'<Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>',
|
|
883
|
+
'<Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/>',
|
|
884
|
+
'<Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/>',
|
|
885
|
+
'<Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>',
|
|
886
|
+
'<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>',
|
|
887
|
+
'<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>',
|
|
888
|
+
'<Override PartName="/docProps/custom.xml" ContentType="application/vnd.openxmlformats-officedocument.custom-properties+xml"/>'
|
|
889
|
+
];
|
|
890
|
+
slidesToExport.forEach((_s, idx) => {
|
|
891
|
+
overrides.push(`<Override PartName="/ppt/slides/slide${idx + 1}.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>`);
|
|
892
|
+
});
|
|
893
|
+
for (const notesPart of notesPartNames) {
|
|
894
|
+
overrides.push(`<Override PartName="/${notesPart}" ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml"/>`);
|
|
895
|
+
}
|
|
896
|
+
for (const chartPart of chartPartNames) {
|
|
897
|
+
overrides.push(`<Override PartName="/${chartPart}" ContentType="application/vnd.openxmlformats-officedocument.drawingml.chart+xml"/>`);
|
|
898
|
+
}
|
|
899
|
+
addXmlEntry('[Content_Types].xml', [
|
|
900
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
901
|
+
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">',
|
|
902
|
+
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>',
|
|
903
|
+
'<Default Extension="xml" ContentType="application/xml"/>',
|
|
904
|
+
...overrides,
|
|
905
|
+
'</Types>'
|
|
906
|
+
].join(''));
|
|
907
|
+
return SpreadsheetEngine.Instance.BuildZipArchive(entries);
|
|
908
|
+
}
|
|
909
|
+
function extractParagraphsFromXmlBlock(xmlFragment) {
|
|
910
|
+
const paragraphs = [];
|
|
911
|
+
const pRe = /<a:p\b[^>]*>([\s\S]*?)<\/a:p>/gi;
|
|
912
|
+
let pm;
|
|
913
|
+
while ((pm = pRe.exec(xmlFragment)) !== null) {
|
|
914
|
+
const pInner = pm[1];
|
|
915
|
+
const hasBullet = /<a:buChar\b/i.test(pInner);
|
|
916
|
+
const textChunks = [];
|
|
917
|
+
const tRe = /<a:t\b[^>]*>([\s\S]*?)<\/a:t>/gi;
|
|
918
|
+
let tm;
|
|
919
|
+
while ((tm = tRe.exec(pInner)) !== null) {
|
|
920
|
+
textChunks.push(unescapePptxXml(tm[1]));
|
|
921
|
+
}
|
|
922
|
+
const joined = textChunks.join('');
|
|
923
|
+
paragraphs.push(hasBullet && joined.trim() ? `- ${joined}` : joined);
|
|
924
|
+
}
|
|
925
|
+
return paragraphs.join('\n').trim();
|
|
926
|
+
}
|
|
927
|
+
function parseChartXmlToRegion(chartXml, regionId) {
|
|
928
|
+
const titleMatch = /<c:title\b[\s\S]*?<a:t\b[^>]*>([\s\S]*?)<\/a:t>/i.exec(chartXml);
|
|
929
|
+
const title = titleMatch ? unescapePptxXml(titleMatch[1]) : 'Imported Chart';
|
|
930
|
+
const chartType = /<c:lineChart\b/i.test(chartXml)
|
|
931
|
+
? 'line'
|
|
932
|
+
: /<c:pieChart\b/i.test(chartXml)
|
|
933
|
+
? 'pie'
|
|
934
|
+
: /<c:areaChart\b/i.test(chartXml)
|
|
935
|
+
? 'area'
|
|
936
|
+
: 'bar';
|
|
937
|
+
const categories = [];
|
|
938
|
+
const seriesList = [];
|
|
939
|
+
const serRe = /<c:ser\b[^>]*>([\s\S]*?)<\/c:ser>/gi;
|
|
940
|
+
let sm;
|
|
941
|
+
while ((sm = serRe.exec(chartXml)) !== null) {
|
|
942
|
+
const serBody = sm[1];
|
|
943
|
+
const nameMatch = /<c:tx\b[\s\S]*?<c:v\b[^>]*>([\s\S]*?)<\/c:v>/i.exec(serBody);
|
|
944
|
+
const serName = nameMatch ? unescapePptxXml(nameMatch[1]) : `Series ${seriesList.length + 1}`;
|
|
945
|
+
if (categories.length === 0) {
|
|
946
|
+
const catBlock = /<c:cat\b[^>]*>([\s\S]*?)<\/c:cat>/i.exec(serBody)?.[1] ?? '';
|
|
947
|
+
const ptRe = /<c:v\b[^>]*>([\s\S]*?)<\/c:v>/gi;
|
|
948
|
+
let pm;
|
|
949
|
+
while ((pm = ptRe.exec(catBlock)) !== null) {
|
|
950
|
+
categories.push(unescapePptxXml(pm[1]));
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
const valBlock = /<c:val\b[^>]*>([\s\S]*?)<\/c:val>/i.exec(serBody)?.[1] ?? '';
|
|
954
|
+
const vals = [];
|
|
955
|
+
const ptRe = /<c:v\b[^>]*>([\s\S]*?)<\/c:v>/gi;
|
|
956
|
+
let vm;
|
|
957
|
+
while ((vm = ptRe.exec(valBlock)) !== null) {
|
|
958
|
+
const parsed = Number(unescapePptxXml(vm[1]));
|
|
959
|
+
vals.push(Number.isFinite(parsed) ? parsed : 0);
|
|
960
|
+
}
|
|
961
|
+
seriesList.push({ name: serName, values: vals });
|
|
962
|
+
}
|
|
963
|
+
const columns = [
|
|
964
|
+
{ Name: 'Category', DisplayName: 'Category', Type: 'nvarchar' },
|
|
965
|
+
...seriesList.map((s) => ({ Name: s.name, DisplayName: s.name, Type: 'decimal' }))
|
|
966
|
+
];
|
|
967
|
+
const rowCount = Math.max(categories.length, seriesList[0]?.values.length ?? 0);
|
|
968
|
+
const rows = [];
|
|
969
|
+
for (let r = 0; r < rowCount; r++) {
|
|
970
|
+
const row = {};
|
|
971
|
+
Object.defineProperty(row, 'Category', {
|
|
972
|
+
value: categories[r] ?? `Item ${r + 1}`,
|
|
973
|
+
writable: true,
|
|
974
|
+
enumerable: true,
|
|
975
|
+
configurable: true
|
|
976
|
+
});
|
|
977
|
+
for (const s of seriesList) {
|
|
978
|
+
const safeKey = s.name === '__proto__' || s.name === 'constructor' || s.name === 'prototype'
|
|
979
|
+
? `Series_${s.name}`
|
|
980
|
+
: s.name;
|
|
981
|
+
Object.defineProperty(row, safeKey, {
|
|
982
|
+
value: s.values[r] ?? 0,
|
|
983
|
+
writable: true,
|
|
984
|
+
enumerable: true,
|
|
985
|
+
configurable: true
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
rows.push(row);
|
|
989
|
+
}
|
|
990
|
+
// Never forge HMAC-signed FrozenSnapshot blocks from untrusted PPTX chart XML (`S3`);
|
|
991
|
+
// always materialize imported chart data as static rich-text markdown.
|
|
992
|
+
const headerLine = `| ${columns.map((c) => c.DisplayName).join(' | ')} |`;
|
|
993
|
+
const sepLine = `| ${columns.map(() => '---').join(' | ')} |`;
|
|
994
|
+
const dataLines = rows.map((r) => `| ${columns.map((c) => String(r[c.Name] ?? '')).join(' | ')} |`);
|
|
995
|
+
return {
|
|
996
|
+
RegionID: regionId,
|
|
997
|
+
Label: title,
|
|
998
|
+
Kind: 'rich-text',
|
|
999
|
+
MarkdownContent: [`### ${title}`, '', headerLine, sepLine, ...dataLines].join('\n')
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Imports a `.pptx` archive (`Uint8Array`) headlessly into a normalized {@link SlideDeckSpec} (`NW-4`).
|
|
1004
|
+
*/
|
|
1005
|
+
export function ImportDeckFromPptxBytesInternal(pptxBytes, fallbackTitle = 'Imported Presentation') {
|
|
1006
|
+
const decoder = new TextDecoder();
|
|
1007
|
+
const files = SpreadsheetEngine.Instance.ExtractZipArchive(pptxBytes);
|
|
1008
|
+
const readText = (path) => {
|
|
1009
|
+
const bytes = files.get(path);
|
|
1010
|
+
return bytes ? decoder.decode(bytes) : null;
|
|
1011
|
+
};
|
|
1012
|
+
// Parse optional MJ custom metadata
|
|
1013
|
+
let customMeta = {};
|
|
1014
|
+
const customXml = readText('docProps/custom.xml');
|
|
1015
|
+
if (customXml) {
|
|
1016
|
+
const metaMatch = /name="MJSlideDeckMeta"[\s\S]*?<vt:lpwstr>([\s\S]*?)<\/vt:lpwstr>/i.exec(customXml);
|
|
1017
|
+
if (metaMatch) {
|
|
1018
|
+
try {
|
|
1019
|
+
const parsed = JSON.parse(unescapePptxXml(metaMatch[1]));
|
|
1020
|
+
if (parsed && typeof parsed === 'object') {
|
|
1021
|
+
customMeta = parsed;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
catch {
|
|
1025
|
+
customMeta = {};
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
// Parse core title
|
|
1030
|
+
const coreXml = readText('docProps/core.xml') ?? '';
|
|
1031
|
+
const coreTitleMatch = /<dc:title[^>]*>([\s\S]*?)<\/dc:title>/i.exec(coreXml);
|
|
1032
|
+
const title = coreTitleMatch ? unescapePptxXml(coreTitleMatch[1]).trim() || fallbackTitle : fallbackTitle;
|
|
1033
|
+
// Parse presentation.xml (size + ordered slide rel IDs)
|
|
1034
|
+
const presXml = readText('ppt/presentation.xml') ?? '';
|
|
1035
|
+
if (!presXml) {
|
|
1036
|
+
throw new Error('Invalid .pptx archive: missing ppt/presentation.xml.');
|
|
1037
|
+
}
|
|
1038
|
+
const sldSzTag = /<p:sldSz\b([^>]*)/i.exec(presXml)?.[1] ?? '';
|
|
1039
|
+
const cxAttr = Number(/\bcx="(\d+)"/i.exec(sldSzTag)?.[1] ?? SLIDE_W_16_9);
|
|
1040
|
+
const cyAttr = Number(/\bcy="(\d+)"/i.exec(sldSzTag)?.[1] ?? SLIDE_H_STD);
|
|
1041
|
+
const typeAttr = /\btype="([^"]*)"/i.exec(sldSzTag)?.[1] ?? '';
|
|
1042
|
+
const aspectRatio = typeAttr === 'screen4x3' || (cxAttr > 0 && cyAttr > 0 && cxAttr / cyAttr <= 1.45) ? '4:3' : '16:9';
|
|
1043
|
+
// Map presentation rels safely (rejecting '..' escape outside archive root)
|
|
1044
|
+
const presRelsXml = readText('ppt/_rels/presentation.xml.rels') ?? '';
|
|
1045
|
+
const presRelMap = new Map();
|
|
1046
|
+
for (const rel of parseRelsXml(presRelsXml)) {
|
|
1047
|
+
presRelMap.set(rel.Id, rel);
|
|
1048
|
+
}
|
|
1049
|
+
const slidePaths = [];
|
|
1050
|
+
const sldIdRe = /<p:sldId\b[^>]*r:id="([^"]+)"/gi;
|
|
1051
|
+
let sidMatch;
|
|
1052
|
+
while ((sidMatch = sldIdRe.exec(presXml)) !== null) {
|
|
1053
|
+
const rel = presRelMap.get(sidMatch[1]);
|
|
1054
|
+
if (!rel)
|
|
1055
|
+
continue;
|
|
1056
|
+
const normalized = normalizePptxRelTarget('ppt', rel.Target);
|
|
1057
|
+
if (normalized && files.has(normalized)) {
|
|
1058
|
+
slidePaths.push(normalized);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
// Fallback: collect ppt/slides/slide*.xml sorted numerically if sldIdLst missing
|
|
1062
|
+
if (slidePaths.length === 0) {
|
|
1063
|
+
const fallbackPaths = Array.from(files.keys())
|
|
1064
|
+
.filter((k) => /^ppt\/slides\/slide\d+\.xml$/i.test(k))
|
|
1065
|
+
.sort((a, b) => {
|
|
1066
|
+
const na = parseInt(/slide(\d+)\.xml/i.exec(a)?.[1] ?? '0', 10);
|
|
1067
|
+
const nb = parseInt(/slide(\d+)\.xml/i.exec(b)?.[1] ?? '0', 10);
|
|
1068
|
+
return na - nb;
|
|
1069
|
+
});
|
|
1070
|
+
slidePaths.push(...fallbackPaths);
|
|
1071
|
+
}
|
|
1072
|
+
// Parse theme1.xml colors & fonts
|
|
1073
|
+
const themeXml = readText('ppt/theme/theme1.xml') ?? '';
|
|
1074
|
+
const readSchemeHex = (tag, fallback) => {
|
|
1075
|
+
const block = new RegExp(`<a:${tag}\\b[^>]*>([\\s\\S]*?)<\\/a:${tag}>`, 'i').exec(themeXml)?.[1] ?? '';
|
|
1076
|
+
const hex = /<a:srgbClr\s+val="([0-9a-fA-F]{6})"/i.exec(block)?.[1];
|
|
1077
|
+
return hex ? `#${hex}` : fallback;
|
|
1078
|
+
};
|
|
1079
|
+
const majorFontMatch = /<a:majorFont\b[^>]*>[\s\S]*?<a:latin\s+typeface="([^"]+)"/i.exec(themeXml);
|
|
1080
|
+
const minorFontMatch = /<a:minorFont\b[^>]*>[\s\S]*?<a:latin\s+typeface="([^"]+)"/i.exec(themeXml);
|
|
1081
|
+
const theme = {
|
|
1082
|
+
ThemeID: customMeta.Theme?.ThemeID || 'imported-pptx',
|
|
1083
|
+
Name: customMeta.Theme?.Name || 'Imported PPTX Theme',
|
|
1084
|
+
PrimaryColor: readSchemeHex('accent1', '#4F46E5'),
|
|
1085
|
+
AccentColor: readSchemeHex('accent2', '#0EA5E9'),
|
|
1086
|
+
BackgroundColor: readSchemeHex('lt1', '#FFFFFF'),
|
|
1087
|
+
SurfaceColor: readSchemeHex('lt2', '#F8FAFC'),
|
|
1088
|
+
TextColor: readSchemeHex('dk1', '#0F172A'),
|
|
1089
|
+
MutedTextColor: readSchemeHex('dk2', '#475569'),
|
|
1090
|
+
HeadingFont: majorFontMatch ? `${unescapePptxXml(majorFontMatch[1])}, sans-serif` : 'Inter, system-ui, sans-serif',
|
|
1091
|
+
BodyFont: minorFontMatch ? `${unescapePptxXml(minorFontMatch[1])}, sans-serif` : 'Inter, system-ui, sans-serif'
|
|
1092
|
+
};
|
|
1093
|
+
const slides = slidePaths.map((slidePath, idx) => {
|
|
1094
|
+
const slideXml = readText(slidePath) ?? '';
|
|
1095
|
+
const slideDir = slidePath.includes('/') ? slidePath.slice(0, slidePath.lastIndexOf('/')) : '';
|
|
1096
|
+
const slideBaseName = slidePath.includes('/') ? slidePath.slice(slidePath.lastIndexOf('/') + 1) : slidePath;
|
|
1097
|
+
const relsPath = slideDir ? `${slideDir}/_rels/${slideBaseName}.rels` : `_rels/${slideBaseName}.rels`;
|
|
1098
|
+
const slideRelEntries = parseRelsXml(readText(relsPath) ?? '');
|
|
1099
|
+
const slideRelById = new Map();
|
|
1100
|
+
for (const r of slideRelEntries) {
|
|
1101
|
+
slideRelById.set(r.Id, r);
|
|
1102
|
+
}
|
|
1103
|
+
const showZero = /<p:sld\b[^>]*\bshow="0"/i.test(slideXml);
|
|
1104
|
+
const metaSlide = customMeta.Slides?.[idx];
|
|
1105
|
+
let slideTitle = `Slide ${idx + 1}`;
|
|
1106
|
+
let slideSubtitle;
|
|
1107
|
+
const regions = [];
|
|
1108
|
+
let regionCounter = 0;
|
|
1109
|
+
// Parse <p:sp> shapes
|
|
1110
|
+
const spRe = /<p:sp\b[^>]*>([\s\S]*?)<\/p:sp>/gi;
|
|
1111
|
+
let spm;
|
|
1112
|
+
while ((spm = spRe.exec(slideXml)) !== null) {
|
|
1113
|
+
const spBody = spm[1];
|
|
1114
|
+
const spName = /\bname="([^"]*)"/i.exec(spBody)?.[1] ?? '';
|
|
1115
|
+
const phType = /<p:ph\b[^>]*\btype="([^"]*)"/i.exec(spBody)?.[1] ?? '';
|
|
1116
|
+
const text = extractParagraphsFromXmlBlock(spBody);
|
|
1117
|
+
if (!text)
|
|
1118
|
+
continue;
|
|
1119
|
+
if (phType === 'title' || phType === 'ctrTitle' || spName === 'Title') {
|
|
1120
|
+
slideTitle = text;
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
if (phType === 'subTitle' || spName === 'Subtitle') {
|
|
1124
|
+
slideSubtitle = text;
|
|
1125
|
+
continue;
|
|
1126
|
+
}
|
|
1127
|
+
if (spName === 'Footer') {
|
|
1128
|
+
continue;
|
|
1129
|
+
}
|
|
1130
|
+
regionCounter++;
|
|
1131
|
+
regions.push({
|
|
1132
|
+
RegionID: `region-${regionCounter}`,
|
|
1133
|
+
Label: unescapePptxXml(spName) || `Region ${regionCounter}`,
|
|
1134
|
+
Kind: 'rich-text',
|
|
1135
|
+
MarkdownContent: text
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
// Parse <p:graphicFrame> (tables + charts)
|
|
1139
|
+
const gfRe = /<p:graphicFrame\b[^>]*>([\s\S]*?)<\/p:graphicFrame>/gi;
|
|
1140
|
+
let gfm;
|
|
1141
|
+
while ((gfm = gfRe.exec(slideXml)) !== null) {
|
|
1142
|
+
const gfBody = gfm[1];
|
|
1143
|
+
const chartRef = /<c:chart\b[^>]*r:id="([^"]+)"/i.exec(gfBody)?.[1];
|
|
1144
|
+
if (chartRef) {
|
|
1145
|
+
const rel = slideRelById.get(chartRef);
|
|
1146
|
+
const chartPath = rel ? normalizePptxRelTarget(slideDir, rel.Target) : null;
|
|
1147
|
+
const chartXml = chartPath ? readText(chartPath) : null;
|
|
1148
|
+
if (chartXml) {
|
|
1149
|
+
regionCounter++;
|
|
1150
|
+
regions.push(parseChartXmlToRegion(chartXml, `chart-${idx + 1}-${regionCounter}`));
|
|
1151
|
+
}
|
|
1152
|
+
continue;
|
|
1153
|
+
}
|
|
1154
|
+
const tblMatch = /<a:tbl\b[^>]*>([\s\S]*?)<\/a:tbl>/i.exec(gfBody);
|
|
1155
|
+
if (tblMatch) {
|
|
1156
|
+
const tableRows = [];
|
|
1157
|
+
const trRe = /<a:tr\b[^>]*>([\s\S]*?)<\/a:tr>/gi;
|
|
1158
|
+
let trm;
|
|
1159
|
+
while ((trm = trRe.exec(tblMatch[1])) !== null) {
|
|
1160
|
+
const rowCells = [];
|
|
1161
|
+
const tcRe = /<a:tc\b[^>]*>([\s\S]*?)<\/a:tc>/gi;
|
|
1162
|
+
let tcm;
|
|
1163
|
+
while ((tcm = tcRe.exec(trm[1])) !== null) {
|
|
1164
|
+
rowCells.push(extractParagraphsFromXmlBlock(tcm[1]).replace(/\n/g, ' '));
|
|
1165
|
+
}
|
|
1166
|
+
if (rowCells.length > 0)
|
|
1167
|
+
tableRows.push(rowCells);
|
|
1168
|
+
}
|
|
1169
|
+
if (tableRows.length > 0) {
|
|
1170
|
+
regionCounter++;
|
|
1171
|
+
const headerLine = `| ${tableRows[0].join(' | ')} |`;
|
|
1172
|
+
const sepLine = `| ${tableRows[0].map(() => '---').join(' | ')} |`;
|
|
1173
|
+
const bodyLines = tableRows.slice(1).map((r) => `| ${r.join(' | ')} |`);
|
|
1174
|
+
regions.push({
|
|
1175
|
+
RegionID: `table-${regionCounter}`,
|
|
1176
|
+
Label: 'Data Table',
|
|
1177
|
+
Kind: 'table',
|
|
1178
|
+
MarkdownContent: [headerLine, sepLine, ...bodyLines].join('\n')
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
// Speaker notes via notesSlide relationship
|
|
1184
|
+
let speakerNotes = '';
|
|
1185
|
+
const notesRel = slideRelEntries.find((r) => r.Type === REL_TYPE_NOTES_SLIDE);
|
|
1186
|
+
if (notesRel) {
|
|
1187
|
+
const notesPath = normalizePptxRelTarget(slideDir, notesRel.Target);
|
|
1188
|
+
const notesXml = notesPath ? readText(notesPath) : null;
|
|
1189
|
+
if (notesXml) {
|
|
1190
|
+
speakerNotes = extractParagraphsFromXmlBlock(notesXml);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return {
|
|
1194
|
+
SlideID: metaSlide?.SlideID || `slide-${idx + 1}`,
|
|
1195
|
+
SlideNumber: idx + 1,
|
|
1196
|
+
Layout: metaSlide?.Layout || 'TitleAndBody',
|
|
1197
|
+
Title: slideTitle,
|
|
1198
|
+
Subtitle: slideSubtitle,
|
|
1199
|
+
Regions: regions.length > 0
|
|
1200
|
+
? regions
|
|
1201
|
+
: [{ RegionID: 'main', Label: 'Content', Kind: 'rich-text', MarkdownContent: '' }],
|
|
1202
|
+
SpeakerNotes: speakerNotes,
|
|
1203
|
+
Transition: metaSlide?.Transition || 'fade',
|
|
1204
|
+
Hidden: metaSlide?.Hidden ?? showZero
|
|
1205
|
+
};
|
|
1206
|
+
});
|
|
1207
|
+
const master = customMeta.Master ?? {
|
|
1208
|
+
HeaderText: '',
|
|
1209
|
+
FooterText: '',
|
|
1210
|
+
ShowSlideNumbers: true,
|
|
1211
|
+
ShowDate: true,
|
|
1212
|
+
OrganizationName: 'MemberJunction'
|
|
1213
|
+
};
|
|
1214
|
+
return {
|
|
1215
|
+
SchemaVersion: '1.0',
|
|
1216
|
+
DeckID: customMeta.DeckID || 'imported-pptx',
|
|
1217
|
+
Title: title,
|
|
1218
|
+
Subtitle: customMeta.Subtitle,
|
|
1219
|
+
AspectRatio: aspectRatio,
|
|
1220
|
+
Theme: theme,
|
|
1221
|
+
Master: master,
|
|
1222
|
+
Slides: slides.length > 0 ? slides : [{ SlideID: 'slide-1', SlideNumber: 1, Layout: 'TitleAndBody', Title: title, Regions: [{ RegionID: 'main', Label: 'Content', Kind: 'rich-text', MarkdownContent: '' }], SpeakerNotes: '' }],
|
|
1223
|
+
UpdatedAt: new Date().toISOString()
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Computes EMU coordinates (`x`, `y`, `cx`, `cy`) for each slide region based on the
|
|
1228
|
+
* slide's canonical layout so exported `.pptx` slides preserve grid/card geometry.
|
|
1229
|
+
*/
|
|
1230
|
+
function computePptxRegionBounds(layout, rIdx, regionCount, marginX, cursorY, contentW, availH) {
|
|
1231
|
+
const gap = 228600; // 0.25 in
|
|
1232
|
+
if (regionCount === 2 &&
|
|
1233
|
+
(layout === 'TwoColumn' ||
|
|
1234
|
+
layout === 'Comparison' ||
|
|
1235
|
+
layout === 'LiveDataSlide' ||
|
|
1236
|
+
layout === 'ChartAndText')) {
|
|
1237
|
+
const colW = Math.floor((contentW - gap) / 2);
|
|
1238
|
+
return {
|
|
1239
|
+
x: rIdx === 0 ? marginX : marginX + colW + gap,
|
|
1240
|
+
y: cursorY,
|
|
1241
|
+
cx: colW,
|
|
1242
|
+
cy: availH
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
if ((layout === 'KpiStrip' || layout === 'Timeline') && regionCount >= 2) {
|
|
1246
|
+
const cols = Math.min(4, regionCount);
|
|
1247
|
+
const colW = Math.floor((contentW - gap * (cols - 1)) / cols);
|
|
1248
|
+
const col = rIdx % cols;
|
|
1249
|
+
const rows = Math.ceil(regionCount / cols);
|
|
1250
|
+
const row = Math.floor(rIdx / cols);
|
|
1251
|
+
const rowH = Math.max(640080, Math.floor((availH - gap * (rows - 1)) / rows));
|
|
1252
|
+
return {
|
|
1253
|
+
x: marginX + col * (colW + gap),
|
|
1254
|
+
y: cursorY + row * (rowH + gap),
|
|
1255
|
+
cx: colW,
|
|
1256
|
+
cy: rowH
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
if (layout === 'Quadrant' && regionCount >= 3) {
|
|
1260
|
+
const colW = Math.floor((contentW - gap) / 2);
|
|
1261
|
+
const rowH = Math.max(640080, Math.floor((availH - gap) / 2));
|
|
1262
|
+
const col = rIdx % 2;
|
|
1263
|
+
const row = Math.floor(rIdx / 2);
|
|
1264
|
+
return {
|
|
1265
|
+
x: marginX + col * (colW + gap),
|
|
1266
|
+
y: cursorY + row * (rowH + gap),
|
|
1267
|
+
cx: colW,
|
|
1268
|
+
cy: rowH
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
if (layout === 'BentoGrid' && regionCount >= 3) {
|
|
1272
|
+
const rowH = Math.max(640080, Math.floor((availH - gap) / 2));
|
|
1273
|
+
if (rIdx === 0) {
|
|
1274
|
+
return { x: marginX, y: cursorY, cx: contentW, cy: rowH };
|
|
1275
|
+
}
|
|
1276
|
+
const bottomCols = Math.max(1, regionCount - 1);
|
|
1277
|
+
const colW = Math.floor((contentW - gap * (bottomCols - 1)) / bottomCols);
|
|
1278
|
+
return {
|
|
1279
|
+
x: marginX + (rIdx - 1) * (colW + gap),
|
|
1280
|
+
y: cursorY + rowH + gap,
|
|
1281
|
+
cx: colW,
|
|
1282
|
+
cy: rowH
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
if (layout === 'MetricComparison' && regionCount >= 2) {
|
|
1286
|
+
const topH = Math.floor(availH * 0.54);
|
|
1287
|
+
const bottomH = Math.max(640080, availH - topH - gap);
|
|
1288
|
+
if (rIdx < 2) {
|
|
1289
|
+
const colW = Math.floor((contentW - gap) / 2);
|
|
1290
|
+
return {
|
|
1291
|
+
x: marginX + rIdx * (colW + gap),
|
|
1292
|
+
y: cursorY,
|
|
1293
|
+
cx: colW,
|
|
1294
|
+
cy: topH
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
return {
|
|
1298
|
+
x: marginX,
|
|
1299
|
+
y: cursorY + topH + gap,
|
|
1300
|
+
cx: contentW,
|
|
1301
|
+
cy: bottomH
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
return {
|
|
1305
|
+
x: marginX,
|
|
1306
|
+
y: cursorY + Math.floor((availH / regionCount) * rIdx),
|
|
1307
|
+
cx: contentW,
|
|
1308
|
+
cy: Math.max(640080, Math.floor(availH / regionCount) - 91440)
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1311
|
+
//# sourceMappingURL=SlideDeckPptxEngine.js.map
|