UNPKG

@mescius/dspdfviewer

Version:
186 lines (185 loc) 7 kB
import { AnnotationBase } from "./AnnotationTypes"; /** * Represents a RichMediaAnnotation, a specific type of annotation designed for rich media content. * The annotationType code is 90, designated as AnnotationTypeCode.RICHMEDIA. * The subtype name is "RichMedia". * @example * ```javascript * // Add a RichMedia annotation to the PDF document. * * addRichMedia(viewer, "City_Noises.mp3", "posterFile.png", { width: 300, height: 150, topMargin: 100, mediaFileType: "mp3" }); * * async function addRichMedia(viewer, mediaUrl, posterUrl, args) { * const { width, height, topMargin, mediaFileType } = args; * * const mediaBytes = await fetchBytes(mediaUrl); * const posterBytes = await fetchBytes(posterUrl); * * const fileId = new Date().getTime() + "." + mediaFileType; * const fileName = fileId; * const posterFileId = new Date().getTime() + ".png"; * const posterFileName = posterFileId; * * const pageIndex = 0; * * const pageViewBox = viewer.getViewPort(pageIndex).viewBox; * * const rect = [ * (pageViewBox[2] - width) / 2, * pageViewBox[3] - topMargin - height, * (pageViewBox[2] - width) / 2 + width, * pageViewBox[3] - topMargin * ]; * * viewer.storage.setItem(fileId, mediaBytes); * viewer.storage.setItem(posterFileId, posterBytes); * * viewer.addAnnotation(pageIndex, { * annotationType: 90, // RICHMEDIA * subtype: "RichMedia", * fileId, * fileName, * posterFileId, * posterFileName, * activationCondition: "XA", * deactivationCondition: "XD", * presentationStyle: "Embedded", * showNavigationPane: false, * rect * }); * } * * function fetchBytes(url) { * return new Promise(function (resolve) { * fetch(url).then(response => response.blob()).then(blob => blob.arrayBuffer()).then(arrayBuffer => { resolve(new Uint8Array(arrayBuffer)); }); * }); * } * ``` */ export declare class RichMediaAnnotation extends AnnotationBase { /** * Media file attachment identifier. * @example * ```javascript * // Get media file attachment data: * const fileData = viewer.storage.getItem(annotation.fileId); * ``` **/ fileId?: string; /** * Media file name. **/ fileName?: string; /** * @ignore exclude from docs **/ fileLength?: number; /** * @ignore exclude from docs **/ fileIdChanged?: boolean; /** * Poster file attachment identifier. * @example * ```javascript * // Get poster file attachment data: * const fileData = viewer.storage.getItem(annotation.posterFileId); * ``` **/ posterFileId?: string; /** * Poster file name. **/ posterFileName?: string; /** * @ignore exclude from docs **/ posterFileLength?: number; /** * @ignore exclude from docs **/ posterFileIdChanged?: boolean; /** * Rich media activation condition. * Possible values: * - "XA": Explicit activation. Occurs when the user clicks on the media. * - "PO": Page open. Activation takes place when the page containing the rich media annotation receives focus as the current page. * - "PV": Page visible. Activation occurs when the media container or any of its parts becomes visible in the active view. * @default "XA" */ activationCondition: "XA" | "PO" | "PV"; /** * Rich media deactivation condition. * Possible values: * - "XD": Explicit deactivation. Occurs when the user clicks on the media. * - "PC": Page close. Deactivation takes place when the page containing the rich media annotation loses focus as the current page. * - "PI": Page invisible. Deactivation occurs when the media container becomes invisible in the active view. * @default "XD" */ deactivationCondition: "XD" | "PC" | "PI"; /** * Rich media presentation style. * @default "Embedded" */ presentationStyle: "Embedded" | "Windowed"; /** * Determines whether to show playback controls. * @default false */ showNavigationPane: boolean; /** * Constructor for RichMediaAnnotation. * Initializes properties and sets the annotation type and subtype. */ constructor(); } /** * Represents rich media content within a RichMediaAnnotation. * * @typedef {Object} RichMediaContent * @property {Object} assets - Configuration for rich media assets. * @property {(string | { content: Uint8Array; filename: string; })[]} assets.names - Array of asset names or objects containing content and filename. */ export type RichMediaContent = { assets: { names: (string | { content: Uint8Array; filename: string; })[]; }; }; /** * Represents rich media settings within a RichMediaAnnotation. * * @typedef {Object} RichMediaSettings * @property {Object} activation - Configuration for rich media activation. * @property {"XA" | "PO" | "PV"} activation.condition - Activation condition. Possible values: "XA" (Explicit activation), "PO" (Page Open), or "PV" (Page Visible). * @property {Object} activation.presentation - Presentation settings for activation. * @property {boolean} activation.presentation.navigationPane - If true, the navigation pane should be visible when the content is initially activated. If false, the navigation pane should not displayed by default. * @property {boolean} activation.presentation.passContextClick - Whether to pass context click events during activation. * @property {'Embedded' | 'Windowed'} activation.presentation.style - Style of presentation during activation ('Embedded' or 'Windowed'). * @property {boolean} activation.presentation.toolbar - Whether to show the toolbar during activation. * @property {boolean} activation.presentation.transparent - Whether the presentation is transparent during activation. * @property {"RichMediaActivation"} activation.type - Type of activation ("RichMediaActivation"). * @property {Object} deactivation - Configuration for rich media deactivation. * @property {"XD" | "PC" | "PI"} deactivation.condition - Deactivation condition. Possible values: "XD" (Explicit deactivation), "PC" (Page Close), or "PI" (Page Invisible). * @property {"RichMediaDeactivation"} deactivation.type - Type of deactivation ("RichMediaDeactivation"). * @ignore internal type */ export type RichMediaSettings = { activation: { condition: "XA" | "PO" | "PV"; presentation: { navigationPane: boolean; passContextClick: boolean; style: 'Embedded' | 'Windowed'; toolbar: boolean; transparent: boolean; }; type: "RichMediaActivation"; }; deactivation: { condition: "XD" | "PC" | "PI"; type: "RichMediaDeactivation"; }; };