Skip to content

fix(element): correct and clarify ElementComponent JSDoc and types#8936

Merged
willeastcott merged 7 commits into
mainfrom
fix/element-component-jsdoc
Jun 21, 2026
Merged

fix(element): correct and clarify ElementComponent JSDoc and types#8936
willeastcott merged 7 commits into
mainfrom
fix/element-component-jsdoc

Conversation

@willeastcott

@willeastcott willeastcott commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Description

A full audit of the ElementComponent getter/setters against their actual implementations, correcting the documentation and types that had drifted. It started from shadowOffset (typed number but actually a Vec2) and grew to cover the whole accessor surface.

Type / behavior fixes (these change the generated .d.ts):

  • shadowOffsetnumberVec2
  • maxLines getter — documented as "returns null for unlimited"; it actually returns -1
  • pixelsPerUnitnumbernumber | null (null = use the sprite's own value)
  • fontAsset / textureAsset / materialAsset / spriteAssetnumberAsset | number | null, annotated on both getter and setter (the type generator emits one getter-driven type per accessor, so a setter-only union was being dropped)
  • rtlReorder — referenced the wrong registration function (registerUnicodeConverter); corrected to registerRtlReorder
  • removed the lines setter — it delegated to a non-existent TextElement setter and threw on assignment; lines is now a documented read-only getter

Doc clarifications (no type change):

  • semantics/units/ranges for shadowOffset (range, sign, why [0, 0] shows nothing), spacing (it's a multiplier, not a distance), outlineThickness (0–1), fontSize / lineHeight (units), and color (alpha is ignored — use opacity)
  • default values for the numeric text properties: fontSize (32), lineHeight (32), spacing (1), minFontSize (8), maxFontSize (32), outlineThickness (0)
  • reworded Only works for {@link ELEMENTTYPE_X} types.… elements. throughout (a single type constant reads oddly as plural)

Note: the app.systems.element.registerRtlReorder / registerUnicodeConverter references are left as inline code rather than {@link}s. These methods will be reworked into get/set accessors (and documented) in a follow-up PR, so this PR deliberately doesn't surface them in the public API.

Verified with eslint, npm run build:types, npm run test:types, and npm run docs (no new unresolved-link warnings).

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

🤖 Generated with Claude Code

Audit of every ElementComponent getter/setter against its implementation:

- shadowOffset was typed `number`; it is a `Vec2`
- maxLines getter returns -1 (not null) when there is no limit
- pixelsPerUnit is nullable (null = use the sprite's own value)
- fontAsset/textureAsset/materialAsset/spriteAsset setters accept an Asset or id
- rtlReorder referenced registerUnicodeConverter instead of registerRtlReorder
- removed the broken `lines` setter (TextElement has no setter, so it threw) and
  documented the read-only getter
- clarified units/ranges for spacing, outlineThickness, fontSize, lineHeight and
  the alpha behavior of color

Verified with eslint, build:types and test:types.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown

Public API report

This PR changes the public API surface (+13 / −12), per the docs' rules (@ignore / @Private / undocumented are excluded).

Show API diff
-ElementComponent.get fontAsset(): number
+ElementComponent.get fontAsset(): number | Asset | null
+ElementComponent.get lines(): string[]
-ElementComponent.get materialAsset(): number
+ElementComponent.get materialAsset(): number | Asset | null
-ElementComponent.get pixelsPerUnit(): number
+ElementComponent.get pixelsPerUnit(): number | null
-ElementComponent.get shadowOffset(): number
+ElementComponent.get shadowOffset(): Vec2
-ElementComponent.get spriteAsset(): number
+ElementComponent.get spriteAsset(): number | Asset | null
-ElementComponent.get textureAsset(): number
+ElementComponent.get textureAsset(): number | Asset | null
-ElementComponent.set fontAsset(arg: number)
+ElementComponent.set fontAsset(arg: number | Asset | null)
-ElementComponent.set materialAsset(arg: number)
+ElementComponent.set materialAsset(arg: number | Asset | null)
-ElementComponent.set pixelsPerUnit(arg: number)
+ElementComponent.set pixelsPerUnit(arg: number | null)
-ElementComponent.set shadowOffset(arg: number)
+ElementComponent.set shadowOffset(arg: Vec2)
-ElementComponent.set spriteAsset(arg: number)
+ElementComponent.set spriteAsset(arg: number | Asset | null)
-ElementComponent.set textureAsset(arg: number)
+ElementComponent.set textureAsset(arg: number | Asset | null)

Informational only — this never fails the build.

@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2287.8 KB (−0.0 KB, −0.00%) 586.7 KB (−0.0 KB, −0.00%) 455.6 KB (−0.2 KB, −0.05%)
playcanvas.min.mjs 2285.2 KB (−0.0 KB, −0.00%) 585.8 KB (−0.0 KB, −0.00%) 455.7 KB (+0.1 KB, +0.01%)

@willeastcott willeastcott added docs Documentation related enhancement Request for a new feature labels Jun 21, 2026
The type generator produces a single type per accessor, driven by the getter, so
the `Asset | number` annotations placed on only the setters were dropped and the
generated .d.ts still showed `number`. Annotate both the getter and setter (and
include null, matching ModelComponent#asset) for fontAsset, textureAsset,
materialAsset and spriteAsset so the Asset form actually appears in the public
types.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add the default to fontSize (32), lineHeight (32), spacing (1), minFontSize (8),
maxFontSize (32) and outlineThickness (0), which previously documented their
range/units but not their default.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
"Only works for {@link ELEMENTTYPE_TEXT} types." renders with a single type
constant, so the plural "types" reads oddly. Reword to "... elements." across
the property docs, and fix the related "types who/which" phrasing to
"elements that ...".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the inline `app.systems.element.registerRtlReorder` and
`registerUnicodeConverter` code references with {@link} cross-references. Both
methods were undocumented, so with excludeNotDocumented they were absent from the
generated docs and the links would not resolve; added JSDoc to each (including
the callback signatures) so the links point at real, documented members.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@willeastcott willeastcott changed the title fix(element): correct ElementComponent property types and JSDoc fix(element): correct and clarify ElementComponent JSDoc and types Jun 21, 2026
The unicodeConverter/rtlReorder register methods will be reworked into get/set
accessors in a follow-up PR. Revert the proactively-added registerUnicodeConverter
{@link} (and the supporting JSDoc on that method) back to inline code so that
change is handled holistically there. The registerRtlReorder link stays, as it
also corrects the rtlReorder doc's previously-wrong function reference.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Unlink the registerRtlReorder reference and drop the JSDoc added to it, mirroring
the earlier registerUnicodeConverter revert. With excludeNotDocumented, adding
JSDoc would surface these methods in the API docs; since they will be reworked
into get/set accessors in a follow-up PR, both are left as inline-code references
here and system.js is unchanged. The rtlReorder doc keeps the corrected function
name (registerRtlReorder, not registerUnicodeConverter).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@willeastcott willeastcott merged commit d3725eb into main Jun 21, 2026
10 checks passed
@willeastcott willeastcott deleted the fix/element-component-jsdoc branch June 21, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation related enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant