Skip to content

Conversation

@mateuszJS
Copy link
Owner

@mateuszJS mateuszJS commented Oct 14, 2025

Summary by CodeRabbit

  • New Features

    • Import asset files (*.wgsl, *.svg, *.ttf) as strings.
    • Added normalizeVec2(vec) utility.
    • Exposed Point in the public API.
  • Refactor

    • Centralized and re-exported types from a unified types module.
    • Introduced global zig.* namespace for shared types.
    • Updated public typings to use zig.* and Id; onAssetSelect now receives Id.
  • Chores

    • Updated TypeScript config: ES2020 lib, stricter lib checks, adjusted type roots, and included new declaration file in build.

Copilot AI review requested due to automatic review settings October 14, 2025 13:12
@coderabbitai
Copy link

coderabbitai bot commented Oct 14, 2025

Walkthrough

Centralizes public types in src/types.ts and re-exports via src/index.ts. Introduces a global zig namespace for ambient Zig typings and updates src/logic/index.d.ts to use zig.* types. Moves asset module declarations (*.wgsl, *.svg, *.ttf) from global.d.ts to modules.d.ts. Updates many files to import types explicitly. Adjusts tsconfig settings.

Changes

Cohort / File(s) Summary
Type surface centralization
src/types.ts, src/index.ts, integration-tests/index.ts
Adds foundational types/enums in src/types.ts; src/index.ts re-exports types and updates initCreator’s onAssetSelect to use Id; integration test updates exports to include Point.
Zig ambient namespace + declarations
global.d.ts, src/logic/index.d.ts
Adds declare global zig namespace mapping to types from ./src/types; migrates public API signatures in logic d.ts to zig.* types; removes several previously exported global types.
Asset module declarations relocation
modules.d.ts, global.d.ts
Moves module declarations for *.wgsl, *.svg, *.ttf into a dedicated modules.d.ts; removes them from global.d.ts.
Type import adoption: utils
src/utils/* (getAngle.ts, getBezierPos.ts, getBezierTan.ts, getCurveLength.ts, getDefaultPoints.ts, getDistance.ts, normalizeVec2.ts, distancePointToLine.ts)
Adds imports from 'types' and annotates function signatures/params/returns without runtime changes; adds new normalizeVec2 utility.
Type import adoption: svgToShapes
src/svgToShapes/* (boundingBox.ts, collectShapesData.ts, definitions.ts, getProps.ts, parseEllipse.ts, parsePathData.ts, parseRect.ts, radialGradient.ts, utils.ts)
Adds imports of Point/Color/SdfEffect/ShapeProps from 'types' and applies annotations; no logic changes.
Type import adoption: core/render
src/WebGPU/textureCache.ts, src/fonts.ts, src/pointer.ts, src/run.ts, src/sanitizeFill.ts
Adds imports for BoundingBox, Point, SdfEffect from 'types' and updates annotations only.
Build/TS config
tsconfig.json, tsconfig.build.json
Adds ES2020 lib, adjusts typeRoots, enables lib checks, updates excludes; includes modules.d.ts in build.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant App as initCreator (TS)
  participant Logic as Logic (zig bindings)
  note over App,Logic: Signatures migrated to zig.* types

  Caller->>App: initCreator({ onAssetSelect: (assetId: Id) => void })
  App->>Logic: connectOnAssetSelectionCallback(cb: (data: zig.Id) => void)
  Logic-->>App: emit selection (id: zig.Id)
  App->>App: cast [...id] as Id
  App-->>Caller: onAssetSelect(assetId: Id)
  note right of Caller: Callback now typed with Id
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

released on @next

Poem

In burrows of types, I hop with glee,
Zig whispers “global,” TS nods with “zee.”
Paths and points line up in rhyme,
Gradients blush in compile-time.
SVGs sing from modules new—
A carrot-shaped enum joins the crew.
Thump-thump: shipped on @next, woohoo! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The pull request title “fix: expose types” indicates that something related to types is being exposed but is overly generic and misuses the “fix” prefix for what is essentially a feature or refactoring. It does not specify which types or modules are affected, nor does it convey that global Zig typings and re-exports are being introduced. As a result, the title does not provide sufficient context for someone scanning the repository history. Consider revising the title to clearly describe the primary change and its scope, for example “feat: expose global Zig typings via types.ts and modules.d.ts” to convey both the feature nature and the specific modules involved.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch expose-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR exposes types by moving type definitions from the main index file to a dedicated types file and updating import statements across the codebase. The main purpose is to fix type exposure by centralizing type definitions and ensuring they're properly accessible.

  • Moved all type definitions from src/index.ts to src/types.ts
  • Updated import statements across utility functions and modules to use the centralized types
  • Added modules.d.ts to the TypeScript build configuration for better type declaration generation

Reviewed Changes

Copilot reviewed 27 out of 32 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tsconfig.build.json Added modules.d.ts to include array and fixed typo in comment
src/types.ts Added comprehensive type definitions moved from index.ts
src/index.ts Removed type definitions and added imports/exports from types file
src/utils/*.ts Updated to import Point/PointUV types from centralized types file
src/svgToShapes/*.ts Updated to import types from centralized types file
integration-tests/index.ts Updated import to include Point type
ADRs/type of zig & exported types Added documentation about typing strategy

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/utils/normalizeVec2.ts (1)

3-9: Handle zero-length vector to prevent NaN.

If vec is {x: 0, y: 0}, length will be 0, causing division by zero on lines 6-7. This produces {x: NaN, y: NaN}, which will corrupt downstream calculations.

Apply this diff to handle the edge case:

 export default function normalizeVec2(vec: Point): Point {
   const length = Math.sqrt(vec.x * vec.x + vec.y * vec.y)
+  if (length === 0) {
+    return { x: 0, y: 0 }
+  }
   return {
     x: vec.x / length,
     y: vec.y / length,
   }
 }
🧹 Nitpick comments (3)
src/svgToShapes/parsePathData.ts (1)

1-1: Switch to type-only import for Point.

Point is only used as a type, so mark this as a type import to keep the compiled output clean and satisfy verbatimModuleSyntax/preserveValueImports configurations. Please mirror the change wherever the new 'types' entry point is pulled in purely for types.

-import { Point } from 'types'
+import type { Point } from 'types'
src/types.ts (1)

5-142: Centralized type surface looks solid. Optional refinements below.

  • Consider making Id a readonly tuple to prevent accidental mutation: type Id = readonly [number, number, number, number].
  • Consider replacing enum CreatorTool with a union type or a const object + as const for tree-shaking friendliness, unless you depend on a runtime enum.

Not blockers.

src/index.ts (1)

14-23: Use type-only imports to avoid unnecessary runtime imports.

These are type positions; switch to import type for cleaner emitted JS.

-import {
+import type {
   CreatorTool,
   Id,
   PointUV,
   SerializedInputAsset,
   SerializedOutputAsset,
   ShapeProps,
   ZigAsset,
 } from './types'
 export * from './types'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff031e1 and 28f36f7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (31)
  • ADRs/type of zig & exported types (1 hunks)
  • global.d.ts (1 hunks)
  • integration-tests/index.ts (1 hunks)
  • modules.d.ts (1 hunks)
  • src/WebGPU/textureCache.ts (1 hunks)
  • src/fonts.ts (1 hunks)
  • src/index.ts (2 hunks)
  • src/logic/index.d.ts (6 hunks)
  • src/pointer.ts (1 hunks)
  • src/run.ts (1 hunks)
  • src/sanitizeFill.ts (1 hunks)
  • src/svgToShapes/boundingBox.ts (1 hunks)
  • src/svgToShapes/collectShapesData.ts (1 hunks)
  • src/svgToShapes/definitions.ts (1 hunks)
  • src/svgToShapes/getProps.ts (1 hunks)
  • src/svgToShapes/parseEllipse.ts (1 hunks)
  • src/svgToShapes/parsePathData.ts (1 hunks)
  • src/svgToShapes/parseRect.ts (1 hunks)
  • src/svgToShapes/radialGradient.ts (1 hunks)
  • src/svgToShapes/utils.ts (1 hunks)
  • src/types.ts (1 hunks)
  • src/utils/distancePointToLine.ts (1 hunks)
  • src/utils/getAngle.ts (1 hunks)
  • src/utils/getBezierPos.ts (1 hunks)
  • src/utils/getBezierTan.ts (1 hunks)
  • src/utils/getCurveLength.ts (1 hunks)
  • src/utils/getDefaultPoints.ts (1 hunks)
  • src/utils/getDistance.ts (1 hunks)
  • src/utils/normalizeVec2.ts (1 hunks)
  • tsconfig.build.json (1 hunks)
  • tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/types.ts (2)
src/logic/index.d.ts (1)
  • Point (81-81)
src/svgToShapes/boundingBox.ts (1)
  • BoundingBox (7-32)
global.d.ts (2)
src/logic/index.d.ts (1)
  • Point (81-81)
src/types.ts (6)
  • Point (5-8)
  • PointUV (10-15)
  • BoundingBox (17-22)
  • Id (25-25)
  • ShapeProps (51-55)
  • ZigAsset (142-142)
src/index.ts (1)
src/types.ts (1)
  • Id (25-25)
src/logic/index.d.ts (2)
src/types.ts (6)
  • PointUV (10-15)
  • Point (5-8)
  • ShapeProps (51-55)
  • ZigAsset (142-142)
  • Id (25-25)
  • BoundingBox (17-22)
src/svgToShapes/boundingBox.ts (1)
  • BoundingBox (7-32)
🔇 Additional comments (23)
src/svgToShapes/utils.ts (1)

3-3: LGTM!

Type imports correctly added to support the centralized type surface.

src/svgToShapes/parseEllipse.ts (1)

1-2: LGTM!

Type import correctly added for Point usage in function signature and curve definitions.

src/utils/getBezierTan.ts (1)

1-1: LGTM!

Type import correctly added to support Point usage in function signature.

src/WebGPU/textureCache.ts (1)

6-6: LGTM!

Type import correctly added for BoundingBox parameter annotation in startCache.

src/utils/getDefaultPoints.ts (1)

1-1: LGTM!

Type import correctly added for PointUV return type annotation.

src/utils/getCurveLength.ts (1)

1-1: LGTM!

Type import correctly added for Point parameter annotations in getCurveLength.

src/svgToShapes/getProps.ts (1)

7-7: LGTM!

Type import correctly added for Color usage in gradient stop definitions.

src/run.ts (1)

26-26: LGTM!

Type imports correctly added for BoundingBox and Point usage in cache callbacks and pick tracking.

integration-tests/index.ts (1)

1-1: LGTM!

The explicit import of Point aligns with the centralized type surface and improves type safety.

tsconfig.build.json (1)

10-10: LGTM!

Adding modules.d.ts to the include array ensures the new ambient module declarations for asset types are included in the build output.

src/utils/getDistance.ts (1)

1-5: LGTM!

The type annotations improve type safety without changing the function's behavior.

src/utils/getBezierPos.ts (1)

1-21: LGTM!

The type annotations strengthen the function signature without altering its Bézier curve calculation logic.

ADRs/type of zig & exported types (1)

1-5: LGTM!

The ADR clearly documents the rationale for using declare global blocks to expose types for Zig ambient definitions while maintaining a centralized type surface.

src/utils/getAngle.ts (1)

1-5: LGTM!

The type annotations improve type safety without changing the angle calculation logic.

global.d.ts (1)

3-15: Global zig namespace augmentation is fine; ensure inclusion order.

Make sure global.d.ts is part of the TypeScript program (dev and build) so zig.* is available to src/logic/index.d.ts. If not already, add global.d.ts to the include/files list.

You can confirm with the same script shared in the modules.d.ts comment.

src/index.ts (2)

43-43: API change: onAssetSelect now expects Id (tuple) instead of a number.

This is likely a breaking change for consumers. Please document it and provide a brief migration note in the changelog/README.


177-177: Good: clone and cast zig.Id to Id before emitting.

The spread prevents accidental aliasing with Zig-managed memory and matches the Id tuple shape.

src/logic/index.d.ts (6)

23-37: Aligning addImage/addShape/resetAssets to zig. types looks correct.*

The shift to zig.Point/PointUV/ShapeProps/ZigAsset is consistent with global augmentation.

Please ensure global.d.ts is included in the program so zig.* resolves for consumers.


38-39: Switched selection/update IDs to zig.Id — good.

Matches the new public Id tuple.


81-84: Constructors returning zig. types are consistent.*

Point and PtrI32 signatures align with the new namespaces.


127-129: Update callbacks now emit zig.ZigAsset[] and zig.Id — consistent.

Matches the rest of the API.


135-139: Cache/select updates use zig.BoundingBox and zig.PointUV/ShapeProps — consistent.

No issues.


160-167: Setters updated to zig. types — consistent.*

setSelectedAssetProps and setSelectedAssetBounds signatures look good.

@mateuszJS mateuszJS merged commit 457fad0 into next Oct 15, 2025
6 checks passed
@github-actions
Copy link

🎉 This PR is included in version 0.1.0-next.27 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants