Repository navigation
refactor(core): dedupe diff pipelines, CJK width heuristic, and micro-duplications (first batch of #2014) - #2026
Merged
Merged
Conversation
…-duplications First batch of the packages/core refactoring analysis (#2014). Zero behavior change — output SVGs are byte-identical (verified by rendering all example projects on main and this branch and diffing). - Extract resolveBeforeAfter / assembleDiffSheets / toDiffStateMaps helpers in index.ts and use them from compileSystemDiff, compileDeployDiff, compileOrgDiff, and buildAllViewsSvgDiffProject (point 1). - Consolidate the CJK text-width heuristic (CJK = 1.5x char width, threshold > U+2E80) into charDisplayWidth / estimateTextWidth in rendering-constants.ts; layout.ts, deploy-layout.ts, and the three inline copies in svg-builder.ts now share it. Name svg-renderer's 0.8 ratio as RENDERED_DESC_FONT_RATIO (value untouched) and fix the misleading DESCRIPTION_FONT_RATIO comment; cross-reference matrix-svg's intentionally different heuristic (point 3). - Widen LayoutNode["kind"] with OrgLayoutNodeKind and drop the 'as unknown as' cast in exporter/drawio/org-layout.ts (point 7, type-only). - Move src/render/matrix-svg.ts (+ test) into src/renderer/, hoist the duplicated toPascalCase into translate/identifier.ts, and document why the two escapeXml variants (svg-builder vs mxgraph-builder) are kept separate (point 8). Refs #2014 Co-Authored-By: Claude <[email protected]>
…rix-svg move ADR-20260502-01 tracks packages/core/src/render/matrix-svg.ts as a file assumption; update it to the new renderer/ location. Also apply oxfmt to layout.ts (leftover blank line from the estimateTextWidth removal). Refs #2014 Co-Authored-By: Claude <[email protected]>
kompiro
added a commit
that referenced
this pull request
Jul 16, 2026
The CJK/ellipsis truncation fix in PR #2026 changes rendered SVG output, so it is a user-visible patch to @karasu-tools/core and the karasu CLI (which bundles core as a devDependency, so the bump does not cascade). Refs #2014 Co-Authored-By: Claude <[email protected]>
This was referenced Jul 16, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First batch of the
packages/corerefactoring opportunities analyzed in #2014 (points 1, 3, 7, 8), plus the fixes for all 8 code-review findings.Behavior change scope: everything is byte-identical except one deliberate fix — node-card description truncation now goes through the shared
truncateToWidth, so CJK descriptions are truncated by display width instead of raw char count (they used to overflow the node border). Details and full verification below.Point 1 — dedupe the three
compile*Diffpipelines (src/index.ts)Extracted shared helpers and used them from
compileSystemDiff,compileDeployDiff,compileOrgDiff, andbuildAllViewsSvgDiffProject:resolveBeforeAfter(fs, beforePath, afterPath)— sharedImportResolver+ before/after resolutionbeforeAfterDiagnostics(resolved)— fresh concat of the two sides' resolver diagnosticsassembleDiffSheets(before, after, theme, badgeLabels, displayMode)— builtin + before + after sheets, icon-theme sheet appended in icon modetoDiffStateMaps(diffed)— flatten diff metadata into theMap<id, state>shape the renderers consumeReview follow-up: each
compile*Diffis now split into a thin resolve wrapper + a synccompile*DiffFromResolvedbody, andbuildAllViewsSvgDiffProjectfeeds its single upfront resolver pass to all applicable view diffs — 2 resolver passes per bundled diff instead of up to 8. Output unchanged.Point 3 — consolidate the CJK text-width heuristic
charDisplayWidth(ch, charWidth)/estimateTextWidth(text, charWidth)torenderer/rendering-constants.ts(CJK = 1.5× char width, threshold> U+2E80— values untouched)renderer/layout.tsandrenderer/deploy-layout.tsdrop their line-for-line identical private copies; the three inline copies insvg-builder.ts'struncateToWidth/wrapToWidthnow call the shared helper0.8ratio insvg-renderer.tsasRENDERED_DESC_FONT_RATIO(value not unified to layout's 0.85 — that would change output geometry) and fixed the misleading// DESCRIPTION_FONT_RATIOcommentestimateTableTextWidthto avoid colliding with the sharedestimateTextWidthDeliberate behavior fix: description truncation on node cards
renderNode's description truncation (used by system and deploy cards viarenderFromLayout) previously did a manualfloor(availableWidth / charWidth)char-count slice: it counted CJK chars as 1× width (so CJK descriptions were truncated too late and overflowed the node border) and appended…beyond the width budget (so even truncated ASCII descriptions overflowed by up to one char). It now calls the sharedtruncateToWidth, which counts CJK as 1.5× and reserves the ellipsis width.Verified by rendering all 13 example projects (bundled + bundled-diff × default + icon = 52 SVGs) on
mainand on this branch:在庫データの一元管理→在庫データの…,公開前チェック・違反通報の処理→公開前チェック・違反…); (b) already-truncated descriptions (ASCII and CJK) end one character earlier because the ellipsis now fits inside the width budget (e.g.AI assistant…→AI assistan…,Kubernetes (GKE)→Kubernetes (GKE…).Point 7 — fix the illegal
LayoutNode["kind"]cast (type-only)Widened
LayoutNode["kind"]with a newOrgLayoutNodeKindunion inrenderer/layout-types.tsand deleted the"member" as unknown as LayoutNode["kind"]cast inexporter/drawio/org-layout.ts. Per review, the union is narrowed to just"member"— teams are emitted asContainerRect, never asLayoutNode.Point 8 — placement and micro-duplication cleanups
src/render/matrix-svg.ts(+ its test) intosrc/renderer/; updated theindex.tsre-export, ADR-20260502-01's file assumptions, and (per review) the stale paths indocs/acceptance/1062-crud-matrix-view.mdanddocs/test-perspectives/TPL-20260510-21-scoped-glance-drill-down.mdtoPascalCasefromtranslate/db.ts/translate/openapi.tsinto a sharedtranslate/identifier.ts. Per review, the module comment now states honestly thattranslate/wrangler.tskeeps its owntoIdentifieron purpose (undefined-return for unusable input, leading-digit guard, drops trailing punctuation — folding it in would change wrangler output), with cross-references in both filesescapeXmlvariants exist (renderer/svg-builder.tsvsexporter/drawio/mxgraph-builder.ts— the'escaping is load-bearing for mxGraph); intentionally not mergedrenderNodenow usesNODE_PADDING_Xinstead of the hardcoded40 * 2(value unchanged)Verification
pnpm --filter @karasu-tools/core testpnpm typecheck(full repo)pnpm check:cyclespnpm knip@resvg/resvg-wasmconfig hint, identical onmain)pnpm lintmainvs branch: 10 byte-identical; the 42 that differ contain only the documented description-truncation fix (element-level scripted check: 0 non-truncation changes)pnpm adr:check-assumptionsChangeset:
.changeset/description-truncation-display-width.md(patch for@karasu-tools/coreandkarasu— the truncation fix is a user-visible rendering change; the refactoring itself is internal).Follow-ups (out of scope here, tracked in #2014): point 2 (compile facade extraction, builds on point 1's helpers), points 4–6 (layout / renderNode / extractView decomposition).
Refs #2014
🤖 Generated with Claude Code