UNPKG

@compdfkit_pdf_sdk/react_native

Version:

ComPDFKit for React Native is a comprehensive SDK that allows you to quickly add PDF functionality to Android, iOS, and React Native applications.

96 lines 3.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CPDFWidget = void 0; /** * Copyright © 2014-2026 PDF Technologies, Inc. All Rights Reserved. * * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT. * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES. * This notice may not be removed from this file. */ const CPDFOptions_1 = require("../../configuration/CPDFOptions"); /** * Base class for form widgets, storing essential form information. * * This class represents a form widget in a PDF document, containing basic attributes * such as type, title, and the page it appears on. * The `fromJson` method allows converting JSON data into form widget objects. * * @class CPDFWidget * @group Forms * @property {CPDFWidgetType} type - The type of the form widget. * @property {string} title - The title of the form widget (default: empty string). * @property {number} page - The page number where the form widget appears (default: 0). * @property {string} uuid - The unique identifier for the form widget (default: empty string). * @property {Date | null} modifyDate - The date when the form widget was last modified (default: null). * @property {Date | null} createDate - The date when the form widget was created (default: null). * @property {CPDFRectF | null} rect - The rectangular coordinates of the form widget (default: null). * @property {string} borderColor - The border color of the form widget (default: '#000000'). * @property {string} fillColor - The fill color of the form widget (default: '#000000'). */ class CPDFWidget { /** * The type of the form widget. */ type; /** * The title of the form widget (default: empty string). */ title; /** * The page number where the form widget appears (default: 0). */ page; uuid; createDate = null; rect = null; borderColor; fillColor; borderWidth; constructor(params) { this.type = CPDFWidget.parseType(params.type); this.title = params.title ?? ""; this.page = params.page ?? 0; this.uuid = params.uuid ?? ""; this.createDate = params.createDate != null ? new Date(params.createDate) : null; this.rect = params.rect ?? null; this.borderColor = params.borderColor ?? '#000000'; this.fillColor = params.fillColor ?? '#000000'; this.borderWidth = params.borderWidth ?? 0; } static fromJson(json) { return new this(json); } static fromJsonArray(jsonArray) { return jsonArray.map(item => new this(item)); } static parseType(type) { return Object.values(CPDFOptions_1.CPDFWidgetType).includes(type) ? type : CPDFOptions_1.CPDFWidgetType.UNKNOWN; } toJSON() { const { createDate, ...data } = this; return { ...data, ...(createDate && { createDate: createDate.getTime() }), borderColor: this.borderColor, fillColor: this.fillColor, borderWidth: this.borderWidth }; } /** * Update widget properties in a type-safe way * @param updates Partial object containing properties to update * @returns this instance for chaining * * @example * widget.update({ title: 'New Title', fillColor: '#FF0000', borderColor: '#00FF00' }); * await document.updateWidget(widget); */ update(updates) { Object.assign(this, updates); return this; } } exports.CPDFWidget = CPDFWidget; //# sourceMappingURL=CPDFWidget.js.map