mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-08-01 17:27:45 +03:00
Optimize mxl-decompile output: deduplicate fonts, remove noise
- Font deduplication: identical fonts reuse existing name (6→4 on Акт)
- Don't emit "rowStyle": "default" for empty styles
- Don't emit "cells": [] on empty rows
- Don't emit "default": {} in styles section
- Result: ~10% smaller JSON output, cleaner for Claude to read/write
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
03a6820f69
commit
8092015807
@@ -276,9 +276,25 @@ if ($rawFonts.Count -gt 0) {
|
|||||||
$fontDefs["default"] = $rawFonts[0]
|
$fontDefs["default"] = $rawFonts[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-FontKey {
|
||||||
|
param($f)
|
||||||
|
return "$($f.Face)|$($f.Size)|$($f.Bold)|$($f.Italic)|$($f.Underline)|$($f.Strikeout)"
|
||||||
|
}
|
||||||
|
|
||||||
|
$fontKeyMap = @{}
|
||||||
|
$fontKeyMap[(Get-FontKey $rawFonts[0])] = "default"
|
||||||
|
|
||||||
for ($i = 1; $i -lt $rawFonts.Count; $i++) {
|
for ($i = 1; $i -lt $rawFonts.Count; $i++) {
|
||||||
$f = $rawFonts[$i]
|
$f = $rawFonts[$i]
|
||||||
$df = $rawFonts[0]
|
$df = $rawFonts[0]
|
||||||
|
|
||||||
|
# Dedup: if identical font already named, reuse
|
||||||
|
$fKey = Get-FontKey $f
|
||||||
|
if ($fontKeyMap.ContainsKey($fKey)) {
|
||||||
|
$fontNames[$i] = $fontKeyMap[$fKey]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
$name = $null
|
$name = $null
|
||||||
|
|
||||||
if ($f.Face -eq $df.Face -and $f.Size -eq $df.Size) {
|
if ($f.Face -eq $df.Face -and $f.Size -eq $df.Size) {
|
||||||
@@ -311,6 +327,7 @@ for ($i = 1; $i -lt $rawFonts.Count; $i++) {
|
|||||||
|
|
||||||
$fontNames[$i] = $name
|
$fontNames[$i] = $name
|
||||||
$fontDefs[$name] = $f
|
$fontDefs[$name] = $f
|
||||||
|
$fontKeyMap[$fKey] = $name
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- 11. Collect and name styles ---
|
# --- 11. Collect and name styles ---
|
||||||
@@ -409,7 +426,7 @@ foreach ($area in $namedAreas) {
|
|||||||
$rd = $rowData[$globalRow]
|
$rd = $rowData[$globalRow]
|
||||||
|
|
||||||
if (-not $rd -or $rd.Empty) {
|
if (-not $rd -or $rd.Empty) {
|
||||||
$areaRows += [ordered]@{ cells = [array]@() }
|
$areaRows += [ordered]@{}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +472,7 @@ foreach ($area in $namedAreas) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rowStyleName) { $dslRow["rowStyle"] = $rowStyleName }
|
if ($rowStyleName -and $rowStyleName -ne "default") { $dslRow["rowStyle"] = $rowStyleName }
|
||||||
|
|
||||||
# Build cell list
|
# Build cell list
|
||||||
$dslCells = @()
|
$dslCells = @()
|
||||||
@@ -499,7 +516,7 @@ foreach ($area in $namedAreas) {
|
|||||||
$dslCells += $dslCell
|
$dslCells += $dslCell
|
||||||
}
|
}
|
||||||
|
|
||||||
$dslRow["cells"] = [array]$dslCells
|
if ($dslCells.Count -gt 0) { $dslRow["cells"] = [array]$dslCells }
|
||||||
$areaRows += $dslRow
|
$areaRows += $dslRow
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,6 +574,11 @@ $result = [ordered]@{
|
|||||||
defaultWidth = $defaultWidth
|
defaultWidth = $defaultWidth
|
||||||
}
|
}
|
||||||
if ($compressedWidths.Count -gt 0) { $result["columnWidths"] = $compressedWidths }
|
if ($compressedWidths.Count -gt 0) { $result["columnWidths"] = $compressedWidths }
|
||||||
|
# Remove empty "default" style
|
||||||
|
if ($styleDefs.Contains("default") -and $styleDefs["default"].Count -eq 0) {
|
||||||
|
$styleDefs.Remove("default")
|
||||||
|
}
|
||||||
|
|
||||||
$result["fonts"] = $fontsOut
|
$result["fonts"] = $fontsOut
|
||||||
$result["styles"] = $styleDefs
|
$result["styles"] = $styleDefs
|
||||||
$result["areas"] = [array]$dslAreas
|
$result["areas"] = [array]$dslAreas
|
||||||
|
|||||||
Reference in New Issue
Block a user