@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.
80 lines • 2.85 kB
JavaScript
;
/**
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.botaMenus = exports.menus = void 0;
exports.mergeDeep = mergeDeep;
const CPDFEnumUtils_1 = require("../util/CPDFEnumUtils");
const HEX_COLOR_REGEX = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
/**
* Deep merge utility for configuration objects.
* Handles arrays, objects, and color normalization.
*/
function mergeDeep(defaults, overrides) {
const merged = {};
const keys = new Set([
...Object.keys(defaults || {}),
...Object.keys(overrides || {}),
]);
for (const key of keys) {
const defaultValue = defaults?.[key];
const overrideValue = overrides?.[key];
let value;
if (overrideValue !== undefined) {
if (Array.isArray(overrideValue)) {
value = [...overrideValue];
}
else if (overrideValue && typeof overrideValue === "object") {
value = mergeDeep(defaultValue || {}, overrideValue);
}
else {
value = overrideValue;
}
}
else {
if (Array.isArray(defaultValue)) {
value = [...defaultValue];
}
else if (defaultValue && typeof defaultValue === "object") {
value = mergeDeep(defaultValue, {});
}
else {
value = defaultValue;
}
}
if (typeof value === "string" && HEX_COLOR_REGEX.test(value)) {
try {
value = (0, CPDFEnumUtils_1.normalizeColorToARGB)(value);
}
catch { }
}
merged[key] = value;
}
return merged;
}
/**
* Helper function to create context menu items with default showType.
*/
const menus = (...items) => items.map((item) => {
if (typeof item === "string") {
// Provide default showType for simple string menu items
return { key: item, showType: "text" };
}
// Ensure object items have a showType; preserve provided value if exists
return item.showType
? item
: { ...item, showType: "text" };
});
exports.menus = menus;
/**
* Helper function to create BOTA menu items.
*/
const botaMenus = (...items) => items.map((item) => (typeof item === "string" ? { id: item } : item));
exports.botaMenus = botaMenus;
//# sourceMappingURL=ConfigHelpers.js.map