From 4bd8f27dece561138adcf292ad278d01eb2b1a72 Mon Sep 17 00:00:00 2001 From: Nick Shirokov Date: Thu, 21 May 2026 18:38:34 +0300 Subject: [PATCH] =?UTF-8?q?feat(skd):=20preset=20style=3Dnone=20+=20=D0=B4?= =?UTF-8?q?=D0=B5=D1=82=D0=B5=D0=BA=D1=82=20=D0=BF=D1=83=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20fingerprint=20=D0=B2=20decompile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Закрывает простую часть категории C: шаблоны где у ячеек appearance содержит только per-cell атрибуты (МинимальнаяШирина и др.) без font/ borders/colors. Раньше такие шаблоны попадали в TemplateStyleMismatch. - skd-compile (ps1+py): новый preset 'none' со всеми стилевыми полями null/false. Emit-CellAppearance / _emit_cell_appearance пропускают Font-элемент когда style.font=null. - skd-decompile: пустой fingerprint (после отсева per-cell ключей) не считается за стиль ячейки; если все non-merge ячейки шаблона имели пустой fp — эмитим style="none" вместо sentinel. - Новый тест template-no-style (round-trip bit-perfect). - Versions: compile v1.31→v1.32, decompile v0.13→v0.14. Метрики: - ERP-сэмпл 30: 32 → 24 sentinel'ов, clean 24→26/30 - Корпус из 40 отчётов целевого класса: 45 → 39 sentinel'ов, 19/40 clean Остаточные sentinel'ы — реальный custom appearance (нестандартный шрифт/ выравнивание/цвет вне built-in пресетов). Требует расширения DSL под hashtable-style — отдельная задача. --- .../skd-compile/scripts/skd-compile.ps1 | 24 ++-- .../skills/skd-compile/scripts/skd-compile.py | 23 ++-- .../skd-decompile/scripts/skd-decompile.ps1 | 23 ++-- .../snapshots/template-no-style/Template.xml | 109 ++++++++++++++++++ .../template-no-style/decompiled.json | 28 +++++ .../skd-decompile/template-no-style.json | 27 +++++ 6 files changed, 211 insertions(+), 23 deletions(-) create mode 100644 tests/skills/cases/skd-decompile/snapshots/template-no-style/Template.xml create mode 100644 tests/skills/cases/skd-decompile/snapshots/template-no-style/decompiled.json create mode 100644 tests/skills/cases/skd-decompile/template-no-style.json diff --git a/.claude/skills/skd-compile/scripts/skd-compile.ps1 b/.claude/skills/skd-compile/scripts/skd-compile.ps1 index ff745829..2668c83b 100644 --- a/.claude/skills/skd-compile/scripts/skd-compile.ps1 +++ b/.claude/skills/skd-compile/scripts/skd-compile.ps1 @@ -1,4 +1,4 @@ -# skd-compile v1.31 — Compile 1C DCS from JSON +# skd-compile v1.32 — Compile 1C DCS from JSON # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills param( [string]$DefinitionFile, @@ -1412,6 +1412,12 @@ function Emit-ParamValue { # Built-in style presets $script:areaStylePresets = @{ + none = @{ + font = $null; fontSize = $null; bold = $false; italic = $false + hAlign = $null; vAlign = $null; wrap = $false + bgColor = $null; textColor = $null + borderColor = $null; borders = $false + } data = @{ font = 'Arial'; fontSize = 10; bold = $false; italic = $false hAlign = $null; vAlign = $null; wrap = $false @@ -1530,13 +1536,15 @@ function Emit-CellAppearance { } X "$ind" } - # Font - $boldStr = if ($style.bold) { "true" } else { "false" } - $italicStr = if ($style.italic) { "true" } else { "false" } - X "$ind" - X "$ind`tШрифт" - X "$ind`t" - X "$ind" + # Font (skip if style has no font configured — for "none" preset) + if ($style.font) { + $boldStr = if ($style.bold) { "true" } else { "false" } + $italicStr = if ($style.italic) { "true" } else { "false" } + X "$ind" + X "$ind`tШрифт" + X "$ind`t" + X "$ind" + } # Horizontal alignment if ($style.hAlign) { X "$ind" diff --git a/.claude/skills/skd-compile/scripts/skd-compile.py b/.claude/skills/skd-compile/scripts/skd-compile.py index 667600be..c97fc6f1 100644 --- a/.claude/skills/skd-compile/scripts/skd-compile.py +++ b/.claude/skills/skd-compile/scripts/skd-compile.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# skd-compile v1.31 — Compile 1C DCS from JSON +# skd-compile v1.32 — Compile 1C DCS from JSON # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills import argparse import json @@ -1163,6 +1163,12 @@ def emit_parameters(lines, defn): # === AreaTemplate DSL === AREA_STYLE_PRESETS = { + 'none': { + 'font': None, 'fontSize': None, 'bold': False, 'italic': False, + 'hAlign': None, 'vAlign': None, 'wrap': False, + 'bgColor': None, 'textColor': None, + 'borderColor': None, 'borders': False, + }, 'data': { 'font': 'Arial', 'fontSize': 10, 'bold': False, 'italic': False, 'hAlign': None, 'vAlign': None, 'wrap': False, @@ -1258,13 +1264,14 @@ def _emit_cell_appearance(lines, style, width=0, v_merge=False, h_merge=False, m lines.append(f'{ind}\t\t') lines.append(f'{ind}\t') lines.append(f'{ind}') - # Font - bold_str = 'true' if style.get('bold') else 'false' - italic_str = 'true' if style.get('italic') else 'false' - lines.append(f'{ind}') - lines.append(f'{ind}\t\u0428\u0440\u0438\u0444\u0442') - lines.append(f'{ind}\t') - lines.append(f'{ind}') + # Font (skip if style has no font configured \u2014 for "none" preset) + if style.get('font'): + bold_str = 'true' if style.get('bold') else 'false' + italic_str = 'true' if style.get('italic') else 'false' + lines.append(f'{ind}') + lines.append(f'{ind}\t\u0428\u0440\u0438\u0444\u0442') + lines.append(f'{ind}\t') + lines.append(f'{ind}') # Horizontal alignment if style.get('hAlign'): lines.append(f'{ind}') diff --git a/.claude/skills/skd-decompile/scripts/skd-decompile.ps1 b/.claude/skills/skd-decompile/scripts/skd-decompile.ps1 index 099d8610..e86f7516 100644 --- a/.claude/skills/skd-decompile/scripts/skd-decompile.ps1 +++ b/.claude/skills/skd-decompile/scripts/skd-decompile.ps1 @@ -1,4 +1,4 @@ -# skd-decompile v0.13 — Decompile 1C DCS Template.xml to JSON DSL (draft) +# skd-decompile v0.14 — Decompile 1C DCS Template.xml to JSON DSL (draft) # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills param( [Parameter(Mandatory)] @@ -858,6 +858,7 @@ function Build-Template { $minHeight = $null $detectedStyle = $null $styleMismatch = $false + $hasAnyNonEmptyFp = $false # true если хоть одна ячейка имеет стилевые атрибуты $drilldownByParam = @{} # param name → field name (X from Расшифровка_X) $rowIdx = 0 @@ -875,12 +876,17 @@ function Build-Template { # Style detection (skip empty cells with no appearance, and merge cells) if ($appNode -and -not $perCell.mergeV -and -not $perCell.mergeH) { $fp = Get-AppearanceFingerprint $appNode - $matched = Match-BuiltinStyle $fp - if ($null -eq $detectedStyle) { - $detectedStyle = $matched - } elseif ($matched -ne $detectedStyle) { - $styleMismatch = $true + if ($fp.Count -gt 0) { + # Ячейка имеет стилевые атрибуты — пробуем match с built-in + $hasAnyNonEmptyFp = $true + $matched = Match-BuiltinStyle $fp + if ($null -eq $detectedStyle) { + $detectedStyle = $matched + } elseif ($matched -ne $detectedStyle) { + $styleMismatch = $true + } } + # Пустой fp (только per-cell width/merge) — ячейка без стиля, не контрибутирует. } # Drilldown attachment @@ -930,7 +936,10 @@ function Build-Template { # Decide output form if ($detectedStyle -and -not $styleMismatch) { $tmplObj['style'] = $detectedStyle - } elseif ($styleMismatch -or ($null -eq $detectedStyle -and $rows.Count -gt 0)) { + } elseif (-not $hasAnyNonEmptyFp -and $rows.Count -gt 0) { + # Все ячейки без стилевых атрибутов — это шаблон "без стиля" + $tmplObj['style'] = 'none' + } elseif ($styleMismatch -or ($null -eq $detectedStyle -and $hasAnyNonEmptyFp)) { # Couldn't unify style — emit sentinel $tmplObj['__unsupported__'] = (New-Sentinel -kind 'TemplateStyleMismatch' -loc $loc -detail 'Шаблон содержит ячейки с непокрытым/неоднородным оформлением (Кольцо 2)')['__unsupported__'] } diff --git a/tests/skills/cases/skd-decompile/snapshots/template-no-style/Template.xml b/tests/skills/cases/skd-decompile/snapshots/template-no-style/Template.xml new file mode 100644 index 00000000..93975050 --- /dev/null +++ b/tests/skills/cases/skd-decompile/snapshots/template-no-style/Template.xml @@ -0,0 +1,109 @@ + + + + ИсточникДанных1 + Local + + + Тест + + Поле1 + Поле1 + + xs:string + + 0 + Variable + + + + + Поле2 + Поле2 + + xs:string + + 0 + Variable + + + + ИсточникДанных1 + ВЫБРАТЬ * ИЗ Справочник.Сотрудники + + + + Основной + + + ru + Основной + + + + + + + + + + + + + + + + diff --git a/tests/skills/cases/skd-decompile/snapshots/template-no-style/decompiled.json b/tests/skills/cases/skd-decompile/snapshots/template-no-style/decompiled.json new file mode 100644 index 00000000..621c8bcf --- /dev/null +++ b/tests/skills/cases/skd-decompile/snapshots/template-no-style/decompiled.json @@ -0,0 +1,28 @@ +{ + "dataSets": [ + { + "name": "Тест", + "query": "ВЫБРАТЬ * ИЗ Справочник.Сотрудники", + "fields": [ + "Поле1: string", + "Поле2: string" + ] + } + ], + "templates": [ + { + "name": "БезСтиля", + "style": "none", + "widths": [ + "7", + "7" + ], + "rows": [ + [ + "A", + "B" + ] + ] + } + ] +} \ No newline at end of file diff --git a/tests/skills/cases/skd-decompile/template-no-style.json b/tests/skills/cases/skd-decompile/template-no-style.json new file mode 100644 index 00000000..806aa64b --- /dev/null +++ b/tests/skills/cases/skd-decompile/template-no-style.json @@ -0,0 +1,27 @@ +{ + "name": "Шаблон без стилевых атрибутов (style=none) — только per-cell width", + "preRun": [ + { + "script": "skd-compile/scripts/skd-compile", + "input": { + "dataSets": [{ + "name": "Тест", + "query": "ВЫБРАТЬ * ИЗ Справочник.Сотрудники", + "fields": ["Поле1: string", "Поле2: string"] + }], + "templates": [ + { + "name": "БезСтиля", + "style": "none", + "widths": [7, 7], + "rows": [["A", "B"]] + } + ] + }, + "args": { "-DefinitionFile": "{inputFile}", "-OutputPath": "Template.xml" }, + "cwd": "{workDir}" + } + ], + "params": { "templatePath": "Template.xml" }, + "outputPath": "decompiled.json" +}