{"version":3,"file":"xlsx.cjs","names":["crcTable","crc32","bytes","Uint32Array","i","c","k","crc","byte","u16","value","u32","utf8","text","TextEncoder","encode","buildZip","entries","DOS_TIME","DOS_DATE","local","central","localSize","centralSize","entry","nameBytes","name","data","size","length","localOffset","localHeader","Uint8Array","from","push","record","eocd","concat","chunks","total","reduce","sum","chunk","out","at","set","buildExportTable","buildZip","utf8","xml","text","replaceAll","columnLetter","index","n","out","String","fromCodePoint","Math","floor","safeText","ch","STYLE","default","bold","date","datetime","EXCEL_EPOCH_MS","Date","UTC","isDateOnly","getUTCHours","getUTCMinutes","getUTCSeconds","getUTCMilliseconds","getHours","getMinutes","getSeconds","getMilliseconds","excelSerial","local","getFullYear","getMonth","getDate","getTime","styleAttr","style","cellXml","ref","value","Number","isNaN","dateStyle","isFinite","colsXml","table","cols","headers","map","header","stated","widths","width","min","max","length","join","rowOpen","level","sheetXml","lines","i","push","maxLevel","rows","forEach","row","r","meta","rowMeta","role","cells","c","stylesXml","documents","sheetName","contentTypes","rootRels","workbook","safeSheetName","workbookRels","name","data","cleaned","trim","slice","buildTableXlsx","options","xlsxBytes","columns","view","summary","XLSX_MIME","xlsxWriter","extension","build","parts","mimeType"],"sources":["../src/export/zip.ts","../src/export/xlsx.ts"],"sourcesContent":["/**\n * A minimal ZIP writer, because an `.xlsx` is a ZIP and nothing else here is.\n *\n * Entries are **stored**, not deflated. ZIP has supported method 0 since 1989\n * and every reader — Excel, Numbers, LibreOffice, Google Sheets — accepts it,\n * which means a spreadsheet export needs no compression library and therefore\n * no dependency. The file is larger than a deflated one; that is the whole\n * trade, and for anything big enough to care there is the backend export seam.\n *\n * Written against the APPNOTE structure directly: a local header per entry, a\n * central directory listing them, and an end-of-central-directory record. The\n * numbers are little-endian and the offsets have to be exact, which is why this\n * is tested on the bytes rather than on \"the file opened\".\n */\n\n/** One file inside the archive. */\nexport interface ZipEntry {\n  /** Path within the archive, forward slashes, no leading slash. */\n  name: string;\n  /** File contents. */\n  data: Uint8Array;\n}\n\n/**\n * CRC-32, the checksum ZIP stores per entry.\n *\n * The table is built once on first use rather than shipped as 256 literals —\n * it costs microseconds and keeps the bundle honest.\n */\nlet crcTable: Uint32Array | undefined;\n\nfunction crc32(bytes: Uint8Array): number {\n  if (!crcTable) {\n    crcTable = new Uint32Array(256);\n    for (let i = 0; i < 256; i++) {\n      let c = i;\n      for (let k = 0; k < 8; k++) {\n        c = (c & 1) === 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;\n      }\n      crcTable[i] = c >>> 0;\n    }\n  }\n  let crc = 0xffffffff;\n  for (const byte of bytes) {\n    crc = (crcTable[(crc ^ byte) & 0xff] ?? 0) ^ (crc >>> 8);\n  }\n  return (crc ^ 0xffffffff) >>> 0;\n}\n\n/** Little-endian writers — ZIP is little-endian throughout. */\nfunction u16(value: number): number[] {\n  return [value & 0xff, (value >>> 8) & 0xff];\n}\n\nfunction u32(value: number): number[] {\n  return [\n    value & 0xff,\n    (value >>> 8) & 0xff,\n    (value >>> 16) & 0xff,\n    (value >>> 24) & 0xff,\n  ];\n}\n\n/** UTF-8 bytes for a name or a document. */\nexport function utf8(text: string): Uint8Array<ArrayBuffer> {\n  return new TextEncoder().encode(text);\n}\n\n/**\n * Build a ZIP archive from entries.\n *\n * The DOS timestamp is fixed rather than taken from the clock: exporting the\n * same table twice should produce the same bytes, which makes the output\n * diffable and the tests deterministic. Readers show the epoch date and no\n * spreadsheet cares.\n *\n * @param entries - Files to include, in the order they should appear.\n * @returns The archive bytes.\n */\nexport function buildZip(\n  entries: readonly ZipEntry[]\n): Uint8Array<ArrayBuffer> {\n  const DOS_TIME = 0;\n  const DOS_DATE = 0x21; // 1980-01-01, the earliest a DOS date can express.\n  // Chunks, never one growing array of bytes. A file's contents are appended by\n  // reference and copied once at the end: spreading them into `push` would pass\n  // one argument per byte, which throws a RangeError somewhere past a hundred\n  // thousand of them — an export that works until the day the table is big.\n  const local: Uint8Array[] = [];\n  const central: Uint8Array[] = [];\n  let localSize = 0;\n  let centralSize = 0;\n\n  for (const entry of entries) {\n    const nameBytes = utf8(entry.name);\n    const crc = crc32(entry.data);\n    const size = entry.data.length;\n    // Where this entry's local header begins — the central directory has to\n    // publish it, and a reader jumps straight here to find the bytes.\n    const localOffset = localSize;\n\n    const localHeader = Uint8Array.from([\n      ...u32(0x04034b50),\n      ...u16(20), // version needed: 2.0\n      ...u16(0x0800), // UTF-8 names\n      ...u16(0), // method 0 — stored\n      ...u16(DOS_TIME),\n      ...u16(DOS_DATE),\n      ...u32(crc),\n      ...u32(size),\n      ...u32(size),\n      ...u16(nameBytes.length),\n      ...u16(0), // no extra field\n    ]);\n    local.push(localHeader, nameBytes, entry.data);\n    localSize += localHeader.length + nameBytes.length + size;\n\n    // Matching central-directory record.\n    const record = Uint8Array.from([\n      ...u32(0x02014b50),\n      ...u16(20), // version made by\n      ...u16(20), // version needed\n      ...u16(0x0800),\n      ...u16(0),\n      ...u16(DOS_TIME),\n      ...u16(DOS_DATE),\n      ...u32(crc),\n      ...u32(size),\n      ...u32(size),\n      ...u16(nameBytes.length),\n      ...u16(0), // extra\n      ...u16(0), // comment\n      ...u16(0), // disk number\n      ...u16(0), // internal attrs\n      ...u32(0), // external attrs\n      ...u32(localOffset),\n    ]);\n    central.push(record, nameBytes);\n    centralSize += record.length + nameBytes.length;\n  }\n\n  const eocd = Uint8Array.from([\n    ...u32(0x06054b50),\n    ...u16(0), // this disk\n    ...u16(0), // disk with central directory\n    ...u16(entries.length),\n    ...u16(entries.length),\n    ...u32(centralSize),\n    ...u32(localSize),\n    ...u16(0), // comment length\n  ]);\n\n  return concat([...local, ...central, eocd]);\n}\n\n/** Join chunks into one buffer — a single allocation and one copy each. */\nfunction concat(chunks: readonly Uint8Array[]): Uint8Array<ArrayBuffer> {\n  const total = chunks.reduce((sum, chunk) => sum + chunk.length, 0);\n  const out = new Uint8Array(total);\n  let at = 0;\n  for (const chunk of chunks) {\n    out.set(chunk, at);\n    at += chunk.length;\n  }\n  return out;\n}\n","/**\n * A spreadsheet file, written by hand.\n *\n * `.xlsx` is a ZIP of XML documents, which is the only reason writing one\n * without a dependency is reasonable. What it needs is small: a content-type\n * map, two relationship files, a workbook naming one sheet, and the sheet\n * itself. Everything else in the format is optional.\n *\n * Values are written as **inline strings** or numbers rather than through a\n * shared-strings table. Shared strings save space when text repeats and cost a\n * second document plus an index to maintain; for a table export the saving is\n * small and the failure mode — an index that disagrees with the sheet — produces\n * a file Excel refuses to open. Inline is simpler and cannot desynchronise.\n *\n * Numbers stay numbers so a spreadsheet can sum them, which is the entire point\n * of exporting to a spreadsheet rather than a CSV.\n */\nimport type { ColumnDef } from \"../types\";\nimport {\n  buildExportTable,\n  type ExportTable,\n  type ExportViewEntry,\n  type ExportWriter,\n} from \"./exportWriter\";\nimport { buildZip, utf8, type ZipEntry } from \"./zip\";\n\n/** Escape the five characters XML cannot carry literally. */\nfunction xml(text: string): string {\n  return text\n    .replaceAll(\"&\", \"&amp;\")\n    .replaceAll(\"<\", \"&lt;\")\n    .replaceAll(\">\", \"&gt;\")\n    .replaceAll('\"', \"&quot;\")\n    .replaceAll(\"'\", \"&apos;\");\n}\n\n/**\n * A column's spreadsheet letter: 0 → A, 25 → Z, 26 → AA.\n *\n * Base-26 with no zero digit, so the usual `% 26` loop is off by one without\n * the decrement — the bug that puts column 26 at \"BA\".\n */\nexport function columnLetter(index: number): string {\n  let n = index;\n  let out = \"\";\n  do {\n    out = String.fromCodePoint(65 + (n % 26)) + out;\n    n = Math.floor(n / 26) - 1;\n  } while (n >= 0);\n  return out;\n}\n\n/**\n * Strip what XML 1.0 cannot carry: control characters other than tab, newline\n * and carriage return. One such byte from a database makes the whole workbook\n * unopenable, and the user has no way to tell which cell did it.\n *\n * Written as a scan rather than a regex because the regex form needs a lint\n * suppression, and a rule worth silencing here is a rule worth not tripping.\n */\nfunction safeText(text: string): string {\n  let out = \"\";\n  for (const ch of text) {\n    // A character compares below a space exactly when its code point does,\n    // which is the whole test — and needs no code-point lookup to make it.\n    if (ch >= \" \" || ch === \"\\t\" || ch === \"\\n\" || ch === \"\\r\") out += ch;\n  }\n  return out;\n}\n\n/** Style index in `styles.xml`: default, header/total bold, date, datetime. */\nconst STYLE = {\n  default: 0,\n  bold: 1,\n  date: 2,\n  datetime: 3,\n} as const;\n\n/** Excel's day-zero, including the 1900 leap-year bug it still ships. */\nconst EXCEL_EPOCH_MS = Date.UTC(1899, 11, 30);\n\n/** A date with no clock is a day; anything else is a day-and-time. */\nfunction isDateOnly(date: Date): boolean {\n  return (\n    (date.getUTCHours() === 0 &&\n      date.getUTCMinutes() === 0 &&\n      date.getUTCSeconds() === 0 &&\n      date.getUTCMilliseconds() === 0) ||\n    (date.getHours() === 0 &&\n      date.getMinutes() === 0 &&\n      date.getSeconds() === 0 &&\n      date.getMilliseconds() === 0)\n  );\n}\n\n/** Excel serial: days (and a fraction) since 1899-12-30. */\nfunction excelSerial(date: Date): number {\n  if (isDateOnly(date) && date.getHours() === 0 && date.getUTCHours() !== 0) {\n    const local = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());\n    return (local - EXCEL_EPOCH_MS) / 86_400_000;\n  }\n  return (date.getTime() - EXCEL_EPOCH_MS) / 86_400_000;\n}\n\nfunction styleAttr(style: number): string {\n  return style === STYLE.default ? \"\" : ` s=\"${String(style)}\"`;\n}\n\n/**\n * One `<c>` element, typed by what the value actually is.\n *\n * The type comes from the value, never from parsing its text. A postal code of\n * `\"01730\"` and a phone number of `\"0123\"` are strings, and a writer that\n * sniffed digits would hand back `1730` and `123` — the classic spreadsheet\n * export bug, and unfixable by the user once the file exists.\n *\n * Strings need no formula guard here: XLSX keeps formulas in an `<f>` element,\n * so text beginning with `=` is text. That is why `escapeFormulas` is a CSV\n * concern and this format ignores it.\n *\n * Dates stay dates: a `Date` becomes an Excel serial with a date or\n * datetime number format, so a spreadsheet can sort and filter the column\n * instead of reading a string that looks like one.\n */\nfunction cellXml(\n  ref: string,\n  value: unknown,\n  style: number = STYLE.default\n): string {\n  if (value instanceof Date && !Number.isNaN(value.getTime())) {\n    const dateStyle = isDateOnly(value) ? STYLE.date : STYLE.datetime;\n    return `<c r=\"${ref}\"${styleAttr(dateStyle)}><v>${excelSerial(value)}</v></c>`;\n  }\n  if (typeof value === \"number\" && Number.isFinite(value)) {\n    return `<c r=\"${ref}\"${styleAttr(style)}><v>${value}</v></c>`;\n  }\n  if (typeof value === \"boolean\") {\n    return `<c r=\"${ref}\"${styleAttr(style)} t=\"b\"><v>${value ? 1 : 0}</v></c>`;\n  }\n  const text = typeof value === \"string\" ? value : \"\";\n  if (text === \"\") return `<c r=\"${ref}\"${styleAttr(style)}/>`;\n  return `<c r=\"${ref}\"${styleAttr(style)} t=\"inlineStr\"><is><t xml:space=\"preserve\">${xml(\n    safeText(text)\n  )}</t></is></c>`;\n}\n\nfunction colsXml(table: ExportTable): string {\n  const cols = table.headers.map((header, index) => {\n    const stated = table.widths?.[index];\n    const width = stated ?? Math.min(40, Math.max(8, header.length + 2));\n    return `<col min=\"${String(index + 1)}\" max=\"${String(index + 1)}\" width=\"${String(width)}\" customWidth=\"1\"/>`;\n  });\n  return cols.length > 0 ? `<cols>${cols.join(\"\")}</cols>` : \"\";\n}\n\nfunction rowOpen(index: number, level: number): string {\n  return level > 0\n    ? `<row r=\"${String(index)}\" outlineLevel=\"${String(level)}\">`\n    : `<row r=\"${String(index)}\">`;\n}\n\n/** The sheet document: a header row of column names, then the data. */\nfunction sheetXml(table: ExportTable): string {\n  const lines: string[] = [];\n  const header = table.headers\n    .map((text, i) => cellXml(`${columnLetter(i)}1`, text, STYLE.bold))\n    .join(\"\");\n  lines.push(`${rowOpen(1, 0)}${header}</row>`);\n\n  let maxLevel = 0;\n  table.rows.forEach((row, r) => {\n    const meta = table.rowMeta?.[r];\n    const level = meta?.level ?? 0;\n    if (level > maxLevel) maxLevel = level;\n    const style =\n      meta?.role === \"group\" || meta?.role === \"aggregate\"\n        ? STYLE.bold\n        : STYLE.default;\n    const cells = row\n      .map((value, c) => cellXml(`${columnLetter(c)}${r + 2}`, value, style))\n      .join(\"\");\n    lines.push(`${rowOpen(r + 2, level)}${cells}</row>`);\n  });\n\n  return (\n    '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>' +\n    '<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">' +\n    '<sheetPr><outlinePr summaryBelow=\"0\"/></sheetPr>' +\n    `<sheetFormatPr defaultRowHeight=\"15\" outlineLevelRow=\"${String(maxLevel)}\"/>` +\n    '<sheetViews><sheetView workbookViewId=\"0\">' +\n    '<pane ySplit=\"1\" topLeftCell=\"A2\" activePane=\"bottomLeft\" state=\"frozen\"/>' +\n    \"</sheetView></sheetViews>\" +\n    colsXml(table) +\n    `<sheetData>${lines.join(\"\")}</sheetData>` +\n    \"</worksheet>\"\n  );\n}\n\n/** Fonts, date formats, and the four cell styles the sheet refers to. */\nfunction stylesXml(): string {\n  return (\n    '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>' +\n    '<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">' +\n    '<numFmts count=\"2\">' +\n    '<numFmt numFmtId=\"164\" formatCode=\"yyyy-mm-dd\"/>' +\n    '<numFmt numFmtId=\"165\" formatCode=\"yyyy-mm-dd hh:mm\"/>' +\n    \"</numFmts>\" +\n    '<fonts count=\"2\">' +\n    '<font><sz val=\"11\"/><name val=\"Calibri\"/></font>' +\n    '<font><b/><sz val=\"11\"/><name val=\"Calibri\"/></font>' +\n    \"</fonts>\" +\n    '<fills count=\"3\">' +\n    '<fill><patternFill patternType=\"none\"/></fill>' +\n    '<fill><patternFill patternType=\"gray125\"/></fill>' +\n    '<fill><patternFill patternType=\"solid\"><fgColor rgb=\"FFD6DCE4\"/><bgColor indexed=\"64\"/></patternFill></fill>' +\n    \"</fills>\" +\n    '<borders count=\"1\"><border/></borders>' +\n    '<cellStyleXfs count=\"1\">' +\n    '<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\"/>' +\n    \"</cellStyleXfs>\" +\n    '<cellXfs count=\"4\">' +\n    '<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/>' +\n    '<xf numFmtId=\"0\" fontId=\"1\" fillId=\"2\" borderId=\"0\" xfId=\"0\" applyFont=\"1\" applyFill=\"1\"/>' +\n    '<xf numFmtId=\"164\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyNumberFormat=\"1\"/>' +\n    '<xf numFmtId=\"165\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyNumberFormat=\"1\"/>' +\n    \"</cellXfs>\" +\n    \"</styleSheet>\"\n  );\n}\n\n/** The fixed documents every workbook needs, plus the sheet and its styles. */\nfunction documents(table: ExportTable, sheetName: string): ZipEntry[] {\n  const contentTypes =\n    '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>' +\n    '<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">' +\n    '<Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\"/>' +\n    '<Default Extension=\"xml\" ContentType=\"application/xml\"/>' +\n    '<Override PartName=\"/xl/workbook.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml\"/>' +\n    '<Override PartName=\"/xl/styles.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml\"/>' +\n    '<Override PartName=\"/xl/worksheets/sheet1.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml\"/>' +\n    \"</Types>\";\n\n  const rootRels =\n    '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>' +\n    '<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">' +\n    '<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\" Target=\"xl/workbook.xml\"/>' +\n    \"</Relationships>\";\n\n  const workbook =\n    '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>' +\n    '<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" ' +\n    'xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">' +\n    `<sheets><sheet name=\"${xml(safeSheetName(sheetName))}\" sheetId=\"1\" r:id=\"rId1\"/></sheets>` +\n    \"</workbook>\";\n\n  const workbookRels =\n    '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>' +\n    '<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">' +\n    '<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\" Target=\"worksheets/sheet1.xml\"/>' +\n    '<Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\" Target=\"styles.xml\"/>' +\n    \"</Relationships>\";\n\n  return [\n    { name: \"[Content_Types].xml\", data: utf8(contentTypes) },\n    { name: \"_rels/.rels\", data: utf8(rootRels) },\n    { name: \"xl/workbook.xml\", data: utf8(workbook) },\n    { name: \"xl/_rels/workbook.xml.rels\", data: utf8(workbookRels) },\n    { name: \"xl/styles.xml\", data: utf8(stylesXml()) },\n    { name: \"xl/worksheets/sheet1.xml\", data: utf8(sheetXml(table)) },\n  ];\n}\n\n/**\n * Excel's own rules for a sheet name: at most 31 characters and none of\n * `: \\ / ? * [ ]`. A name that breaks them makes the whole file unopenable, so\n * it is corrected rather than passed through.\n */\nexport function safeSheetName(name: string): string {\n  const cleaned = name.replaceAll(/[:\\\\/?*[\\]]/g, \" \").trim();\n  return (cleaned === \"\" ? \"Sheet1\" : cleaned).slice(0, 31);\n}\n\n/**\n * Build an `.xlsx` for the given rows and columns.\n *\n * Cell values resolve exactly as they do for CSV — a column's `exportValue`\n * first, then its accessor or `sortValue` — so the same table produces the same\n * data in either format. What differs is that numbers, booleans and dates stay\n * typed, because a spreadsheet that cannot sum a column is a screenshot.\n *\n * @typeParam TRow - The row type.\n * @param options - Rows, columns, and the sheet's name.\n * @returns The workbook bytes, ready to download.\n */\nexport function buildTableXlsx<TRow>(options: {\n  rows: readonly TRow[];\n  columns: readonly ColumnDef<TRow>[];\n  sheetName?: string;\n  view?: readonly ExportViewEntry<TRow>[];\n  summary?: Readonly<Partial<Record<string, unknown>>>;\n}): Uint8Array<ArrayBuffer> {\n  return xlsxBytes(\n    buildExportTable(options.rows, options.columns, {\n      view: options.view,\n      summary: options.summary,\n    }),\n    options.sheetName\n  );\n}\n\n/** The workbook for an already-resolved table — what the writer calls. */\nfunction xlsxBytes(\n  table: ExportTable,\n  sheetName?: string\n): Uint8Array<ArrayBuffer> {\n  return buildZip(documents(table, sheetName ?? \"Sheet1\"));\n}\n\n/** The MIME type Excel, Numbers and Google Sheets all register for `.xlsx`. */\nconst XLSX_MIME =\n  \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\";\n\n/**\n * The spreadsheet writer, for the `exportCsv` prop's `writer` option:\n *\n * ```tsx\n * import { xlsxWriter } from \"@adapttable/core/xlsx\";\n *\n * <DataTable exportCsv={{ writer: xlsxWriter(), scope: \"selected\" }} … />\n * ```\n *\n * Every scope works unchanged — page, all, selected, range, and any column\n * subset — because the scope is resolved before a writer is asked for anything.\n *\n * @param options - The sheet's name inside the workbook. Defaults to `\"Sheet1\"`.\n * @returns A writer to hand to `exportCsv`.\n */\nexport function xlsxWriter(options?: { sheetName?: string }): ExportWriter {\n  return {\n    extension: \"xlsx\",\n    build: ({ table }) => ({\n      parts: [xlsxBytes(table, options?.sheetName)],\n      mimeType: XLSX_MIME,\n      // Binary: the bytes are the file, and there is no text form of them.\n      text: \"\",\n    }),\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAIA;AAEJ,SAASC,MAAMC,OAA2B;CACxC,IAAI,CAACF,UAAU;EACbA,WAAW,IAAIG,YAAY,GAAG;EAC9B,KAAK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