{"ast":null,"code":"import { HEADING_PATTERN, PDF_ROLE_TO_HTML_ROLE } from './constants.js';\nexport function isPdfRole(role) {\n  return role in PDF_ROLE_TO_HTML_ROLE;\n}\nexport function isStructTreeNode(node) {\n  return 'children' in node;\n}\nexport function isStructTreeNodeWithOnlyContentChild(node) {\n  if (!isStructTreeNode(node)) {\n    return false;\n  }\n  return node.children.length === 1 && 0 in node.children && 'id' in node.children[0];\n}\nexport function getRoleAttributes(node) {\n  const attributes = {};\n  if (isStructTreeNode(node)) {\n    const {\n      role\n    } = node;\n    const matches = role.match(HEADING_PATTERN);\n    if (matches) {\n      attributes.role = 'heading';\n      attributes['aria-level'] = Number(matches[1]);\n    } else if (isPdfRole(role)) {\n      const htmlRole = PDF_ROLE_TO_HTML_ROLE[role];\n      if (htmlRole) {\n        attributes.role = htmlRole;\n      }\n    }\n  }\n  return attributes;\n}\nexport function getBaseAttributes(node) {\n  const attributes = {};\n  if (isStructTreeNode(node)) {\n    if (node.alt !== undefined) {\n      attributes['aria-label'] = node.alt;\n    }\n    if (node.lang !== undefined) {\n      attributes.lang = node.lang;\n    }\n    if (isStructTreeNodeWithOnlyContentChild(node)) {\n      const [child] = node.children;\n      if (child) {\n        const childAttributes = getBaseAttributes(child);\n        return Object.assign(Object.assign({}, attributes), childAttributes);\n      }\n    }\n  } else {\n    if ('id' in node) {\n      attributes['aria-owns'] = node.id;\n    }\n  }\n  return attributes;\n}\nexport function getAttributes(node) {\n  if (!node) {\n    return null;\n  }\n  return Object.assign(Object.assign({}, getRoleAttributes(node)), getBaseAttributes(node));\n}","map":{"version":3,"names":["HEADING_PATTERN","PDF_ROLE_TO_HTML_ROLE","isPdfRole","role","isStructTreeNode","node","isStructTreeNodeWithOnlyContentChild","children","length","getRoleAttributes","attributes","matches","match","Number","htmlRole","getBaseAttributes","alt","undefined","lang","child","childAttributes","Object","assign","id","getAttributes"],"sources":["/var/www/gavt/node_modules/react-pdf/dist/esm/shared/structTreeUtils.js"],"sourcesContent":["import { HEADING_PATTERN, PDF_ROLE_TO_HTML_ROLE } from './constants.js';\nexport function isPdfRole(role) {\n    return role in PDF_ROLE_TO_HTML_ROLE;\n}\nexport function isStructTreeNode(node) {\n    return 'children' in node;\n}\nexport function isStructTreeNodeWithOnlyContentChild(node) {\n    if (!isStructTreeNode(node)) {\n        return false;\n    }\n    return node.children.length === 1 && 0 in node.children && 'id' in node.children[0];\n}\nexport function getRoleAttributes(node) {\n    const attributes = {};\n    if (isStructTreeNode(node)) {\n        const { role } = node;\n        const matches = role.match(HEADING_PATTERN);\n        if (matches) {\n            attributes.role = 'heading';\n            attributes['aria-level'] = Number(matches[1]);\n        }\n        else if (isPdfRole(role)) {\n            const htmlRole = PDF_ROLE_TO_HTML_ROLE[role];\n            if (htmlRole) {\n                attributes.role = htmlRole;\n            }\n        }\n    }\n    return attributes;\n}\nexport function getBaseAttributes(node) {\n    const attributes = {};\n    if (isStructTreeNode(node)) {\n        if (node.alt !== undefined) {\n            attributes['aria-label'] = node.alt;\n        }\n        if (node.lang !== undefined) {\n            attributes.lang = node.lang;\n        }\n        if (isStructTreeNodeWithOnlyContentChild(node)) {\n            const [child] = node.children;\n            if (child) {\n                const childAttributes = getBaseAttributes(child);\n                return Object.assign(Object.assign({}, attributes), childAttributes);\n            }\n        }\n    }\n    else {\n        if ('id' in node) {\n            attributes['aria-owns'] = node.id;\n        }\n    }\n    return attributes;\n}\nexport function getAttributes(node) {\n    if (!node) {\n        return null;\n    }\n    return Object.assign(Object.assign({}, getRoleAttributes(node)), getBaseAttributes(node));\n}\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,qBAAqB,QAAQ,gBAAgB;AACvE,OAAO,SAASC,SAASA,CAACC,IAAI,EAAE;EAC5B,OAAOA,IAAI,IAAIF,qBAAqB;AACxC;AACA,OAAO,SAASG,gBAAgBA,CAACC,IAAI,EAAE;EACnC,OAAO,UAAU,IAAIA,IAAI;AAC7B;AACA,OAAO,SAASC,oCAAoCA,CAACD,IAAI,EAAE;EAC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