Files
simstudioai--sim/apps/sim/lib/pptx-renderer/model/master.ts
T
wehub-resource-sync d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

81 lines
2.2 KiB
TypeScript

/**
* Slide master parser — extracts color map, background, text styles,
* and placeholder shapes from a p:sldMaster XML.
*/
import type { SafeXmlNode } from '../parser/xml-parser'
import { isPlaceholder, parseAllAttributes } from './xml-helpers'
export interface MasterData {
colorMap: Map<string, string>
background?: SafeXmlNode
textStyles: {
titleStyle?: SafeXmlNode
bodyStyle?: SafeXmlNode
otherStyle?: SafeXmlNode
}
defaultTextStyle?: SafeXmlNode
placeholders: SafeXmlNode[]
spTree: SafeXmlNode
rels: Map<string, import('../parser/rel-parser').RelEntry>
}
/**
* Extract placeholder shape nodes from an spTree node.
* A shape is considered a placeholder if it has a `p:ph` element in its nvPr.
*/
function extractPlaceholders(spTree: SafeXmlNode): SafeXmlNode[] {
const placeholders: SafeXmlNode[] = []
const allChildren = spTree.allChildren()
for (const child of allChildren) {
if (isPlaceholder(child)) {
placeholders.push(child)
}
}
return placeholders
}
/**
* Parse a slide master XML root (`p:sldMaster`) into MasterData.
*/
export function parseMaster(root: SafeXmlNode): MasterData {
const cSld = root.child('cSld')
// --- Background ---
const bg = cSld.child('bg')
const background = bg.exists() ? bg : undefined
// --- Shape tree ---
const spTree = cSld.child('spTree')
// --- Color map ---
const clrMap = root.child('clrMap')
const colorMap = parseAllAttributes(clrMap)
// --- Text styles ---
const txStyles = root.child('txStyles')
const titleStyle = txStyles.child('titleStyle')
const bodyStyle = txStyles.child('bodyStyle')
const otherStyle = txStyles.child('otherStyle')
// --- Default text style ---
const defaultTextStyle = root.child('defaultTextStyle')
// --- Placeholders ---
const placeholders = extractPlaceholders(spTree)
return {
colorMap,
background,
textStyles: {
titleStyle: titleStyle.exists() ? titleStyle : undefined,
bodyStyle: bodyStyle.exists() ? bodyStyle : undefined,
otherStyle: otherStyle.exists() ? otherStyle : undefined,
},
defaultTextStyle: defaultTextStyle.exists() ? defaultTextStyle : undefined,
placeholders,
spTree,
rels: new Map(), // populated later by buildPresentation
}
}