Skip to content

Refactor/uniform scale 2d transform#30

Merged
u8array merged 6 commits into
mainfrom
refactor/uniform-scale-2d-transform
May 8, 2026
Merged

Refactor/uniform scale 2d transform#30
u8array merged 6 commits into
mainfrom
refactor/uniform-scale-2d-transform

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented May 8, 2026

No description provided.

u8array added 4 commits May 8, 2026 22:51
QR, Aztec, and DataMatrix all share the same commitTransform shape:
clamp(min, max, round(prop * min(sx, sy))) on a single integer module-
size prop. The bodies were near-duplicates; Aztec was missing the call
entirely (canvas resize had no effect — users had to edit the props
panel). Closes that gap as a side effect of consolidating.

Add a factory helper, parametrised by prop name and range, and route
all three registries through it.
Two small ergonomics improvements to the helper added in the previous
commit:

- Default P to Record<K, number> in the helper signature so callers no
  longer have to repeat the prop literal twice as a type argument and
  again as the runtime arg. K is inferred from the runtime arg, P is
  contextually narrowed by the registry slot. Type safety is preserved
  (typos still fail via parameter contravariance against the registry's
  AztecProps/QrCodeProps/DataMatrixProps).

- Extract per-registry MIN/MAX constants for the magnification /
  dimension range. The same range was repeated three times per code
  (helper call + NumberInput min + max) — now one source of truth per
  registry file.
…m invariant

Two tests motivated by the aztec resize regression:

1. Direct unit test for commitUniformScaleTransform — clamp on both
   ends, integer rounding, min(sx,sy) selection. The helper's other
   siblings in transformHelpers.ts have no direct tests either, but
   this is the only one with non-trivial logic worth pinning down.

2. Smoke test in registry.test.ts: every code-2d type must declare a
   commitTransform handler. This is the invariant aztec violated
   silently — without it, a canvas drag-resize is a no-op. Catches
   the same shape of regression for any future 2D code.
- transformHelpers.test.ts: drop the explicit type args at the helper
  call to actually exercise the inference path the previous commit
  introduced. The unused Sample type stays as the props shape.
- qrcode/aztec/datamatrix: shorten the interface field comments to the
  semantic meaning. The range was duplicated as 'range FOO_MIN..MAX'
  pointing at file-private constants — readers consulting the props
  type from outside don't see those, and inside the file the constants
  sit right above. Plain 'module size in dots' is enough.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors 2D barcode components to use a new commitUniformScaleTransform helper for consistent scaling and introduces constants for property limits. It also adds unit tests for the transform helper and a registry test to ensure all 2D code types implement a transformation handler. A review comment points out that the maximum error correction level for Aztec codes should be increased to 300 to support Aztec Runes.

Comment thread src/registry/aztec.tsx Outdated
u8array added 2 commits May 8, 2026 23:08
EC_LEVEL_MAX was inherited as 232 from the previously hardcoded value;
that excludes Aztec Rune (ecLevel=300), which the AztecProps comment
documents as valid. The NumberInput's single-max constraint cannot
express the discontinuous domain (0, 1-99, 101-104, 201-232, 300), so
use the highest valid value as the upper bound. Closes the pre-existing
gap surfaced by extracting the constant.
Strip the domain restatement (already in AztecProps), the regression
reference (commit-message material), and keep only the non-obvious
constraint: NumberInput's single-max can't model the discontinuous
domain, so we pick the highest valid value.
@u8array u8array merged commit 6fc1763 into main May 8, 2026
2 checks passed
@u8array u8array deleted the refactor/uniform-scale-2d-transform branch May 8, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant