Commit graph

259 commits

Author SHA1 Message Date
4fb2b40cba fix: Add starting lock stitches to PEN encoder to match C# behavior
The encoder now adds 8 lock stitches at the very beginning of every pattern,
matching the behavior of the original C# PesxToPen.cs code (Nuihajime_TomeDataPlus
is called when counter <= 2).

Key changes:
- Find first non-MOVE stitch for lock stitch placement
- Add 8 starting lock stitches before main encoding loop
- Calculate forward-looking direction for optimal knot hiding
- Update all 30 tests to account for starting lock stitches

Also added tests to verify:
- DATA_END flag is automatically added to last stitch
- Starting lock stitches are correctly placed at pattern start

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 13:23:20 +01:00
Jan-Henrik Bruhn
e7fb02a163
Merge pull request #10 from jhbruhn/feature/add-pen-conversion-tests
Feature: add PEN conversion tests, refactoring around PEN conversion
2025-12-14 12:34:57 +01:00
d35228e40b feature: Add tests for automatic DATA_END flag insertion
Added tests to verify the encoder correctly handles pattern termination:

- Test that DATA_END flag is added to last stitch even without END flag
- Test that DATA_END flag is added when input has explicit END flag

This ensures patterns are always properly terminated in PEN format,
regardless of whether the input stitches have an END marker.

All 29 tests passing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 12:32:05 +01:00
ba380723c0 feature: Refactor PEN parser to decoder with coherent types
Renamed and restructured PEN parsing to match encoder pattern:

