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
96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import { toError } from '@sim/utils/errors'
|
|
import type { ListRenderOptions } from '@/lib/pptx-renderer/core/viewer'
|
|
import { PptxViewer } from '@/lib/pptx-renderer/core/viewer'
|
|
import type { ZipParseLimits } from '@/lib/pptx-renderer/parser/zip-parser'
|
|
|
|
const logger = createLogger('SimPptxViewer')
|
|
|
|
export const SIM_PPTX_ZIP_LIMITS = {
|
|
maxEntries: 2500,
|
|
maxEntryUncompressedBytes: 50 * 1024 * 1024,
|
|
maxTotalUncompressedBytes: 200 * 1024 * 1024,
|
|
maxMediaBytes: 150 * 1024 * 1024,
|
|
maxConcurrency: 8,
|
|
} as const satisfies ZipParseLimits
|
|
|
|
export const SIM_PPTX_LIST_OPTIONS = {
|
|
windowed: true,
|
|
batchSize: 8,
|
|
initialSlides: 4,
|
|
overscanViewport: 1.5,
|
|
} as const satisfies ListRenderOptions
|
|
|
|
export interface OpenSimPptxViewerOptions {
|
|
buffer: ArrayBuffer | Uint8Array
|
|
container: HTMLElement
|
|
scrollContainer?: HTMLElement
|
|
signal?: AbortSignal
|
|
zipLimits?: ZipParseLimits
|
|
listOptions?: ListRenderOptions
|
|
onRenderStart?: () => void
|
|
onRenderComplete?: () => void
|
|
onSlideChange?: (index: number) => void
|
|
onSlideError?: (index: number, error: unknown) => void
|
|
onNodeError?: (nodeId: string, error: unknown) => void
|
|
}
|
|
|
|
export interface SimPptxViewerHandle {
|
|
readonly viewer: PptxViewer
|
|
destroy(): void
|
|
}
|
|
|
|
export async function openSimPptxViewer({
|
|
buffer,
|
|
container,
|
|
scrollContainer,
|
|
signal,
|
|
zipLimits = SIM_PPTX_ZIP_LIMITS,
|
|
listOptions = SIM_PPTX_LIST_OPTIONS,
|
|
onRenderStart,
|
|
onRenderComplete,
|
|
onSlideChange,
|
|
onSlideError,
|
|
onNodeError,
|
|
}: OpenSimPptxViewerOptions): Promise<SimPptxViewerHandle> {
|
|
const viewer = new PptxViewer(container, {
|
|
fitMode: 'contain',
|
|
scrollContainer,
|
|
zipLimits,
|
|
onRenderStart,
|
|
onRenderComplete,
|
|
onSlideChange,
|
|
onSlideError,
|
|
onNodeError,
|
|
})
|
|
|
|
let destroyed = false
|
|
const destroy = () => {
|
|
if (destroyed) return
|
|
destroyed = true
|
|
viewer.destroy()
|
|
}
|
|
|
|
const abortDestroy = () => destroy()
|
|
signal?.addEventListener('abort', abortDestroy, { once: true })
|
|
|
|
try {
|
|
await viewer.open(buffer, {
|
|
renderMode: 'list',
|
|
listOptions,
|
|
signal,
|
|
})
|
|
} catch (error) {
|
|
destroy()
|
|
const normalized = toError(error)
|
|
if (normalized.name !== 'AbortError') {
|
|
logger.warn('Failed to render PPTX preview', { error: normalized.message })
|
|
}
|
|
throw normalized
|
|
} finally {
|
|
signal?.removeEventListener('abort', abortDestroy)
|
|
}
|
|
|
|
return { viewer, destroy }
|
|
}
|