{"version":3,"file":"tree-Bbs1C8Rc.mjs","names":[],"sources":["../src/xml/namespaces.ts","../src/xml/tree.ts"],"sourcesContent":["// OOXML namespace and well-known package-path constants.\n//\n// Mirrors openpyxl/openpyxl/xml/constants.py so the test corpus stays directly\n// comparable. Where openpyxl exposes a single big dict (NAMESPACES) we keep\n// them as discrete `const` exports — bundlers can then drop the ones a given\n// build path never imports.\n\n// ---- W3C / Dublin Core ------------------------------------------------------\n\nexport const XML_NS = 'http://www.w3.org/XML/1998/namespace';\nexport const XSI_NS = 'http://www.w3.org/2001/XMLSchema-instance';\n\nexport const DCORE_NS = 'http://purl.org/dc/elements/1.1/';\nexport const DCTERMS_NS = 'http://purl.org/dc/terms/';\nexport const DCMITYPE_NS = 'http://purl.org/dc/dcmitype/';\nexport const DCTERMS_PREFIX = 'dcterms';\n\n// ---- ECMA-376 Office Document core ------------------------------------------\n\nconst DOC_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/';\nexport const REL_NS = `${DOC_NS}relationships`;\nexport const COMMENTS_NS = `${REL_NS}/comments`;\nexport const IMAGE_NS = `${REL_NS}/image`;\nexport const VML_NS = `${REL_NS}/vmlDrawing`;\nexport const EXTERNAL_LINK_NS = `${REL_NS}/externalLink`;\nexport const VTYPES_NS = `${DOC_NS}docPropsVTypes`;\nexport const XPROPS_NS = `${DOC_NS}extended-properties`;\nexport const CUSTPROPS_NS = `${DOC_NS}custom-properties`;\nexport const CPROPS_FMTID = '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}';\n\n// ---- Package layer ----------------------------------------------------------\n\nconst PKG_NS = 'http://schemas.openxmlformats.org/package/2006/';\nexport const PKG_REL_NS = `${PKG_NS}relationships`;\nexport const COREPROPS_NS = `${PKG_NS}metadata/core-properties`;\nexport const CONTYPES_NS = `${PKG_NS}content-types`;\n\n// ---- SpreadsheetML & DrawingML ----------------------------------------------\n\nexport const SHEET_MAIN_NS = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main';\nexport const CHART_NS = 'http://schemas.openxmlformats.org/drawingml/2006/chart';\nexport const DRAWING_NS = 'http://schemas.openxmlformats.org/drawingml/2006/main';\nexport const SHEET_DRAWING_NS = 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing';\nexport const CHART_DRAWING_NS = 'http://schemas.openxmlformats.org/drawingml/2006/chartDrawing';\nexport const PICTURE_NS = 'http://schemas.openxmlformats.org/drawingml/2006/picture';\n\n// ---- Microsoft extensions ---------------------------------------------------\n\nexport const CUSTOMUI_NS = 'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility';\nexport const MARKUP_COMPAT_NS = 'http://schemas.openxmlformats.org/markup-compatibility/2006';\nexport const X14_NS = 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main';\nexport const X15_NS = 'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main';\nexport const X16_NS = 'http://schemas.microsoft.com/office/spreadsheetml/2014/revision';\nexport const C14_NS = 'http://schemas.microsoft.com/office/drawing/2010/chart';\nexport const C15_NS = 'http://schemas.microsoft.com/office/drawing/2012/chart';\nexport const C16_NS = 'http://schemas.microsoft.com/office/drawing/2017/03/chart';\nexport const CX_NS = 'http://schemas.microsoft.com/office/drawing/2014/chartex';\nexport const THREADED_COMMENTS_NS = 'http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments';\n\n// ---- Default prefix map -----------------------------------------------------\n//\n// Used when serialising XmlNode trees back to text: prefer these prefixes for\n// namespaces we recognise so output matches what Excel / openpyxl\n// conventionally emit. Entries are intentionally short — full prefix discovery\n// falls back to auto-generated names (`ns0`, `ns1`, ...) for namespaces not\n// listed here.\n\nexport const DEFAULT_PREFIXES: Readonly<Record<string, string>> = Object.freeze({\n  [XML_NS]: 'xml',\n  [XSI_NS]: 'xsi',\n  [DCORE_NS]: 'dc',\n  [DCTERMS_NS]: DCTERMS_PREFIX,\n  [DCMITYPE_NS]: 'dcmitype',\n  [REL_NS]: 'r',\n  [VTYPES_NS]: 'vt',\n  // app.xml uses XPROPS_NS as its default namespace; custom.xml uses\n  // CUSTPROPS_NS the same way. Mark them as '' so serialised output matches\n  // Office / openpyxl convention out of the box.\n  [XPROPS_NS]: '',\n  [CUSTPROPS_NS]: '',\n  [PKG_REL_NS]: '',\n  [COREPROPS_NS]: 'cp',\n  [CONTYPES_NS]: '',\n  [SHEET_MAIN_NS]: '',\n  [CHART_NS]: 'c',\n  [DRAWING_NS]: 'a',\n  [SHEET_DRAWING_NS]: 'xdr',\n  [CHART_DRAWING_NS]: 'cdr',\n  [PICTURE_NS]: 'pic',\n  [MARKUP_COMPAT_NS]: 'mc',\n  [X14_NS]: 'x14',\n  [X15_NS]: 'x15',\n  [X16_NS]: 'x16',\n  [C14_NS]: 'c14',\n  [C15_NS]: 'c15',\n  [C16_NS]: 'c16',\n  [CX_NS]: 'cx',\n  [THREADED_COMMENTS_NS]: 'tc',\n});\n\n// ---- ZIP package paths ------------------------------------------------------\n\nexport const PACKAGE_PROPS = 'docProps';\nexport const PACKAGE_XL = 'xl';\nexport const PACKAGE_RELS = '_rels';\nexport const PACKAGE_THEME = `${PACKAGE_XL}/theme`;\nexport const PACKAGE_WORKSHEETS = `${PACKAGE_XL}/worksheets`;\nexport const PACKAGE_CHARTSHEETS = `${PACKAGE_XL}/chartsheets`;\nexport const PACKAGE_DRAWINGS = `${PACKAGE_XL}/drawings`;\nexport const PACKAGE_CHARTS = `${PACKAGE_XL}/charts`;\nexport const PACKAGE_IMAGES = `${PACKAGE_XL}/media`;\nexport const PACKAGE_PIVOT_TABLE = `${PACKAGE_XL}/pivotTables`;\nexport const PACKAGE_PIVOT_CACHE = `${PACKAGE_XL}/pivotCache`;\nexport const PACKAGE_WORKSHEET_RELS = `${PACKAGE_WORKSHEETS}/${PACKAGE_RELS}`;\nexport const PACKAGE_CHARTSHEETS_RELS = `${PACKAGE_CHARTSHEETS}/${PACKAGE_RELS}`;\n\nexport const ARC_CONTENT_TYPES = '[Content_Types].xml';\nexport const ARC_ROOT_RELS = `${PACKAGE_RELS}/.rels`;\nexport const ARC_WORKBOOK_RELS = `${PACKAGE_XL}/${PACKAGE_RELS}/workbook.xml.rels`;\nexport const ARC_CORE = `${PACKAGE_PROPS}/core.xml`;\nexport const ARC_APP = `${PACKAGE_PROPS}/app.xml`;\nexport const ARC_CUSTOM = `${PACKAGE_PROPS}/custom.xml`;\nexport const ARC_WORKBOOK = `${PACKAGE_XL}/workbook.xml`;\nexport const ARC_STYLE = `${PACKAGE_XL}/styles.xml`;\nexport const ARC_THEME = `${PACKAGE_THEME}/theme1.xml`;\nexport const ARC_SHARED_STRINGS = `${PACKAGE_XL}/sharedStrings.xml`;\nexport const ARC_CUSTOM_UI = 'customUI/customUI.xml';\n\n// ---- MIME / content-type strings -------------------------------------------\n\nconst WORKBOOK_TPL = 'application/vnd.openxmlformats-officedocument.spreadsheetml.%s.main+xml';\nconst SPREADSHEET_TPL = 'application/vnd.openxmlformats-officedocument.spreadsheetml.%s+xml';\nconst WORKBOOK_MACRO_TPL = 'application/vnd.ms-excel.%s.macroEnabled.main+xml';\nconst fmt = (tpl: string, kind: string): string => tpl.replace('%s', kind);\n\nexport const XLSX_TYPE = fmt(WORKBOOK_TPL, 'sheet');\nexport const XLTX_TYPE = fmt(WORKBOOK_TPL, 'template');\nexport const XLSM_TYPE = fmt(WORKBOOK_MACRO_TPL, 'sheet');\nexport const XLTM_TYPE = fmt(WORKBOOK_MACRO_TPL, 'template');\nexport const SHARED_STRINGS_TYPE = fmt(SPREADSHEET_TPL, 'sharedStrings');\nexport const EXTERNAL_LINK_TYPE = fmt(SPREADSHEET_TPL, 'externalLink');\nexport const WORKSHEET_TYPE = fmt(SPREADSHEET_TPL, 'worksheet');\nexport const COMMENTS_TYPE = fmt(SPREADSHEET_TPL, 'comments');\nexport const STYLES_TYPE = fmt(SPREADSHEET_TPL, 'styles');\nexport const CHARTSHEET_TYPE = fmt(SPREADSHEET_TPL, 'chartsheet');\nexport const DRAWING_TYPE = 'application/vnd.openxmlformats-officedocument.drawing+xml';\nexport const CHART_TYPE = 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml';\nexport const CHARTEX_TYPE = 'application/vnd.ms-office.chartex+xml';\nexport const CHARTSHAPE_TYPE = 'application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml';\nexport const THEME_TYPE = 'application/vnd.openxmlformats-officedocument.theme+xml';\nexport const CPROPS_TYPE = 'application/vnd.openxmlformats-officedocument.custom-properties+xml';\nexport const VBA_TYPE = 'application/vnd.ms-office.vbaProject';\nexport const ACTIVEX_TYPE = 'application/vnd.ms-office.activeX+xml';\nexport const CTRLPROPS_TYPE = 'application/vnd.ms-excel.controlproperties+xml';\n\n// ---- QName helpers ----------------------------------------------------------\n\n/**\n * Build a Clark-notation QName: `{namespace}localname`. When `namespace` is\n * empty / undefined the local name is returned as-is.\n */\nexport function qname(namespace: string | undefined, local: string): string {\n  return namespace ? `{${namespace}}${local}` : local;\n}\n\nconst QNAME_RE = /^\\{([^}]*)\\}(.+)$/;\n\n/**\n * Inverse of {@link qname}. Returns `{ ns, local }`. For unprefixed names `ns`\n * is the empty string.\n */\nexport function parseQName(name: string): { ns: string; local: string } {\n  const m = QNAME_RE.exec(name);\n  if (m === null) return { ns: '', local: name };\n  return { ns: m[1] ?? '', local: m[2] ?? '' };\n}\n","// Lightweight XML tree representation used between the parser, the schema\n// layer, and the serializer.\n//\n// Plain object, no DOM, names in Clark notation `{ns}local` so namespace-aware\n// code does not depend on runtime prefix bookkeeping.\n\nimport { qname } from './namespaces';\n\nexport interface XmlNode {\n  /** Clark-notation qualified name: `{namespace}local` or just `local`. */\n  name: string;\n  /** Attribute table; values are always strings (no value coercion at this layer). */\n  attrs: Record<string, string>;\n  /**\n   * Optional element text. When an element has both text and child elements,\n   * callers should set `text` and rely on `children` for mixed content; the\n   * serializer emits `text` then children.\n   */\n  text?: string;\n  /** Child element nodes in document order. */\n  children: XmlNode[];\n}\n\n/**\n * Build an XmlNode from primitive bits. Attributes / children default to empty;\n * pass `undefined` for `text` to omit the text node.\n *\n * The element's name is always supplied in Clark notation. Use the {@link\n * qname} helper from `./namespaces` to keep call sites readable.\n */\nexport function el(\n  name: string,\n  attrs: Readonly<Record<string, string | number | boolean | null | undefined>> = {},\n  children: ReadonlyArray<XmlNode> = [],\n  text?: string,\n): XmlNode {\n  const out: XmlNode = {\n    name,\n    attrs: normaliseAttrs(attrs),\n    children: children.slice(),\n  };\n  if (text !== undefined) out.text = text;\n  return out;\n}\n\nconst normaliseAttrs = (\n  attrs: Readonly<Record<string, string | number | boolean | null | undefined>>,\n): Record<string, string> => {\n  const out: Record<string, string> = {};\n  for (const [k, v] of Object.entries(attrs)) {\n    if (v === undefined || v === null) continue;\n    out[k] = typeof v === 'string' ? v : String(v);\n  }\n  return out;\n};\n\n/**\n * Convenience: element with a Clark-notation name composed from a namespace URI\n * and local name.\n */\nexport function elNs(\n  namespace: string | undefined,\n  local: string,\n  attrs?: Readonly<Record<string, string | number | boolean | null | undefined>>,\n  children?: ReadonlyArray<XmlNode>,\n  text?: string,\n): XmlNode {\n  return el(qname(namespace, local), attrs, children, text);\n}\n\n/** Locate the first child matching the supplied Clark-notation name. */\nexport function findChild(node: XmlNode, name: string): XmlNode | undefined {\n  for (const c of node.children) if (c.name === name) return c;\n  return undefined;\n}\n\n/** All children matching the supplied Clark-notation name, in document order. */\nexport function findChildren(node: XmlNode, name: string): XmlNode[] {\n  const out: XmlNode[] = [];\n  for (const c of node.children) if (c.name === name) out.push(c);\n  return out;\n}\n\n/**\n * Append `child` to `parent`. Mutates and returns `parent` for chaining during\n * construction. Avoid in hot paths — for cell writing the worksheet writer goes\n * through a templated emitter rather than building XmlNode trees per cell.\n */\nexport function appendChild(parent: XmlNode, child: XmlNode): XmlNode {\n  parent.children.push(child);\n  return parent;\n}\n"],"mappings":";AASA,MAAa,SAAS;AACtB,MAAa,SAAS;AAEtB,MAAa,WAAW;AACxB,MAAa,aAAa;AAC1B,MAAa,cAAc;AAC3B,MAAa,iBAAiB;AAI9B,MAAM,SAAS;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