d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
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
103 lines
2.8 KiB
TypeScript
103 lines
2.8 KiB
TypeScript
/**
|
|
* Picture node parser — handles images, video placeholders, and audio placeholders.
|
|
*/
|
|
|
|
import type { SafeXmlNode } from '../../parser/xml-parser'
|
|
import { type BaseNodeData, parseBaseProps } from './base-node'
|
|
|
|
interface CropRect {
|
|
top: number
|
|
bottom: number
|
|
left: number
|
|
right: number
|
|
}
|
|
|
|
export interface PicNodeData extends BaseNodeData {
|
|
nodeType: 'picture'
|
|
blipEmbed?: string
|
|
blipLink?: string
|
|
crop?: CropRect
|
|
/** @internal Raw XML node — opaque to consumers. Use serializePresentation() for JSON-safe data. */
|
|
fill?: SafeXmlNode
|
|
/** @internal Raw XML node — opaque to consumers. Use serializePresentation() for JSON-safe data. */
|
|
line?: SafeXmlNode
|
|
isVideo?: boolean
|
|
isAudio?: boolean
|
|
mediaRId?: string
|
|
}
|
|
|
|
/** OOXML encodes srcRect percentages as 1/100000 of full extent. */
|
|
const CROP_DIVISOR = 100000
|
|
|
|
/**
|
|
* Parse a picture XML node (`p:pic`) into PicNodeData.
|
|
*/
|
|
export function parsePicNode(picNode: SafeXmlNode): PicNodeData {
|
|
const base = parseBaseProps(picNode)
|
|
|
|
// --- Blip fill ---
|
|
const blipFill = picNode.child('blipFill')
|
|
const blip = blipFill.child('blip')
|
|
|
|
// Try both namespaced and non-namespaced embed attribute
|
|
const blipEmbed = blip.attr('embed') ?? blip.attr('r:embed')
|
|
const blipLink = blip.attr('link') ?? blip.attr('r:link')
|
|
|
|
// --- Crop (srcRect) ---
|
|
const srcRect = blipFill.child('srcRect')
|
|
let crop: CropRect | undefined
|
|
if (srcRect.exists()) {
|
|
const t = srcRect.numAttr('t')
|
|
const b = srcRect.numAttr('b')
|
|
const l = srcRect.numAttr('l')
|
|
const r = srcRect.numAttr('r')
|
|
if (t !== undefined || b !== undefined || l !== undefined || r !== undefined) {
|
|
crop = {
|
|
top: (t ?? 0) / CROP_DIVISOR,
|
|
bottom: (b ?? 0) / CROP_DIVISOR,
|
|
left: (l ?? 0) / CROP_DIVISOR,
|
|
right: (r ?? 0) / CROP_DIVISOR,
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- Shape properties (fill + line) ---
|
|
const spPr = picNode.child('spPr')
|
|
const solidFill = spPr.child('solidFill')
|
|
const gradFill = spPr.child('gradFill')
|
|
const fill = solidFill.exists() ? solidFill : gradFill.exists() ? gradFill : undefined
|
|
|
|
const ln = spPr.child('ln')
|
|
const line = ln.exists() ? ln : undefined
|
|
|
|
// --- Video / Audio detection ---
|
|
const nvPicPr = picNode.child('nvPicPr')
|
|
const nvPr = nvPicPr.child('nvPr')
|
|
|
|
const videoFile = nvPr.child('videoFile')
|
|
const audioFile = nvPr.child('audioFile')
|
|
|
|
const isVideo = videoFile.exists()
|
|
const isAudio = audioFile.exists()
|
|
|
|
let mediaRId: string | undefined
|
|
if (isVideo) {
|
|
mediaRId = videoFile.attr('link') ?? videoFile.attr('r:link')
|
|
} else if (isAudio) {
|
|
mediaRId = audioFile.attr('link') ?? audioFile.attr('r:link')
|
|
}
|
|
|
|
return {
|
|
...base,
|
|
nodeType: 'picture',
|
|
blipEmbed,
|
|
blipLink,
|
|
crop,
|
|
fill,
|
|
line,
|
|
isVideo: isVideo || undefined,
|
|
isAudio: isAudio || undefined,
|
|
mediaRId,
|
|
}
|
|
}
|