{"version":3,"names":["Attr","None","Bold","Dim","Italic","Underline","Inverse","Strikethrough","NO_COLOR","SHARED_BLANK","Object","freeze","char","fg","bg","attrs","link","width","charWidthCache","Map","charWidth","code","codePointAt","w","get","undefined","Bun","stringWidth","set","createCell","cellsEqual","a","b","FrameBuffer","dirtyRows","Set","constructor","cols","rows","n","cells","Array","scratch","i","clear","writeCell","idx","cell","length","clearDirtyRows","row","start","end","contentHeight","col","getMutable","add","writeString","str","clip","clipRight","right","clipBottom","bottom","clipLeft","left","clipTop","top","rowStart","wrote","c","fillRect","height","rMin","Math","max","rMax","min","cMin","cMax","r","diffFrames","prev","curr","changes","has","runStart","prevCell","currCell","push","startCol","sgrReset","buildSGRDelta","from","toFg","toBg","toAttrs","parts","attrsRemoved","attrsAdded","boldDimHandled","g","join","serializeChanges","initialState","enableLinks","state","currentLink","run","sgr","wrapSynchronized","data","color","input"],"sources":["frame-buffer.ts"],"sourcesContent":["/**\n * Frame buffer: a 2D grid of terminal cells with differential rendering.\n *\n * Two buffers (current + previous) are maintained. After rendering nodes\n * into the current buffer, diffFrames() produces the minimal set of\n * changed runs. The ANSI serializer converts those runs into escape\n * sequences, tracking SGR state to minimize output bytes.\n */\n\n// --- Cell representation ---\n\n// Attribute bitfield\nexport const Attr = {\n\tNone: 0,\n\tBold: 1,\n\tDim: 2,\n\tItalic: 4,\n\tUnderline: 8,\n\tInverse: 16,\n\tStrikethrough: 32,\n} as const;\nexport type Attr = number;\n\n// Default/no color sentinel — means \"use terminal default\"\nexport const NO_COLOR = -1;\n\nexport interface Cell {\n\t/** Attribute bitfield (bold, italic, etc.) */\n\tattrs: Attr;\n\t/** Background color: 24-bit RGB packed as number, or NO_COLOR */\n\tbg: number;\n\t/** Single character or grapheme cluster */\n\tchar: string;\n\t/** Foreground color: 24-bit RGB packed as number, or NO_COLOR */\n\tfg: number;\n\t/** OSC 8 hyperlink URL, or empty string for no link */\n\tlink: string;\n\t/** Display width: 1 normal, 2 wide (CJK/emoji), 0 continuation cell */\n\twidth: number;\n}\n\n// Canonical blank cell. Every cleared slot in every buffer points at this one\n// frozen object, so two blank slots — even across the prev/next buffers — are\n// pointer-equal, which `cellsEqual` short-circuits on. It is frozen because it\n// must never be mutated, and nothing ever mutates it: in-place writers either\n// materialize a blank into its own scratch first (getMutable) or skip blanks\n// outright (applyColorField, via `char === \" \"`), and every slot the buffer\n// means to write gets a scratch cell, never this one.\nconst SHARED_BLANK: Cell = Object.freeze({\n\tchar: \" \",\n\tfg: NO_COLOR,\n\tbg: NO_COLOR,\n\tattrs: Attr.None,\n\tlink: \"\",\n\twidth: 1,\n});\n\n// Per-glyph width memo. Bun.stringWidth is a native call; a terminal frame is\n// dominated by a tiny set of repeated glyphs (ASCII, box-drawing borders, block\n// elements, braille spinners), so caching width by code point collapses\n// hundreds of native calls per frame into a handful of Map lookups. Bounded by\n// the number of distinct glyphs an app ever paints (small). ASCII is handled\n// inline without touching the map.\nconst charWidthCache = new Map<number, number>();\n\n/** Display width of a single code-point string, memoized. */\nexport function charWidth(char: string): number {\n\tconst code = char.codePointAt(0) ?? 0;\n\tif (code >= 0x20 && code < 0x7f) return 1; // printable ASCII — always 1\n\tlet w = charWidthCache.get(code);\n\tif (w === undefined) {\n\t\tw = Bun.stringWidth(char);\n\t\tcharWidthCache.set(code, w);\n\t}\n\treturn w;\n}\n\nexport function createCell(\n\tchar = \" \",\n\tfg = NO_COLOR,\n\tbg = NO_COLOR,\n\tattrs: Attr = Attr.None,\n\twidth = 1,\n\tlink = \"\",\n): Cell {\n\treturn { char, fg, bg, attrs, link, width };\n}\n\nfunction cellsEqual(a: Cell, b: Cell): boolean {\n\t// Identity short-circuit: cleared cells in both buffers share the single\n\t// SHARED_BLANK reference, so blank↔blank regions (the common case in a sparse\n\t// diff) compare in one pointer check instead of six field comparisons.\n\tif (a === b) return true;\n\treturn (\n\t\ta.char === b.char &&\n\t\ta.fg === b.fg &&\n\t\ta.bg === b.bg &&\n\t\ta.attrs === b.attrs &&\n\t\ta.link === b.link &&\n\t\ta.width === b.width\n\t);\n}\n\n// --- Clip region ---\n\n/** Rectangular clip region (exclusive right/bottom). */\nexport interface ClipRect {\n\tbottom: number;\n\tleft: number;\n\tright: number;\n\ttop: number;\n}\n\n// --- Frame buffer ---\n\nexport class FrameBuffer {\n\treadonly cols: number;\n\treadonly rows: number;\n\t/** The visible grid: each slot points at either SHARED_BLANK or its scratch. */\n\treadonly cells: Cell[];\n\t/**\n\t * One persistent, mutable Cell per slot, allocated once. Writing a slot\n\t * mutates its scratch cell in place and points `cells[i]` at it — so a frame\n\t * allocates zero new cells no matter how much it paints. Blank slots point at\n\t * the shared frozen blank instead, keeping the diff's identity fast path.\n\t */\n\tprivate readonly scratch: Cell[];\n\t/** Rows touched by set()/writeString()/fillRect() since last clear(). */\n\treadonly dirtyRows: Set<number> = new Set();\n\n\tconstructor(cols: number, rows: number) {\n\t\tthis.cols = cols;\n\t\tthis.rows = rows;\n\t\tconst n = cols * rows;\n\t\tthis.cells = new Array<Cell>(n);\n\t\tthis.scratch = new Array<Cell>(n);\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tthis.cells[i] = SHARED_BLANK;\n\t\t\tthis.scratch[i] = createCell();\n\t\t}\n\t\tthis.dirtyRows.clear();\n\t}\n\n\t/** Mutate the scratch cell for a slot in place and make it the visible cell. */\n\tprivate writeCell(\n\t\tidx: number,\n\t\tchar: string,\n\t\tfg: number,\n\t\tbg: number,\n\t\tattrs: Attr,\n\t\twidth: number,\n\t\tlink: string,\n\t) {\n\t\tconst cell = this.scratch[idx] as Cell;\n\t\tcell.char = char;\n\t\tcell.fg = fg;\n\t\tcell.bg = bg;\n\t\tcell.attrs = attrs;\n\t\tcell.width = width;\n\t\tcell.link = link;\n\t\tthis.cells[idx] = cell;\n\t}\n\n\tclear() {\n\t\tfor (let i = 0; i < this.cells.length; i++) {\n\t\t\tthis.cells[i] = SHARED_BLANK;\n\t\t}\n\t\tthis.dirtyRows.clear();\n\t}\n\n\t/** Reset only rows that were previously painted, then clear the dirty set. */\n\tclearDirtyRows() {\n\t\tfor (const row of this.dirtyRows) {\n\t\t\tconst start = row * this.cols;\n\t\t\tconst end = start + this.cols;\n\t\t\tfor (let i = start; i < end; i++) {\n\t\t\t\tthis.cells[i] = SHARED_BLANK;\n\t\t\t}\n\t\t}\n\t\tthis.dirtyRows.clear();\n\t}\n\n\t/** Find the last row that has non-empty content. Returns 0 if all empty. */\n\tcontentHeight(): number {\n\t\tfor (let row = this.rows - 1; row >= 0; row--) {\n\t\t\tfor (let col = 0; col < this.cols; col++) {\n\t\t\t\tconst cell = this.cells[row * this.cols + col] as Cell;\n\t\t\t\tif (\n\t\t\t\t\tcell.char !== \" \" ||\n\t\t\t\t\tcell.fg !== NO_COLOR ||\n\t\t\t\t\tcell.bg !== NO_COLOR ||\n\t\t\t\t\tcell.attrs !== Attr.None\n\t\t\t\t) {\n\t\t\t\t\treturn row + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\n\tget(col: number, row: number): Cell {\n\t\treturn this.cells[row * this.cols + col] as Cell;\n\t}\n\n\t/**\n\t * Return a writable cell for a slot, for callers that mutate it in place\n\t * (e.g. the selection-inverse overlay). A blank slot is first materialized\n\t * into its own scratch cell — never hand out the frozen shared blank — and\n\t * the row is marked dirty. Callers must pass in-bounds coordinates.\n\t */\n\tgetMutable(col: number, row: number): Cell {\n\t\tconst idx = row * this.cols + col;\n\t\tif ((this.cells[idx] as Cell) === SHARED_BLANK) {\n\t\t\tthis.writeCell(idx, \" \", NO_COLOR, NO_COLOR, Attr.None, 1, \"\");\n\t\t\tthis.dirtyRows.add(row);\n\t\t}\n\t\treturn this.cells[idx] as Cell;\n\t}\n\n\tset(col: number, row: number, cell: Cell) {\n\t\tif (col < 0 || col >= this.cols || row < 0 || row >= this.rows) return;\n\t\t// Copy the source cell's fields into this slot's scratch rather than\n\t\t// aliasing the reference — callers (e.g. cross-buffer scroll copies) may\n\t\t// hand us a cell owned by another buffer, and the two pools must stay\n\t\t// independent. A blank source is forwarded as the shared blank.\n\t\tconst idx = row * this.cols + col;\n\t\tif (cell === SHARED_BLANK) {\n\t\t\tthis.cells[idx] = SHARED_BLANK;\n\t\t} else {\n\t\t\tthis.writeCell(\n\t\t\t\tidx,\n\t\t\t\tcell.char,\n\t\t\t\tcell.fg,\n\t\t\t\tcell.bg,\n\t\t\t\tcell.attrs,\n\t\t\t\tcell.width,\n\t\t\t\tcell.link,\n\t\t\t);\n\t\t}\n\t\tthis.dirtyRows.add(row);\n\t}\n\n\t/** Write a string at (col, row) with given attributes. Returns columns consumed. */\n\twriteString(\n\t\tcol: number,\n\t\trow: number,\n\t\tstr: string,\n\t\tfg = NO_COLOR,\n\t\tbg = NO_COLOR,\n\t\tattrs: Attr = Attr.None,\n\t\tclip?: ClipRect,\n\t\tlink = \"\",\n\t): number {\n\t\tconst clipRight = clip ? clip.right : this.cols;\n\t\tconst clipBottom = clip ? clip.bottom : this.rows;\n\t\tconst clipLeft = clip ? clip.left : 0;\n\t\tconst clipTop = clip ? clip.top : 0;\n\n\t\tif (row < clipTop || row >= clipBottom) return 0;\n\n\t\t// writeString only ever touches this one row, so compute its base offset\n\t\t// once and mark it dirty a single time after the loop (if anything landed).\n\t\tconst rowStart = row * this.cols;\n\t\tlet wrote = false;\n\t\tlet c = col;\n\t\tfor (const char of str) {\n\t\t\tif (c >= clipRight) break;\n\t\t\t// Memoized per-glyph width — Bun.stringWidth is a native call and the\n\t\t\t// single hottest cost in paint. charWidth() fast-paths ASCII and\n\t\t\t// caches everything else (borders, blocks, CJK, emoji) by code point.\n\t\t\tconst w = charWidth(char);\n\t\t\tif (w === 0) continue;\n\n\t\t\t// Skip cells left of clip, but still advance column\n\t\t\tif (c + w <= clipLeft) {\n\t\t\t\tc += w;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Skip wide chars that straddle the right clip edge\n\t\t\tif (w === 2 && c + 1 >= clipRight) {\n\t\t\t\tc += w;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// c < clipRight ≤ cols holds from the loop guard; c may still be < 0\n\t\t\t// when a wide glyph straddles the left edge, so guard the low bound.\n\t\t\tif (c >= 0) {\n\t\t\t\tthis.writeCell(rowStart + c, char, fg, bg, attrs, w, link);\n\t\t\t\twrote = true;\n\t\t\t}\n\t\t\tif (w === 2 && c + 1 >= 0 && c + 1 < this.cols) {\n\t\t\t\tthis.writeCell(rowStart + c + 1, \"\", fg, bg, attrs, 0, link);\n\t\t\t\twrote = true;\n\t\t\t}\n\t\t\tc += w;\n\t\t}\n\t\tif (wrote) this.dirtyRows.add(row);\n\t\treturn c - col;\n\t}\n\n\t/** Fill a rectangular region with a cell value. */\n\tfillRect(\n\t\tcol: number,\n\t\trow: number,\n\t\twidth: number,\n\t\theight: number,\n\t\tchar = \" \",\n\t\tfg = NO_COLOR,\n\t\tbg = NO_COLOR,\n\t\tattrs: Attr = Attr.None,\n\t\tclip?: ClipRect,\n\t) {\n\t\tconst rMin = Math.max(row, clip ? clip.top : 0);\n\t\tconst rMax = Math.min(row + height, clip ? clip.bottom : this.rows);\n\t\tconst cMin = Math.max(col, clip ? clip.left : 0);\n\t\tconst cMax = Math.min(col + width, clip ? clip.right : this.cols);\n\n\t\t// rMin/rMax/cMin/cMax are already clamped to valid bounds above. The column\n\t\t// span is the same for every row, so test it once rather than per row.\n\t\tif (cMax <= cMin) return;\n\t\tfor (let r = rMin; r < rMax; r++) {\n\t\t\tconst rowStart = r * this.cols;\n\t\t\tfor (let c = cMin; c < cMax; c++) {\n\t\t\t\tthis.writeCell(rowStart + c, char, fg, bg, attrs, 1, \"\");\n\t\t\t}\n\t\t\tthis.dirtyRows.add(r);\n\t\t}\n\t}\n}\n\n// --- Diff engine ---\n\nexport interface ChangedRun {\n\t/** Reference to the source cell array (no copy). */\n\tcells: Cell[];\n\t/** End index (exclusive) into cells. */\n\tend: number;\n\trow: number;\n\t/** Start index into cells. */\n\tstart: number;\n\tstartCol: number;\n}\n\n/**\n * Compare two frame buffers and produce the minimal set of changed runs.\n * Optionally restrict to a set of dirty rows for faster diffing.\n */\nexport function diffFrames(\n\tprev: FrameBuffer,\n\tcurr: FrameBuffer,\n\tdirtyRows?: Set<number>,\n): ChangedRun[] {\n\tconst changes: ChangedRun[] = [];\n\tconst { cols, rows, cells } = curr;\n\n\tfor (let row = 0; row < rows; row++) {\n\t\tif (dirtyRows && !dirtyRows.has(row)) continue;\n\n\t\tconst rowStart = row * cols;\n\t\tlet runStart = -1;\n\n\t\tfor (let col = 0; col < cols; col++) {\n\t\t\tconst idx = rowStart + col;\n\t\t\tconst prevCell = prev.cells[idx] as Cell;\n\t\t\tconst currCell = cells[idx] as Cell;\n\n\t\t\tif (cellsEqual(prevCell, currCell)) {\n\t\t\t\tif (runStart >= 0) {\n\t\t\t\t\tchanges.push({\n\t\t\t\t\t\trow,\n\t\t\t\t\t\tstartCol: runStart,\n\t\t\t\t\t\tcells,\n\t\t\t\t\t\tstart: rowStart + runStart,\n\t\t\t\t\t\tend: idx,\n\t\t\t\t\t});\n\t\t\t\t\trunStart = -1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (runStart < 0) runStart = col;\n\t\t\t}\n\t\t}\n\n\t\tif (runStart >= 0) {\n\t\t\tchanges.push({\n\t\t\t\trow,\n\t\t\t\tstartCol: runStart,\n\t\t\t\tcells,\n\t\t\t\tstart: rowStart + runStart,\n\t\t\t\tend: rowStart + cols,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn changes;\n}\n\n// --- SGR state tracker + ANSI serializer ---\n\ninterface SGRState {\n\tattrs: Attr;\n\tbg: number;\n\tfg: number;\n}\n\nfunction sgrReset(): SGRState {\n\treturn { fg: NO_COLOR, bg: NO_COLOR, attrs: Attr.None };\n}\n\n/**\n * Build the minimal SGR escape sequence to transition `from` → the target\n * (`toFg`, `toBg`, `toAttrs`). Returns empty string if no change is needed.\n * Takes the target as primitives so the caller can carry SGR state in a single\n * reused object instead of allocating one per cell.\n */\nfunction buildSGRDelta(\n\tfrom: SGRState,\n\ttoFg: number,\n\ttoBg: number,\n\ttoAttrs: Attr,\n): string {\n\tif (from.fg === toFg && from.bg === toBg && from.attrs === toAttrs) {\n\t\treturn \"\";\n\t}\n\n\tconst parts: string[] = [];\n\n\t// Selectively disable removed attributes instead of full reset.\n\t// SGR 22 disables both Bold and Dim, so if one is removed but the other\n\t// kept, we disable with 22 then re-enable the surviving one.\n\tconst attrsRemoved = from.attrs & ~toAttrs;\n\tif (attrsRemoved) {\n\t\tif (attrsRemoved & (Attr.Bold | Attr.Dim)) {\n\t\t\tparts.push(\"22\"); // disables both bold and dim\n\t\t\t// Re-enable the survivor if only one was removed\n\t\t\tif (toAttrs & Attr.Bold) parts.push(\"1\");\n\t\t\tif (toAttrs & Attr.Dim) parts.push(\"2\");\n\t\t}\n\t\tif (attrsRemoved & Attr.Italic) parts.push(\"23\");\n\t\tif (attrsRemoved & Attr.Underline) parts.push(\"24\");\n\t\tif (attrsRemoved & Attr.Inverse) parts.push(\"27\");\n\t\tif (attrsRemoved & Attr.Strikethrough) parts.push(\"29\");\n\t}\n\n\t// Attributes to add (that weren't already re-enabled above)\n\tconst attrsAdded = toAttrs & ~from.attrs;\n\t// Skip bold/dim if they were already handled by the removal path above\n\tconst boldDimHandled = attrsRemoved & (Attr.Bold | Attr.Dim);\n\tif (attrsAdded & Attr.Bold && !boldDimHandled) parts.push(\"1\");\n\tif (attrsAdded & Attr.Dim && !boldDimHandled) parts.push(\"2\");\n\tif (attrsAdded & Attr.Italic) parts.push(\"3\");\n\tif (attrsAdded & Attr.Underline) parts.push(\"4\");\n\tif (attrsAdded & Attr.Inverse) parts.push(\"7\");\n\tif (attrsAdded & Attr.Strikethrough) parts.push(\"9\");\n\n\t// Foreground — no longer reset by attribute changes, only emitted when changed\n\tif (from.fg !== toFg) {\n\t\tif (toFg === NO_COLOR) {\n\t\t\tparts.push(\"39\"); // default fg\n\t\t} else {\n\t\t\tconst r = (toFg >> 16) & 0xff;\n\t\t\tconst g = (toFg >> 8) & 0xff;\n\t\t\tconst b = toFg & 0xff;\n\t\t\tparts.push(`38;2;${r};${g};${b}`);\n\t\t}\n\t}\n\n\t// Background\n\tif (from.bg !== toBg) {\n\t\tif (toBg === NO_COLOR) {\n\t\t\tparts.push(\"49\"); // default bg\n\t\t} else {\n\t\t\tconst r = (toBg >> 16) & 0xff;\n\t\t\tconst g = (toBg >> 8) & 0xff;\n\t\t\tconst b = toBg & 0xff;\n\t\t\tparts.push(`48;2;${r};${g};${b}`);\n\t\t}\n\t}\n\n\tif (parts.length === 0) return \"\";\n\treturn `\\x1b[${parts.join(\";\")}m`;\n}\n\n/**\n * Serialize changed runs into a minimal ANSI byte sequence.\n * Tracks SGR state across runs to avoid redundant attribute codes.\n */\nexport function serializeChanges(\n\tchanges: ChangedRun[],\n\tinitialState?: SGRState,\n\tenableLinks = true,\n): string {\n\tif (changes.length === 0) return \"\";\n\n\t// Local, mutable SGR state carried across all runs/cells (copied so a\n\t// caller-provided initialState is never mutated).\n\tconst state: SGRState = initialState\n\t\t? { fg: initialState.fg, bg: initialState.bg, attrs: initialState.attrs }\n\t\t: sgrReset();\n\tlet currentLink = \"\";\n\tconst parts: string[] = [];\n\n\tfor (const run of changes) {\n\t\t// CUP: move cursor to position (1-indexed)\n\t\tparts.push(`\\x1b[${run.row + 1};${run.startCol + 1}H`);\n\n\t\tfor (let i = run.start; i < run.end; i++) {\n\t\t\tconst cell = run.cells[i] as Cell;\n\t\t\t// Skip continuation cells (part of a wide character)\n\t\t\tif (cell.width === 0) continue;\n\n\t\t\tconst sgr = buildSGRDelta(state, cell.fg, cell.bg, cell.attrs);\n\t\t\tif (sgr) parts.push(sgr);\n\t\t\t// Carry SGR state in one reused object — no per-cell allocation.\n\t\t\tstate.fg = cell.fg;\n\t\t\tstate.bg = cell.bg;\n\t\t\tstate.attrs = cell.attrs;\n\n\t\t\t// OSC 8 hyperlink transitions (only when terminal supports it)\n\t\t\tif (enableLinks && cell.link !== currentLink) {\n\t\t\t\tif (currentLink) {\n\t\t\t\t\tparts.push(\"\\x1b]8;;\\x1b\\\\\"); // close previous link\n\t\t\t\t}\n\t\t\t\tif (cell.link) {\n\t\t\t\t\tparts.push(`\\x1b]8;;${cell.link}\\x1b\\\\`); // open new link\n\t\t\t\t}\n\t\t\t\tcurrentLink = cell.link;\n\t\t\t}\n\n\t\t\tparts.push(cell.char);\n\t\t}\n\t}\n\n\t// Close any open link\n\tif (enableLinks && currentLink) {\n\t\tparts.push(\"\\x1b]8;;\\x1b\\\\\");\n\t}\n\n\t// Reset SGR state so terminal attributes don't bleed\n\tif (\n\t\tstate.attrs !== Attr.None ||\n\t\tstate.fg !== NO_COLOR ||\n\t\tstate.bg !== NO_COLOR\n\t) {\n\t\tparts.push(\"\\x1b[0m\");\n\t}\n\n\treturn parts.join(\"\");\n}\n\n/**\n * Wrap frame data in synchronized output markers (DEC private mode 2026).\n * The terminal holds all rendering until ESU, then paints atomically.\n */\nexport function wrapSynchronized(data: string): string {\n\treturn `\\x1b[?2026h${data}\\x1b[?2026l`;\n}\n\n// --- Color helpers ---\n\n/**\n * Resolve any ColorInput to a packed 24-bit RGB number for Cell fg/bg.\n * Accepts hex (#rgb, #rrggbb), named colors, rgb(), hsl(), numbers, etc.\n * Returns NO_COLOR for invalid input.\n */\nexport function color(input: Bun.ColorInput): number {\n\treturn Bun.color(input, \"number\") ?? NO_COLOR;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,OAAO,MAAMA,IAAI,GAAG;EACnBC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,GAAG,EAAE,CAAC;EACNC,MAAM,EAAE,CAAC;EACTC,SAAS,EAAE,CAAC;EACZC,OAAO,EAAE,EAAE;EACXC,aAAa,EAAE;AAChB,CAAU;AAGV;AACA,OAAO,MAAMC,QAAQ,GAAG,CAAC,CAAC;AAiB1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,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