ADR
A unit-interval style type for `opacity` and `cornerSmoothing`
Context
Two Styles properties carry a number that is only meaningful between 0 and 1, and neither says so.
In types/Styles.ts both are typed as the fully generic union:
# Currentopacity: Style # string | boolean | number | null | TokenReference | PropBinding | ConditionalcornerSmoothing: Style # sameIn schema/styles.schema.json both $ref NumberStyleValue, which is narrower but unbounded:
NumberStyleValue: oneOf: - type: number # no minimum, no maximum - $ref: TokenReference - type: "null"Two problems follow.
The range is undeclared, so an out-of-range literal validates clean and fails later. An authoring round wrote opacity: 76, intending 76 percent. specs validate reported zero errors; the write failed eleven seconds into a canvas render with Property "opacity" failed validation: Too big: expected number to be <=1. The validator already resolves and prints these numbers — its own output shows a token resolving to 56 — so it holds the value at the exact moment it could compare it against a declared bound. It has no bound to compare against.
The type and the schema disagree about what is even permitted. The TS type admits a string, a boolean, a PropBinding and a Conditional; the JSON Schema admits none of them. A consumer compiling against types/ sees a wider contract than the one specs are validated against.
The range itself is already established vocabulary in this schema — gradient centre axes, gradient stop positions, and colour alpha all declare minimum: 0, maximum: 1 with “normalised 0–1” descriptions. What is missing is a style type carrying that bound, usable by a token-bindable property.
One constraint shapes the solution. These properties are token-bindable, and in this library the opacity tokens resolve on a 0–100 scale: {$token: Constants/Opacity/72} is correct and renders correctly, while the literal 72 does not. So the bound belongs on the literal branch only. A bound applied across the whole union would reject the form that works.
Decision Drivers
- Constitution §Typing — a property whose value may be token-bound MUST use
Styleor a domain-specific type likeColorStyle. A named narrow type is the sanctioned route; a bare structural enum is not available here. - Type ↔ schema symmetry — no drift permitted. This change must close the existing asymmetry rather than add to it.
- The declared contract is the only authority — the bound must live in
schema/, so validation enforces it by reading the contract and not from a range table maintained in validator code. - Token references must keep resolving on their own scale — the bound cannot apply to the
TokenReferencebranch. - Reuse over per-property special-casing — one type, adopted by both properties and available to the next property that needs it.
Options Considered
Decision 1 — Where the range constraint lives
Option A: A domain-specific style type carrying the bound (Selected)
Define UnitIntervalStyle in types/ and UnitIntervalStyleValue in schema/, mirroring the ColorStyle ↔ ColorStyleValue pair. The numeric branch declares minimum: 0 and maximum: 1; the TokenReference and null branches are unconstrained.
Pros:
- Satisfies the constitution’s typing rule by the route it names explicitly — a domain-specific type, as
ColorStylealready is for the four colour properties. - Puts the bound in the contract, so validation enforces it with no validator-side range logic.
- Closes the type ↔ schema asymmetry in the same change, because the new TS type matches the new schema definition exactly.
- Reusable: any future property whose literal is a 0–1 fraction adopts it rather than restating the bound.
Cons / Trade-offs:
- Narrowing the TS type is a breaking type-signature change for a consumer that assigned a string, a boolean, a
PropBinding, or aConditionalto either property — even though the JSON Schema never permitted those.
Option B: Bound NumberStyleValue itself (Rejected)
Add minimum/maximum to the existing shared number definition.
Rejected because: NumberStyleValue is the type for every pure number in Styles — strokeWeight, itemSpacing, width, cornerRadius. Bounding it to 0–1 would reject every dimension in every spec. The definition is shared precisely because most numbers are unbounded.
Option C: Range-check in the validator (Rejected)
Leave both declarations alone and have specs validate check style literals against a per-property range table.
Rejected because: it puts the contract in validation code rather than in the schema, which is the authority consumers read. A second tool validating against schema/* would still accept opacity: 76, and the table is a copy of the contract that drifts from it.
Decision 2 — Naming
Option A: UnitIntervalStyle / UnitIntervalStyleValue, over a UnitInterval primitive (Selected)
Three names, two of them new definitions:
UnitInterval— a schema definition for the bounded number itself:type: number,minimum: 0,maximum: 1.UnitIntervalStyleValue— the schema’s style union:oneOfofUnitInterval,TokenReference,null.UnitIntervalStyle— the TypeScript type mirroring that union.
Pros:
- Derived from the mathematical unit interval, [0, 1], which names the constraint exactly and unambiguously rather than describing it.
- Follows the established
<Domain>Style↔<Domain>StyleValuepair naming, so it reads as a sibling ofColorStyle↔ColorStyleValue. - Naming the bounded number separately gives the constraint one home. Gradient centre axes, gradient stop positions and colour alpha each restate
minimum: 0, maximum: 1inline today; they can adoptUnitIntervallater without this ADR having to touch them. - Names the value’s shape rather than its two current adopters, so a third property adopting it does not make the name wrong.
Cons / Trade-offs:
- Assumes the reader is comfortable with the mathematical term. It is a deliberate trade: “unit interval” has exactly one meaning, where “normalized” or “fraction” each have several.
- The name states the range but not the unit, so the description must still say that a token reference resolves on the token’s own scale.
Option B: NormalizedStyle / FractionStyle / OpacityStyle (Rejected)
Rejected because: OpacityStyle is wrong for cornerSmoothing the moment both adopt it. FractionStyle is ambiguous — a fraction is any ratio, not specifically one bounded by 1. NormalizedStyle is the closest contender and matches the “normalised 0–1” phrasing already in the schema’s descriptions, but “normalized” is overloaded: it is also used for Unicode normalization, database normalization, and vector normalization, and it describes a process rather than naming the set. The mathematical term is the unambiguous one.
Decision
Type changes (types/)
| File | Change | Bump |
|---|---|---|
Styles.ts | Added exported type UnitIntervalStyle | MINOR |
Styles.ts | Narrowed field opacity from Style to UnitIntervalStyle | MAJOR |
Styles.ts | Narrowed field cornerSmoothing from Style to UnitIntervalStyle | MAJOR |
Example — new shape (types/Styles.ts):
# Beforeopacity: StylecornerSmoothing: Style
# AfterUnitIntervalStyle: number | TokenReference | null # new exported typeopacity: UnitIntervalStylecornerSmoothing: UnitIntervalStyleSchema changes (schema/)
| File | Change | Bump |
|---|---|---|
styles.schema.json | Added definition UnitInterval | MINOR |
styles.schema.json | Added definition UnitIntervalStyleValue | MINOR |
styles.schema.json | Repointed opacity from NumberStyleValue to UnitIntervalStyleValue | MAJOR |
styles.schema.json | Repointed cornerSmoothing from NumberStyleValue to UnitIntervalStyleValue | MAJOR |
Example — new shape (schema/styles.schema.json):
# New definitionsUnitInterval: description: >- A number on the unit interval [0, 1], inclusive at both ends. type: number minimum: 0 maximum: 1 examples: [0.5, 0, 1]
UnitIntervalStyleValue: description: >- A unit-interval number, a token reference, or null. The bound applies to a literal only — a token reference resolves on the token's own scale, which in a given library may be 0–100. examples: [0.5, 0] oneOf: - $ref: "#/definitions/UnitInterval" - $ref: "#/definitions/TokenReference" - type: "null"Notes
NumberStyleValue is left exactly as it is — it remains the type for every unbounded number in Styles, and nothing else is repointed by this ADR.
UnitInterval is defined as a primitive in its own right so the bound has one home. Three existing definitions restate minimum: 0, maximum: 1 inline — gradient centre axes, gradient stop positions, and colour alpha. This ADR does not repoint them: they are correct as they stand, and changing them is a cleanup with its own blast radius. The new definition exists so the next bounded fraction references it rather than restating it a fourth time.
The TypeScript side gains one name, not two. UnitInterval has no TS counterpart because TypeScript cannot express a numeric range — a type UnitInterval = number alias would state the bound in its name while enforcing nothing, which is the kind of decorative type the constitution’s parity rule is meant to prevent. The range lives only where it can be enforced.
The StyleKey property-name union is untouched: this change alters what values those two keys accept, not which keys exist.
Type ↔ Schema Impact
- Symmetric: Yes — and it removes an existing asymmetry rather than adding one.
- Parity check:
UnitIntervalStyleintypes/Styles.tsmirrorsUnitIntervalStyleValueinschema/styles.schema.json, branch for branch —number,TokenReference,null. Before this ADR the type admittedstring,boolean,PropBindingandConditionalthat the schema rejected; after it, the two agree. - Justified asymmetry:
UnitIntervalexists inschema/with no type counterpart. TypeScript cannot express a numeric range, so the bound is declared once in the place that enforces it. The type states the shape; the schema states the range.
Downstream Impact
| Consumer | Impact | Highlights |
|---|---|---|
specs-cli | Recompile; validation output changes | An out-of-range literal now fails validation instead of reaching the canvas. Nine source files reference these properties |
specs-from-figma | Recompile; confirm emitted values | Capture writes these properties from Figma, where both are already 0–1 — expected to be conformant, to be confirmed. Nine source files reference them |
figma-from-specs | Recompile; confirm value handling | Renders these properties onto the canvas and is where the out-of-range failure surfaced. Seven source files reference them |
react-from-specs | Recompile | Two source files reference them |
webcomponents-from-specs | Recompile | Two source files reference them |
from-specs | None | No reference to either property |
specs-plugin-2 | Recompile; confirm value handling | Twenty-six source files reference these properties; the plugin runtime is the other writer of canvas values |
Per-package depth is out of scope here and belongs to /specs.adr.analyze.
Per-package adoption analysis: specs-local-workspace/adr/121/plan.md (maintained outside this repo).
Semver Decision
Target version: 0.40.0 — the version of packages/schema on the branch this ADR merges into.
Change class: MAJOR — for CHANGELOG placement, not a version bump.
Justification: Constitution §Versioning sets MAJOR for any breaking change to a type signature or schema structure. Two things qualify. Narrowing opacity and cornerSmoothing from Style to UnitIntervalStyle removes assignability a TS consumer may have relied on. And a spec carrying opacity: 76 validates today and will not after this change — a previously accepted document becomes invalid, which is breaking regardless of the document being wrong on its face. The new type and definition are themselves additive and MINOR-class; the repointing is what sets the class for the ADR.
Consequences
- An out-of-range fraction fails at
specs validaterather than eleven seconds into a canvas write, and fails for every tool validating against the published schema rather than only inside the CLI. - The declared contract states the range, so no range table has to be maintained in validator code and none can drift from the schema.
- The two properties’ TS types stop over-promising: a string, a boolean, a prop binding or a conditional no longer typecheck where the schema would have rejected them anyway.
- A future property whose literal is a unit-interval number adopts
UnitIntervalStyle, or referencesUnitIntervaldirectly where it is not token-bindable, instead of restating the bound. - Any spec in any workspace carrying an out-of-range literal on these two properties will start failing validation and must be corrected to either a 0–1 literal or a token reference. Those specs were already failing at render, so this surfaces an existing defect rather than creating one.
NumberStyleValueremains unbounded and shared, so every dimension property is unaffected.