import type { ISlideBackgroundData, ISlideImageElement, ISlidePage, ISlidePageElement, ISlidePageSize, ISlideTransition, SlideModel, SlidePage } from '@univerjs-pro/slides'; import type { Injector } from '@univerjs/core'; import type { IFBlobSource } from '@univerjs/core/facade'; import type { ImageSourceType } from '@univerjs/drawing'; import type { ISlideChartBuilderInfo } from './chart-builder/types'; import type { ISlideImageBuilderInfo } from './f-image'; import type { ISlideShapeBuilderInfo } from './f-shape'; import { FChartBuilderBase } from './chart-builder/chart-builder-base'; import { FChart } from './f-chart'; import { FGroup } from './f-group'; import { FImage, FImageBuilder } from './f-image'; import { FPageElement } from './f-page-element'; import { FShape, FShapeBuilder } from './f-shape'; export interface ISlideImageInsertOptions { id?: string; imageSourceType?: ImageSourceType; left?: number; top?: number; width?: number; height?: number; rotation?: number; crop?: ISlideImageElement['crop']; prstGeom?: ISlideImageElement['prstGeom']; adjustValues?: ISlideImageElement['adjustValues']; index?: number; } /** * The facade class for a slide page. * @hideconstructor */ export declare class FSlide { protected readonly _slideModel: SlideModel; protected readonly _slidePage: SlidePage; protected readonly _injector: Injector; constructor(_slideModel: SlideModel, _slidePage: SlidePage, _injector: Injector); /** * Get the slide id. * @returns {string} The slide id. * * @example * ```ts * const fPresentation = univerAPI.getActivePresentation(); * const fSlide = fPresentation.getActiveSlide(); * console.log(fSlide.getId()); * ``` */ getId(): string; /** * Get the slide name. * @returns {string} The slide name. */ getName(): string; /** * Get the raw slide data. * @returns {ISlidePage} The slide page data. */ getData(): ISlidePage; getTransition(): ISlideTransition | undefined; setTransition(transition?: ISlideTransition): this; /** * Get the underlying slide page model. * @returns {SlidePage} The slide page model. * * @example * ```ts * const fPresentation = univerAPI.getActivePresentation(); * const fSlide = fPresentation.getActiveSlide(); * const slidePage = fSlide.getSlide(); * console.log(slidePage.getId()); * ``` */ getSlide(): SlidePage; /** * Get this slide's page size, falling back to the presentation default. * @returns {ISlidePageSize} The resolved page size. */ getPageSize(): ISlidePageSize; /** * Set this slide's page size. * @param {ISlidePageSize} pageSize The new slide page size. * @returns {FSlide} This slide, for chaining. */ setPageSize(pageSize: ISlidePageSize): this; /** * Get this slide's explicit background. * @returns {ISlideBackgroundData | undefined} The explicit background. */ getBackground(): ISlideBackgroundData | undefined; /** * Set this slide's explicit background. * @param {ISlideBackgroundData} [background] The slide background. Omit to clear it. * @returns {FSlide} This slide, for chaining. */ setBackground(background?: ISlideBackgroundData): this; /** * Set whether this slide shows inherited master shapes and background graphics. * @param {boolean} show Whether inherited master background content is shown. * @returns {FSlide} This slide, for chaining. */ setShowMasterBackground(show: boolean): this; /** * Returns all page elements on this slide. * @returns {FPageElement[]} All page elements in element order. * * @example * ```ts * const fPresentation = univerAPI.getActivePresentation(); * const fSlide = fPresentation.getActiveSlide(); * console.log(fSlide.getElements()); * ``` */ getElements(): FPageElement[]; /** * Returns a page element by element id. * @param {string} id The element id. * @returns {FPageElement | null} The page element, or `null` when it does not exist. * * @example * ```ts * const element = fSlide.getElementById('shape-1'); * console.log(element?.getType()); * ``` */ getElementById(id: string): FPageElement | null; /** * Adds a page element to this slide. * @param {ISlidePageElement} element The slide element data. * @param {number} [index] The insert index in the element order. * @returns {FPageElement} The inserted element. * * @example * ```ts * const shapeInfo = fSlide.newShape() * .setShapeType(univerAPI.Enum.ShapeTypeEnum.Rect) * .build(); * const element = fSlide.insertElement(shapeInfo.element); * console.log(element.getId()); * ``` */ insertElement(element: ISlidePageElement, index?: number): FPageElement; /** * Removes a page element from this slide. * @param {FPageElement | string} element The element or element id to remove. * @returns {boolean} Whether the element was removed successfully. * * @example * ```ts * const element = fSlide.getElements()[0]; * if (element) { * fSlide.deleteElement(element); * } * ``` */ deleteElement(element: FPageElement | string): boolean; /** * Returns a builder to create a new chart for this slide. The builder will not automatically create the chart. * You must call `build()` on the returned builder, then insert it via `fSlide.insertChart(chartInfo)`. * @description Slide charts use a real two-dimensional array as the data source. They do not accept sheet ranges. * @param {FChart} [existing] An existing chart to initialize the builder with for updating. * @returns {FChartBuilderBase} A new chart builder. * * @example * ```ts * const fPresentation = univerAPI.getActivePresentation(); * const fSlide = fPresentation.getActiveSlide(); * * const chartInfo = fSlide.newChart() * .setChartType(univerAPI.Enum.ChartType.Column) * .setData([ * ['Month', 'Sales'], * ['Jan', 120], * ['Feb', 180], * ]) * .setUseFirstRowAsHeaders(true) * .setAbsolutePosition(80, 100) * .setWidth(480) * .setHeight(300) * .build(); * fSlide.insertChart(chartInfo); * ``` */ newChart(existing?: FChart): FChartBuilderBase; /** * Adds a chart to this slide. * @param {ISlideChartBuilderInfo} chartBuilderInfo The chart builder info returned by `FChartBuilderBase.build()`. * @param {number} [index] The insert index in the element order. * @returns {FChart} The inserted chart. */ insertChart(chartBuilderInfo: ISlideChartBuilderInfo, index?: number): FChart; /** * Updates an existing chart on this slide. * @param {ISlideChartBuilderInfo} chartBuilderInfo The chart builder info returned by `FChartBuilderBase.build()`. * @param {ISlideChartElement} chartBuilderInfo.element The chart element data. * @param {ISlideChartDataSource} chartBuilderInfo.dataSource The chart data source. * @param {ChartTypeBits} chartBuilderInfo.chartType The chart type. * @param {ISlideChartBuildOptions} chartBuilderInfo.options The chart build options. * @returns {FChart} The updated chart. * * @example * ```ts * const charts = fSlide.getCharts(); * if (charts.length > 0) { * const chartInfo = charts[0].toBuilder() * .asLineChart() * .setTitle('Updated sales') * .build(); * fSlide.updateChart(chartInfo); * } * ``` */ updateChart(chartBuilderInfo: ISlideChartBuilderInfo): FChart; /** * Returns all charts on this slide. * @returns {FChart[]} The charts on this slide. * * @example * ```ts * const charts = fSlide.getCharts(); * console.log(charts.map((chart) => chart.getChartId())); * ``` */ getCharts(): FChart[]; /** * Returns a chart by chart id or element id. * @param {string} chartIdOrElementId The chart id or element id. * @returns {FChart | null} The chart, or `null` when it does not exist. * * @example * ```ts * const chart = fSlide.getChartById('chart-1'); * console.log(chart?.getDataSource()); * ``` */ getChartById(chartIdOrElementId: string): FChart | null; /** * Removes a chart from this slide. * @param {FChart | string} chart The chart or chart element id to remove. * @returns {boolean} Whether the chart was removed successfully. * * @example * ```ts * const chart = fSlide.getCharts()[0]; * if (chart) { * fSlide.removeChart(chart); * } * ``` */ removeChart(chart: FChart | string): boolean; /** * Returns a builder to create a new shape for this slide. * @param {FShape} [existing] An existing shape to initialize the builder with for updating. * @returns {FShapeBuilder} A new shape builder. * * @example * ```ts * const fPresentation = univerAPI.getActivePresentation(); * const fSlide = fPresentation.getActiveSlide(); * * const shapeInfo = fSlide.newShape() * .setShapeType(univerAPI.Enum.ShapeTypeEnum.Rect) * .setAbsolutePosition(80, 120) * .setWidth(240) * .setHeight(120) * .setShapeSolidFill('#4f90ff') * .build(); * fSlide.insertShape(shapeInfo); * ``` */ newShape(existing?: FShape): FShapeBuilder; /** * Returns a builder to create a text box for this slide. * @returns {FShapeBuilder} A shape builder configured as a text box. * * @example * ```ts * const textBoxInfo = fSlide.newTextBox() * .setText('Quarterly Review') * .setAbsolutePosition(80, 80) * .build(); * fSlide.insertShape(textBoxInfo); * ``` */ newTextBox(): FShapeBuilder; /** * Adds a shape to this slide. * @param {ISlideShapeBuilderInfo} shapeBuilderInfo The shape builder info returned by `FShapeBuilder.build()`. * @param {number} [index] The insert index in the element order. * @returns {FShape} The inserted shape. * * @example * ```ts * const shapeInfo = fSlide.newShape() * .setShapeType(univerAPI.Enum.ShapeTypeEnum.Rect) * .build(); * const shape = fSlide.insertShape(shapeInfo); * console.log(shape.getShapeType()); * ``` */ insertShape(shapeBuilderInfo: ISlideShapeBuilderInfo, index?: number): FShape; /** * Updates an existing shape on this slide. * @param {ISlideShapeBuilderInfo} shapeBuilderInfo The shape builder info returned by `FShapeBuilder.build()`. * @returns {FShape} The updated shape. * * @example * ```ts * const shape = fSlide.getShapes()[0]; * if (shape) { * const shapeInfo = shape.modify() * .setStrokeColor('#ff0000') * .build(); * fSlide.updateShape(shapeInfo); * } * ``` */ updateShape(shapeBuilderInfo: ISlideShapeBuilderInfo): FShape; /** * Returns all shapes on this slide. * @returns {FShape[]} The shapes on this slide. * * @example * ```ts * const shapes = fSlide.getShapes(); * console.log(shapes.length); * ``` */ getShapes(): FShape[]; /** * Removes a shape from this slide. * @param {FShape | string} shape The shape or shape element id to remove. * @returns {boolean} Whether the shape was removed successfully. * * @example * ```ts * const shape = fSlide.getShapes()[0]; * if (shape) { * fSlide.removeShape(shape); * } * ``` */ removeShape(shape: FShape | string): boolean; /** * Returns a builder to create a new image for this slide. The builder will not automatically upload or choose an image. * @param {FImage} [existing] An existing image to initialize the builder with for updating. * @returns {FImageBuilder} A new image builder. * * @example * ```ts * const imageInfo = fSlide.newImage() * .setSource('https://example.com/image.png') * .setAbsolutePosition(80, 120) * .setWidth(320) * .setHeight(180) * .build(); * fSlide.insertImage(imageInfo); * ``` */ newImage(existing?: FImage): FImageBuilder; /** * Adds an image to this slide. * @param {ISlideImageBuilderInfo} imageBuilderInfo The image builder info returned by `FImageBuilder.build()`. * @param {number} [index] The insert index in the element order. * @returns {FImage} The inserted image. * * @example * ```ts * const imageInfo = fSlide.newImage() * .setSource('https://example.com/image.png') * .build(); * const image = fSlide.insertImage(imageInfo); * console.log(image.getSource()); * ``` */ insertImage(imageBuilderInfo: ISlideImageBuilderInfo, index?: number): FImage; /** * Insert an image from a string source or blob source. * @param {string | IFBlobSource} source The image source or blob source. * @param {ISlideImageInsertOptions} [options] Image insertion options. * @returns {Promise} The inserted image. */ insertImageAsync(source: string | IFBlobSource, options?: ISlideImageInsertOptions): Promise; /** * Updates an existing image on this slide. * @param {ISlideImageBuilderInfo} imageBuilderInfo The image builder info returned by `FImageBuilder.build()`. * @returns {FImage} The updated image. * * @example * ```ts * const image = fSlide.getImages()[0]; * if (image) { * const imageInfo = image.modify() * .setWidth(480) * .build(); * fSlide.updateImage(imageInfo); * } * ``` */ updateImage(imageBuilderInfo: ISlideImageBuilderInfo): FImage; /** * Returns all images on this slide. * @returns {FImage[]} The images on this slide. * * @example * ```ts * const images = fSlide.getImages(); * console.log(images.map((image) => image.getSource())); * ``` */ getImages(): FImage[]; /** * Removes an image from this slide. * @param {FImage | string} image The image or image element id to remove. * @returns {boolean} Whether the image was removed successfully. * * @example * ```ts * const image = fSlide.getImages()[0]; * if (image) { * fSlide.removeImage(image); * } * ``` */ removeImage(image: FImage | string): boolean; /** * Returns all group elements on this slide. * @returns {FGroup[]} The groups on this slide. */ getGroups(): FGroup[]; /** * Group two or more slide elements. * @param {Array} elements The elements or element ids to group. * @returns {FGroup} The created group. */ group(elements: Array): FGroup; /** * Ungroup a slide group. * @param {FGroup | string} group The group facade or group id to ungroup. * @returns {FPageElement[]} The released child elements. */ ungroup(group: FGroup | string): FPageElement[]; }