"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OOXML_REL_TARGETS = exports.OOXML_PATHS = void 0;
exports.normalizeZipPath = normalizeZipPath;
exports.getWorksheetNoFromWorksheetPath = getWorksheetNoFromWorksheetPath;
exports.getWorksheetNoFromWorksheetRelsPath = getWorksheetNoFromWorksheetRelsPath;
exports.isMediaPath = isMediaPath;
exports.getMediaFilenameFromPath = getMediaFilenameFromPath;
exports.isThemePath = isThemePath;
exports.getThemeNameFromPath = getThemeNameFromPath;
exports.isBinaryEntryPath = isBinaryEntryPath;
exports.getDrawingNameFromPath = getDrawingNameFromPath;
exports.getDrawingNameFromRelsPath = getDrawingNameFromRelsPath;
exports.getVmlDrawingNameFromPath = getVmlDrawingNameFromPath;
exports.getCommentsIndexFromPath = getCommentsIndexFromPath;
exports.getTableNameFromPath = getTableNameFromPath;
exports.getPivotTableNameFromPath = getPivotTableNameFromPath;
exports.getPivotTableNameFromRelsPath = getPivotTableNameFromRelsPath;
exports.getPivotCacheDefinitionNameFromPath = getPivotCacheDefinitionNameFromPath;
exports.getPivotCacheDefinitionNameFromRelsPath = getPivotCacheDefinitionNameFromRelsPath;
exports.getPivotCacheRecordsNameFromPath = getPivotCacheRecordsNameFromPath;
exports.toContentTypesPartName = toContentTypesPartName;
exports.themePath = themePath;
exports.mediaPath = mediaPath;
exports.worksheetPath = worksheetPath;
exports.worksheetRelsPath = worksheetRelsPath;
exports.worksheetRelTarget = worksheetRelTarget;
exports.commentsPath = commentsPath;
exports.commentsPathFromName = commentsPathFromName;
exports.vmlDrawingPath = vmlDrawingPath;
exports.tablePath = tablePath;
exports.drawingPath = drawingPath;
exports.drawingRelsPath = drawingRelsPath;
exports.pivotCacheDefinitionPath = pivotCacheDefinitionPath;
exports.pivotCacheDefinitionRelsPath = pivotCacheDefinitionRelsPath;
exports.pivotCacheRecordsPath = pivotCacheRecordsPath;
exports.pivotCacheRecordsRelTarget = pivotCacheRecordsRelTarget;
exports.pivotTablePath = pivotTablePath;
exports.pivotTableRelsPath = pivotTableRelsPath;
exports.pivotCacheDefinitionRelTargetFromPivotTable = pivotCacheDefinitionRelTargetFromPivotTable;
exports.pivotCacheDefinitionRelTargetFromWorkbook = pivotCacheDefinitionRelTargetFromWorkbook;
exports.commentsRelTargetFromWorksheet = commentsRelTargetFromWorksheet;
exports.vmlDrawingRelTargetFromWorksheet = vmlDrawingRelTargetFromWorksheet;
exports.drawingRelTargetFromWorksheet = drawingRelTargetFromWorksheet;
exports.vmlDrawingRelTargetFromWorksheetName = vmlDrawingRelTargetFromWorksheetName;
exports.commentsRelTargetFromWorksheetName = commentsRelTargetFromWorksheetName;
exports.pivotTableRelTargetFromWorksheet = pivotTableRelTargetFromWorksheet;
exports.pivotTableRelTargetFromWorksheetName = pivotTableRelTargetFromWorksheetName;
exports.tableRelTargetFromWorksheet = tableRelTargetFromWorksheet;
exports.tableRelTargetFromWorksheetName = tableRelTargetFromWorksheetName;
exports.mediaRelTargetFromRels = mediaRelTargetFromRels;
exports.ctrlPropPath = ctrlPropPath;
exports.ctrlPropRelTargetFromWorksheet = ctrlPropRelTargetFromWorksheet;
exports.OOXML_PATHS = {
    contentTypes: "[Content_Types].xml",
    rootRels: "_rels/.rels",
    docPropsApp: "docProps/app.xml",
    docPropsCore: "docProps/core.xml",
    xlWorkbook: "xl/workbook.xml",
    xlWorkbookRels: "xl/_rels/workbook.xml.rels",
    xlSharedStrings: "xl/sharedStrings.xml",
    xlStyles: "xl/styles.xml",
    xlTheme1: "xl/theme/theme1.xml",
    xlFeaturePropertyBag: "xl/featurePropertyBag/featurePropertyBag.xml"
};
const worksheetXmlRegex = /^xl\/worksheets\/sheet(\d+)[.]xml$/;
const worksheetRelsXmlRegex = /^xl\/worksheets\/_rels\/sheet(\d+)[.]xml[.]rels$/;
const themeXmlRegex = /^xl\/theme\/[a-zA-Z0-9]+[.]xml$/;
const mediaFilenameRegex = /^xl\/media\/([a-zA-Z0-9]+[.][a-zA-Z0-9]{3,4})$/;
const drawingXmlRegex = /^xl\/drawings\/(drawing\d+)[.]xml$/;
const drawingRelsXmlRegex = /^xl\/drawings\/_rels\/(drawing\d+)[.]xml[.]rels$/;
const vmlDrawingRegex = /^xl\/drawings\/(vmlDrawing\d+)[.]vml$/;
const commentsXmlRegex = /^xl\/comments(\d+)[.]xml$/;
const tableXmlRegex = /^xl\/tables\/(table\d+)[.]xml$/;
const pivotTableXmlRegex = /^xl\/pivotTables\/(pivotTable\d+)[.]xml$/;
const pivotTableRelsXmlRegex = /^xl\/pivotTables\/_rels\/(pivotTable\d+)[.]xml[.]rels$/;
const pivotCacheDefinitionXmlRegex = /^xl\/pivotCache\/(pivotCacheDefinition\d+)[.]xml$/;
const pivotCacheDefinitionRelsXmlRegex = /^xl\/pivotCache\/_rels\/(pivotCacheDefinition\d+)[.]xml[.]rels$/;
const pivotCacheRecordsXmlRegex = /^xl\/pivotCache\/(pivotCacheRecords\d+)[.]xml$/;
function normalizeZipPath(path) {
    return path.startsWith("/") ? path.slice(1) : path;
}
function getWorksheetNoFromWorksheetPath(path) {
    const match = worksheetXmlRegex.exec(path);
    if (!match) {
        return undefined;
    }
    return parseInt(match[1], 10);
}
function getWorksheetNoFromWorksheetRelsPath(path) {
    const match = worksheetRelsXmlRegex.exec(path);
    if (!match) {
        return undefined;
    }
    return parseInt(match[1], 10);
}
function isMediaPath(path) {
    return path.startsWith("xl/media/");
}
function getMediaFilenameFromPath(path) {
    const match = mediaFilenameRegex.exec(path);
    return match ? match[1] : undefined;
}
function isThemePath(path) {
    return themeXmlRegex.test(path);
}
function getThemeNameFromPath(path) {
    const match = /^xl\/theme\/([a-zA-Z0-9]+)[.]xml$/.exec(path);
    return match ? match[1] : undefined;
}
function isBinaryEntryPath(path) {
    // Media and themes should be treated as binary in the legacy buffer-based reader.
    // Everything else is parsed as text XML.
    return isMediaPath(path) || isThemePath(path);
}
function getDrawingNameFromPath(path) {
    const match = drawingXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function getDrawingNameFromRelsPath(path) {
    const match = drawingRelsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function getVmlDrawingNameFromPath(path) {
    const match = vmlDrawingRegex.exec(path);
    return match ? match[1] : undefined;
}
function getCommentsIndexFromPath(path) {
    const match = commentsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function getTableNameFromPath(path) {
    const match = tableXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function getPivotTableNameFromPath(path) {
    const match = pivotTableXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function getPivotTableNameFromRelsPath(path) {
    const match = pivotTableRelsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function getPivotCacheDefinitionNameFromPath(path) {
    const match = pivotCacheDefinitionXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function getPivotCacheDefinitionNameFromRelsPath(path) {
    const match = pivotCacheDefinitionRelsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function getPivotCacheRecordsNameFromPath(path) {
    const match = pivotCacheRecordsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
function toContentTypesPartName(zipPath) {
    // ContentTypes uses leading slash PartName (e.g. "/xl/workbook.xml").
    return zipPath.startsWith("/") ? zipPath : `/${zipPath}`;
}
function themePath(themeName) {
    return `xl/theme/${themeName}.xml`;
}
function mediaPath(filename) {
    return `xl/media/${filename}`;
}
function worksheetPath(sheetId) {
    return `xl/worksheets/sheet${sheetId}.xml`;
}
function worksheetRelsPath(sheetId) {
    return `xl/worksheets/_rels/sheet${sheetId}.xml.rels`;
}
function worksheetRelTarget(sheetId) {
    return `worksheets/sheet${sheetId}.xml`;
}
function commentsPath(sheetId) {
    return `xl/comments${sheetId}.xml`;
}
function commentsPathFromName(commentName) {
    // For comments when the caller already has the logical name (e.g. "comments1").
    return `xl/${commentName}.xml`;
}
function vmlDrawingPath(sheetId) {
    return `xl/drawings/vmlDrawing${sheetId}.vml`;
}
function tablePath(target) {
    return `xl/tables/${target}`;
}
function drawingPath(drawingName) {
    return `xl/drawings/${drawingName}.xml`;
}
function drawingRelsPath(drawingName) {
    return `xl/drawings/_rels/${drawingName}.xml.rels`;
}
function pivotCacheDefinitionPath(n) {
    return `xl/pivotCache/pivotCacheDefinition${n}.xml`;
}
function pivotCacheDefinitionRelsPath(n) {
    return `xl/pivotCache/_rels/pivotCacheDefinition${n}.xml.rels`;
}
function pivotCacheRecordsPath(n) {
    return `xl/pivotCache/pivotCacheRecords${n}.xml`;
}
function pivotCacheRecordsRelTarget(n) {
    return `pivotCacheRecords${n}.xml`;
}
function pivotTablePath(n) {
    return `xl/pivotTables/pivotTable${n}.xml`;
}
function pivotTableRelsPath(n) {
    return `xl/pivotTables/_rels/pivotTable${n}.xml.rels`;
}
function pivotCacheDefinitionRelTargetFromPivotTable(n) {
    return `../pivotCache/pivotCacheDefinition${n}.xml`;
}
exports.OOXML_REL_TARGETS = {
    // Targets inside xl/_rels/workbook.xml.rels (base: xl/)
    workbookStyles: "styles.xml",
    workbookSharedStrings: "sharedStrings.xml",
    workbookTheme1: "theme/theme1.xml",
    workbookFeaturePropertyBag: "featurePropertyBag/featurePropertyBag.xml"
};
function pivotCacheDefinitionRelTargetFromWorkbook(n) {
    // Target inside xl/_rels/workbook.xml.rels (base: xl/)
    return `pivotCache/pivotCacheDefinition${n}.xml`;
}
function commentsRelTargetFromWorksheet(sheetId) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../comments${sheetId}.xml`;
}
function vmlDrawingRelTargetFromWorksheet(sheetId) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../drawings/vmlDrawing${sheetId}.vml`;
}
function drawingRelTargetFromWorksheet(drawingName) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../drawings/${drawingName}.xml`;
}
function vmlDrawingRelTargetFromWorksheetName(vmlName) {
    // For VML drawings when the caller already has the logical name (e.g. "vmlDrawing1").
    return `../drawings/${vmlName}.vml`;
}
function commentsRelTargetFromWorksheetName(commentName) {
    // For comments when the caller already has the logical name (e.g. "comments1").
    return `../${commentName}.xml`;
}
function pivotTableRelTargetFromWorksheet(n) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../pivotTables/pivotTable${n}.xml`;
}
function pivotTableRelTargetFromWorksheetName(pivotName) {
    // For pivot tables when the caller already has the logical name (e.g. "pivotTable1").
    return `../pivotTables/${pivotName}.xml`;
}
function tableRelTargetFromWorksheet(target) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../tables/${target}`;
}
function tableRelTargetFromWorksheetName(name) {
    return `../tables/${name}.xml`;
}
function mediaRelTargetFromRels(filename) {
    // Target from a rels file located under xl/*/_rels (base is one level deeper than xl/)
    return `../media/${filename}`;
}
// Form Control (ctrlProps) path functions
function ctrlPropPath(id) {
    return `xl/ctrlProps/ctrlProp${id}.xml`;
}
function ctrlPropRelTargetFromWorksheet(id) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../ctrlProps/ctrlProp${id}.xml`;
}
