Files
simstudioai--sim/apps/sim/lib/pptx-renderer/parser/units.ts
T
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

60 lines
1.6 KiB
TypeScript

/**
* Unit conversion utilities for OOXML / PPTX.
*
* PPTX uses several unit systems:
* - EMU (English Metric Units): 1 inch = 914400 EMU
* - Points: 1 inch = 72 pt
* - Hundredths of a point: used for font sizes
* - 60000ths of a degree: used for angles
* - 100000ths (percentage): used for scale factors
*/
/** EMU to pixels (at 96 DPI). */
export function emuToPx(emu: number): number {
return (emu / 914400) * 96
}
/** EMU to points. */
export function emuToPt(emu: number): number {
return emu / 12700
}
/** OOXML angle (60000ths of a degree) to degrees. */
export function angleToDeg(angle: number): number {
return angle / 60000
}
/** OOXML percentage (100000ths) to a decimal fraction (0..1 range for 0%..100%). */
export function pctToDecimal(pct: number): number {
return pct / 100000
}
/** Hundredths of a point to points (used for font sizes in OOXML). */
export function hundredthPtToPt(val: number): number {
return val / 100
}
/** Points to pixels (at 96 DPI). */
export function ptToPx(pt: number): number {
return (pt * 96) / 72
}
/**
* Heuristic: detect whether a value is in EMU or points.
* Values with abs > 20000 are almost certainly EMU (a single point = 12700 EMU).
*/
export function detectUnit(value: number): 'emu' | 'point' {
return Math.abs(value) > 20000 ? 'emu' : 'point'
}
/**
* Smart conversion to pixels: auto-detects whether the value is EMU or points
* and converts accordingly.
*/
export function smartToPx(value: number): number {
if (detectUnit(value) === 'emu') {
return emuToPx(value)
}
return ptToPx(value)
}