mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-09-03 16:50:52 +03:00
feat(skd): inline cell style override + закрытие категории C
Cell в rows теперь может быть либо string ("text"/"{param}"/"|"/">"/null),
либо объектом {value, style: "presetName"}. Object form применяется когда
стиль ячейки отличается от template default.
compile (ps1+py): helpers _get_cell_value / _get_cell_style_or_default.
Emit-AreaTemplateDSL / _emit_area_template_dsl используют per-cell style
для appearance вместо единого template style.
decompile: refactor Build-Template. Первый pass — собрать style name per
cell в cellStyleMap. Второй pass — выбрать template default как most
frequent style. Третий pass — обернуть в {value, style} ячейки, чьи
стили отличаются от default. TemplateStyleMismatch sentinel удалён —
теперь все случаи покрываются через inline override.
Дедуп при обоих pass'ах (Match-PresetByShape) работает через
effectivePresets (built-in + user + ранее аллоцированные customN), так
что одинаковые shape'ы получают одно имя.
Новый тест template-inline-cell-style (round-trip bit-perfect).
Versions: compile v1.32→v1.33, decompile v0.15→v0.16.
Метрики на момент коммита:
- ERP-сэмпл 30: 30/30 clean, 0 sentinel'ов
- Корпус из 40 отчётов целевого класса: 40/40 clean, 0 sentinel'ов
Закрывает категории A, B, C полностью на обоих корпусах.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# skd-decompile v0.15 — Decompile 1C DCS Template.xml to JSON DSL (draft)
|
||||
# skd-decompile v0.16 — Decompile 1C DCS Template.xml to JSON DSL (draft)
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -933,9 +933,8 @@ function Build-Template {
|
||||
$rows = @()
|
||||
$widths = $null
|
||||
$minHeight = $null
|
||||
$detectedStyle = $null
|
||||
$styleMismatch = $false
|
||||
$hasAnyNonEmptyFp = $false # true если хоть одна ячейка имеет стилевые атрибуты
|
||||
$cellStyleMap = @{} # "r,c" → имя стиля для конкретной ячейки (null для merge/no-style)
|
||||
$hasAnyStyledCell = $false
|
||||
$drilldownByParam = @{} # param name → field name (X from Расшифровка_X)
|
||||
|
||||
$rowIdx = 0
|
||||
@@ -950,23 +949,17 @@ function Build-Template {
|
||||
$perCell = Get-CellPerCellAttrs $appNode
|
||||
$content = Get-CellContent $cellNode $perCell
|
||||
|
||||
# Style detection (skip empty cells with no appearance, and merge cells)
|
||||
# Style detection (skip merge cells)
|
||||
if ($appNode -and -not $perCell.mergeV -and -not $perCell.mergeH) {
|
||||
$cellPreset = Extract-CellPreset $appNode
|
||||
if ($null -ne $cellPreset) {
|
||||
# Ячейка имеет стилевые атрибуты — match против effectivePresets, иначе аллоцируем custom
|
||||
$hasAnyNonEmptyFp = $true
|
||||
$matched = Match-PresetByShape $cellPreset
|
||||
if ($null -eq $matched) {
|
||||
$matched = Allocate-CustomStyle $cellPreset
|
||||
}
|
||||
if ($null -eq $detectedStyle) {
|
||||
$detectedStyle = $matched
|
||||
} elseif ($matched -ne $detectedStyle) {
|
||||
$styleMismatch = $true
|
||||
}
|
||||
$cellStyleMap["$rowIdx,$colIdx"] = $matched
|
||||
$hasAnyStyledCell = $true
|
||||
}
|
||||
# Если cellPreset = $null — ячейка без стилевых атрибутов (только per-cell width/merge), не контрибутирует.
|
||||
}
|
||||
|
||||
# Drilldown attachment
|
||||
@@ -987,6 +980,42 @@ function Build-Template {
|
||||
$rowIdx++
|
||||
}
|
||||
|
||||
# Template default = наиболее частый стиль ячеек.
|
||||
$templateDefault = $null
|
||||
if ($hasAnyStyledCell) {
|
||||
$counts = @{}
|
||||
foreach ($k in $cellStyleMap.Keys) {
|
||||
$name = $cellStyleMap[$k]
|
||||
if (-not $counts.ContainsKey($name)) { $counts[$name] = 0 }
|
||||
$counts[$name]++
|
||||
}
|
||||
$maxCount = 0
|
||||
foreach ($name in $counts.Keys) {
|
||||
if ($counts[$name] -gt $maxCount) {
|
||||
$maxCount = $counts[$name]
|
||||
$templateDefault = $name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Если есть ячейки со стилем, отличным от template default — оборачиваем их в object form.
|
||||
if ($templateDefault) {
|
||||
$rowsOut = @()
|
||||
for ($r = 0; $r -lt $rows.Count; $r++) {
|
||||
$newRow = @()
|
||||
for ($c = 0; $c -lt $rows[$r].Count; $c++) {
|
||||
$key = "$r,$c"
|
||||
if ($cellStyleMap.ContainsKey($key) -and $cellStyleMap[$key] -ne $templateDefault) {
|
||||
$newRow += [ordered]@{ value = $rows[$r][$c]; style = $cellStyleMap[$key] }
|
||||
} else {
|
||||
$newRow += $rows[$r][$c]
|
||||
}
|
||||
}
|
||||
$rowsOut += ,$newRow
|
||||
}
|
||||
$rows = $rowsOut
|
||||
}
|
||||
|
||||
# Template parameters (and drilldown folding)
|
||||
$paramNodes = $templateNode.SelectNodes("r:parameter", $ns)
|
||||
$exprParams = [ordered]@{}
|
||||
@@ -1014,14 +1043,11 @@ function Build-Template {
|
||||
}
|
||||
|
||||
# Decide output form
|
||||
if ($detectedStyle -and -not $styleMismatch) {
|
||||
$tmplObj['style'] = $detectedStyle
|
||||
} elseif (-not $hasAnyNonEmptyFp -and $rows.Count -gt 0) {
|
||||
if ($templateDefault) {
|
||||
$tmplObj['style'] = $templateDefault
|
||||
} elseif ($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__']
|
||||
}
|
||||
if ($widths) { $tmplObj['widths'] = $widths }
|
||||
if ($minHeight) { $tmplObj['minHeight'] = $minHeight }
|
||||
|
||||
Reference in New Issue
Block a user