Changes:
- Renamed pen/parser.ts → pen/decoder.ts (consistent with encoder.ts)
- Created pen/types.ts for PEN-specific type definitions
- Moved types out of machine.ts (they're format-specific, not machine-specific)
- Unified decoder with encoder test helpers (encoder.test.ts now uses decoder)

New structure:
- decodePenStitch() - decode single 4-byte stitch
- decodeAllPenStitches() - decode all stitches from bytes
- decodePenData() - full decode with color blocks and bounds
- getStitchColor() - helper to get color for a stitch index

Type definitions:
- DecodedPenStitch - individual stitch with coordinates and flags
- PenColorBlock - color block (stitch range for one thread)
- DecodedPenData - complete decoded pattern data

Backward compatibility:
- Added compatibility aliases (isJump, flags, startStitch, endStitch)
- Maintains API compatibility with existing UI code

Also added dist-electron to eslint ignore list.

All tests passing (27/27), build successful, lint clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 12:27:24 +01:00
11b710eb17 feature: Reorganize code into formats folder structure
Moved embroidery format-related code from utils to new formats folder:

Structure:
- src/formats/pen/ - PEN format encoding and parsing
  - encoder.ts (was utils/penEncoder.ts)
  - encoder.test.ts (was utils/penEncoder.test.ts)
  - parser.ts (was utils/penParser.ts)
  - PEN constants moved inline to encoder.ts

- src/formats/import/ - Pattern import/conversion (currently PES)
  - worker.ts (was workers/patternConverter.worker.ts)
  - client.ts (was utils/patternConverterClient.ts)
  - pesImporter.ts (was utils/pystitchConverter.ts)
  - pyodideLoader.ts (was utils/pyodideLoader.ts)
  - constants.ts (PyStitch/pyembroidery constants)

Benefits:
- Better separation of concerns
- PEN encoder is co-located with PEN parser
- Import logic is in one place and extensible for other formats
- Removed utils/embroideryConstants.ts - split into appropriate locations
- Updated all 18 import references across the codebase

All tests passing, build successful.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 12:19:21 +01:00
b09f97afef feature: Add test step to CI workflow
- Added npm run test:run to GitHub Actions build workflow
- Updated workflow name to reflect testing is included
- Tests now run between lint and build steps

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 12:02:32 +01:00
6699fcf8e7 feature: Add detailed sequence verification tests for PEN encoding
Enhanced penEncoder test suite with byte-level sequence verification:
- Added helper functions to decode PEN bytes for detailed assertions
- Replaced length-only tests with precise operation order verification
- Added tests for color change sequences (same position and with jump)
- Added test for color change followed by explicit JUMP command
- Added test for long jump sequences with lock stitches
- Verified exact placement of lock stitches, cuts, jumps, and color markers

All 27 tests passing with comprehensive coverage of PEN format encoding.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 11:59:46 +01:00
584f795330 feature: Add comprehensive tests for PEN encoding logic
- Extract PEN encoding logic into separate testable module (penEncoder.ts)
- Implement 24 comprehensive tests covering:
  - Position encoding and coordinate shifting
  - Lock stitch direction calculation (forward/backward)
  - Lock stitch generation with rotation
  - Full PEN encoding with color changes, jumps, and bounds
  - Edge cases (empty arrays, single stitches, TRIM flags)

- Setup vitest for testing
- Refactor pattern converter worker to use extracted penEncoder module
- Fix bounds calculation to include non-MOVE stitches (not just STITCH)
- Remove duplicate function definitions from worker
- Add test scripts: npm run test, npm run test:ui, npm run test:run

All tests passing (24/24) and build successful.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 11:44:48 +01:00
Jan-Henrik Bruhn
5ededbb166
Merge pull request #9 from jhbruhn/feature/add-version-to-title
feature: Add application version to page title
2025-12-13 23:49:10 +01:00
ded3423a19 feature: Add application version to page title
- Read version from package.json at build time using Vite define
- Create global __APP_VERSION__ constant injected by Vite
- Update document title in App component to include version (e.g., "Respira v0.0.0")
- Works reliably in both web and Electron builds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 23:48:05 +01:00
Jan-Henrik Bruhn
a1b009065c
Merge pull request #8 from jhbruhn/fix/pattern-rendering-and-coordinate-bugs
Fix: pattern rendering, coordinate bugs, rotated lock stitches, fixed color changes
2025-12-13 23:40:55 +01:00
abf7b9a67f fix: Resolve TypeScript build errors in PatternCanvas and imports
- Fix PenData import to use correct source (types/machine instead of penParser)
- Add explicit return type annotations for map callbacks in PatternCanvas
- Add parentheses around arrow function parameters to satisfy linter

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 23:38:13 +01:00
8c3e177ea6 fix: Update color change lock stitch direction to match C# Loop C
Color change finish lock stitches now look FORWARD (Loop C) instead of
backward, aligning the knot with the stop event data for correct tension
when the machine halts for thread color changes.

Lock stitch direction breakdown:
- Loop A (Jump/Entry): Look forward - hides knot under upcoming stitches
- Loop B (End/Cut): Look backward - hides knot inside previous stitches
- Loop C (Color Change): Look forward - aligns with stop event data

Added detailed comments documenting which loop corresponds to each
lock stitch location in the code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 23:35:23 +01:00
eb774dcb30 fix: Resolve linter issues in pattern converter and hooks
- Change let to const for variables that are never reassigned
- Fix React Hook dependency array warnings in useBrotherMachine
- Remove unused refreshPatternInfo dependency from uploadPattern
- Add missing refreshPatternInfo dependency to startMaskTrace

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 23:30:56 +01:00
8a32d5184e fix: Implement rotated lock stitches and improve PEN format handling
- Add lock stitch rotation based on movement direction (matches C# PesxToPen.cs)
- Calculate direction by accumulating vectors up to 5 stitches or 8.0 units
- Scale direction vectors from magnitude 8.0 down to 0.4 for proper lock stitch size
- Generate 8 lock stitches (not 4) alternating between +dir and -dir
- Remove PyStitch duplicate position stitches during color changes
- Add long jump detection with automatic lock stitches and cut commands
- Improve color change sequence: finish locks, cut, jump, COLOR_END, start locks
- Parse PEN data to get actual stitches for rendering (fixes jump stitch colors)
- Add encodeStitchPosition() helper function for coordinate encoding
- Improve pattern info refresh timing after mask trace
- Add detailed logging for PEN encoding and pattern info responses

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 23:25:48 +01:00
0bd037b98a fix: Resolve pattern rendering and coordinate handling bugs
This commit addresses multiple critical issues in pattern rendering and coordinate handling:

1. Fixed Y-axis offset accumulation in penParser.ts
   - Corrected sign extension logic for 16-bit signed coordinates
   - Changed to interpret full 16-bit value as signed before shifting
   - Prevents coordinate drift and offset accumulation

2. Fixed color assignment for tack stitches in patternConverter.worker.ts
   - Added detection for small finishing stitches after COLOR_CHANGE commands
   - Assigns tack stitches to correct (previous) color instead of new color
   - Uses conservative pattern matching (< 1.0 unit, followed by JUMP)

3. Made jump stitches visible in pattern preview (KonvaComponents.tsx)
   - Render jump stitches in thread color instead of gray
   - Use dashed pattern [8, 4] to distinguish from regular stitches
   - Set appropriate opacity (0.8 completed, 0.5 not completed)
   - Fixed critical bug: include previous position in jump groups to create proper line segments

4. Updated konvaRenderers.ts for consistency
   - Applied same jump stitch rendering logic
   - Ensures consistent behavior across rendering methods

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 18:37:30 +01:00
Jan-Henrik Bruhn
8c0b893599
Merge pull request #7 from jhbruhn/delete-release-artifacts-before-upload
feature: Streamline build pipeline to only run lint and build checks
2025-12-13 14:16:37 +01:00
Jan-Henrik Bruhn
6293aebc46 feature: Streamline build pipeline to only run lint and build checks
Remove expensive cross-platform Electron packaging from the build pipeline
since it duplicates work done by the release pipeline. The build pipeline
now focuses on quick quality checks (linting + TypeScript compilation) for
every PR and main branch push.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 14:15:07 +01:00
Jan-Henrik Bruhn
d3655c4565
Merge pull request #6 from jhbruhn/delete-release-artifacts-before-upload
fix: Delete release artifacts before upload to prevent duplicates
2025-12-13 14:10:02 +01:00
Jan-Henrik Bruhn
6e7f4fb212 fix: Delete release artifacts before upload to prevent duplicates
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 14:07:41 +01:00
Jan-Henrik Bruhn
77efb8e9b9
Merge pull request #5 from jhbruhn/center-button
feature: Add center pattern button to canvas controls
2025-12-13 13:57:29 +01:00
Jan-Henrik Bruhn
ca3d18fb2c feature: Add center pattern button to canvas controls
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 13:54:04 +01:00
Jan-Henrik Bruhn
7b5cf26428
Merge pull request #4 from jhbruhn/conversion-worker
feature: Implement Web Worker-based pattern conversion with progress tracking
2025-12-13 13:36:38 +01:00
Jan-Henrik Bruhn
0dfc8b731b feature: Implement Web Worker-based pattern conversion with progress tracking
Move Pyodide/PyStitch pattern conversion to a dedicated Web Worker for
non-blocking UI performance. Pyodide now loads in the background on app
startup with real-time progress indicator showing download and initialization
status.

Key changes:
- Create patternConverter.worker.ts with full PES to PEN conversion logic
- Add patternConverterClient.ts singleton for worker management
- Implement progress tracking (0-100%) with step descriptions
- Add inline progress bar in FileUpload component with contextual messaging
- Configure COEP headers for Electron to support Web Workers
- Pass dynamic asset URLs to worker for file:// protocol support
- Update UIStore with progress state management
- Simplify pystitchConverter.ts to delegate to worker client

Benefits:
- Truly non-blocking UI (heavy Python/WASM runs off main thread)
- Real progress feedback during 15MB Pyodide download
- Works in both browser and Electron (dev and production)
- Faster app startup perception with background loading
- Better UX with "waiting" state if user clicks before ready

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 13:34:13 +01:00
Jan-Henrik Bruhn
077c7d0bf5 Add enhancement label to minor 2025-12-12 21:48:27 +01:00
Jan-Henrik Bruhn
2eb78329df
Merge pull request #3 from jhbruhn/zustand
Use Zustand
2025-12-12 21:47:37 +01:00
Jan-Henrik Bruhn
fe2e68a457 feature: Update WorkflowStepper to use Zustand stores directly
Complete the component refactoring by updating WorkflowStepper to
consume stores directly instead of receiving props.

Changes:
- Updated WorkflowStepper to use useMachineStore and usePatternStore
- Removed 7 props that were being passed from App.tsx
- Added hasError import to WorkflowStepper
- Removed unused hasError import from App.tsx

Now all major components use Zustand stores directly:
- FileUpload: 0 props (was 14)
- ProgressMonitor: 0 props (was 9)
- PatternCanvas: 0 props (was 7)
- PatternSummaryCard: 0 props (was 5)
- WorkflowStepper: 0 props (was 7)

Total props eliminated: 42

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 21:43:45 +01:00
Jan-Henrik Bruhn
c22216792a feature: Update components to use Zustand stores directly
Refactor all child components to consume stores directly instead of
receiving props from App.tsx. This eliminates prop drilling and
simplifies the component tree.

Components updated:
- FileUpload: Now uses useMachineStore, usePatternStore, and useUIStore
  directly instead of receiving 14 props
- ProgressMonitor: Now uses useMachineStore and usePatternStore instead
  of receiving 9 props
- PatternCanvas: Now uses useMachineStore and usePatternStore instead of
  receiving 7 props
- PatternSummaryCard: Now uses useMachineStore and usePatternStore
  instead of receiving 5 props

Changes to App.tsx:
- Removed all component props that are now accessed via stores
- Removed unused callbacks: handlePatternLoaded, handlePatternOffsetChange,
  handleUpload, handleDeletePattern
- Removed unused imports: PesPatternData, canDeletePattern, useCallback
- Simplified component tree with zero-prop component calls

Benefits:
- Eliminated prop drilling across 37 props total
- Components can access exactly what they need from stores
- Cleaner, more maintainable component interfaces
- Better separation of concerns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 21:40:24 +01:00
Jan-Henrik Bruhn
e015c587bd feature: Implement Zustand state management
- Add zustand dependency for modern state management
- Create three separate stores for better code organization:
  - useMachineStore: Machine connection, status, and operations
  - usePatternStore: Pattern data, offset, and upload state
  - useUIStore: Pyodide and UI-specific state
- Migrate App.tsx from useBrotherMachine hook to Zustand stores
- Use useShallow for optimized multi-value selections
- Implement dynamic polling intervals based on machine state
- Add ESLint ignore for .vite build directory

Benefits:
- Better separation of concerns with logical store divisions
- Improved performance through selector-based subscriptions
- Cleaner code replacing 445-line hook with maintainable stores
- Full TypeScript support with proper typing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 21:28:52 +01:00
Jan-Henrik Bruhn
b7d64887cb
Merge pull request #2 from jhbruhn/update-node
feature: use proper node version for used electron version
2025-12-12 21:01:51 +01:00
Jan-Henrik Bruhn
e48879d8f9
Merge pull request #1 from jhbruhn/show-version
feature: Display version in Electron window title
2025-12-12 20:59:14 +01:00
Jan-Henrik Bruhn
7ca4a52c85 feature: use proper node version for used electron version 2025-12-12 20:58:48 +01:00
Jan-Henrik Bruhn
ae13001f25 feature: Display version in Electron window title
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 20:50:29 +01:00
Jan-Henrik Bruhn
b2fa76d0dd feature: newer release-drafter version 2025-12-12 20:33:06 +01:00
Jan-Henrik Bruhn
34c641abc7 feature: Add autolabeler configuration and commit guidelines
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 20:31:44 +01:00
Jan-Henrik Bruhn
2d38451629
Increase minimum height of main window to 800 2025-12-12 11:54:58 +01:00
Jan-Henrik Bruhn
821f41d69a
Adjust minimum window size for better layout 2025-12-12 11:52:41 +01:00
Jan-Henrik Bruhn
3516b609f6 Fix ESLint configuration and resolve all linting issues
- Rename eslint.config.js to eslint.config.mjs to support ES modules
- Remove unused parameters from interface implementations
- Fix refs access during render in WorkflowStepper by removing redundant check
- Wrap colorBlocks computation in useMemo to fix exhaustive-deps warning

All linting errors and warnings are now resolved.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 14:11:35 +01:00
Jan-Henrik Bruhn
75ec5c49a9 Add checkout step to publish-to-pages job
The gh CLI needs to be run in a git repository to download release
assets. Add checkout step before downloading release assets.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 13:57:28 +01:00
Jan-Henrik Bruhn
5ef58495bb Fix release asset upload by checking out repository
The gh CLI needs to be run in a git repository to determine the target
repo for uploading release assets. Add checkout step to the
upload-to-release job.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 13:47:31 +01:00
Jan-Henrik Bruhn
0e57ade95f Separate GitHub Pages publishing to only run on release publish
Move GitHub Pages deployment to a separate workflow that triggers only
when a release is published, not when drafts are created or updated.
The new workflow downloads release assets directly from the published
release to deploy alongside the web app.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 13:42:17 +01:00
Jan-Henrik Bruhn
675bb2a6cc Remove readme, for now 2025-12-11 13:40:24 +01:00
Jan-Henrik Bruhn
3d57853928 Add update electron app handler 2025-12-11 13:33:47 +01:00
Jan-Henrik Bruhn
7d7d17f918 Build web app with correct base path for GitHub Pages
Set Vite base path to /respira/ when building for GitHub Pages
so assets load correctly from the repository subdirectory.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 13:30:11 +01:00
Jan-Henrik Bruhn
3760f05c29 Add web app build and deploy to GitHub Pages root
- Add build-web job that builds the web app
- Publish web app to GitHub Pages root directory
- Keep auto-update files in /update/ subdirectory
- Web app accessible at https://jhbruhn.github.io/respira/
- Auto-update files at /update/win32/x64/ and /update/darwin/arm64/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 13:24:17 +01:00
Jan-Henrik Bruhn
e28761f127 Fix auto-update structure and macOS manifest URL
- Organize files in correct directory structure for auto-updater
- Windows files → update/win32/x64/
- macOS files → update/darwin/arm64/ (ZIP + RELEASES.json only)
- Fix macOS update manifest URL from x64 to arm64
- Exclude Linux packages and macOS DMG (not used for auto-updates)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 13:22:38 +01:00
Jan-Henrik Bruhn
6a53f86aea Add GitHub Pages deployment and consolidate release uploads
- Upload build outputs as workflow artifacts (windows/macos/linux)
- Add upload-to-release job that consolidates all platform uploads
- Add publish-to-pages job that deploys to GitHub Pages
- Add required permissions for Pages deployment

Build artifacts are now available in two places:
- GitHub Release for manual downloads
- GitHub Pages /update/ for auto-update systems

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 13:06:43 +01:00
Jan-Henrik Bruhn
a60f9c801f make build include releases.json for macos 2025-12-11 12:54:48 +01:00
Jan-Henrik Bruhn
8026a8977d Include RELEASES.json in macOS build assets upload
Add RELEASES.json to the release artifacts for macOS builds,
which is needed for auto-update functionality.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 12:50:38 +01:00
Jan-Henrik Bruhn
4a8127e5fb Increase left column width from 400px to 480px
Provides more breathing room for controls and progress monitor
in the left column on wide screens.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 12:44:33 +01:00