# Patternizer — designer needle requirements

React/TypeScript replacement for the old Needle size Min/Max box in Patternizer. The preview reconstructs the supplied editing-layout context: Craft and Units & Gauge above a full-width Needles & Hooks section on the left half; Categorization on the right half; Measurements and Yarn used below. This is a designer-only component and preview; it contains no crafter shopping flow.

## Run

Requires Node.js 20.19+ and npm.

```sh
npm ci
npm run dev
npm run typecheck
npm test
npm run build
```

`dist/` is the standalone preview. All app rendering is React/TSX; Vite’s HTML is only the app entry point. Relative build assets support hosting in `/patternizer-needle-requirements/`.

## Integrate

```tsx
import { NeedleRequirements, normalizeRequirements, validateRequirement } from './needle-requirements';
import type { NeedleRequirement } from './needle-requirements';
import './needle-requirements/needle-requirements.css';

// As a separate section spanning Craft + Units & Gauge on the left half:
<NeedleRequirements
  craft={craft} // 'knitting' | 'crochet'
  value={needleRequirements}
  onChange={setNeedleRequirements}
  showErrors={submitted}
/>

// Before your existing pattern save:
const invalid = needleRequirements.some(item =>
  Object.keys(validateRequirement(item, craft)).length > 0
);
if (!invalid) {
  await savePattern({ needleRequirements: normalizeRequirements(needleRequirements) });
}
```

Copy `index.ts`, `NeedleRequirements.tsx`, `model.ts` and `needle-requirements.css` into your existing React application. The parent owns the array and persistence. The component inherits the host font, uses a peer-level Needles & Hooks heading and scopes all CSS under `.nr-panel`; the screenshot context is separate in `PatternizerPreview.tsx` and `preview.css` and does not need to ship in Patternizer. Supply unique stable IDs for imported entries; added entries use browser UUIDs.

## Data and behavior

One row is one required tool, with `type`, `diameterMm`, `lengthCm`, optional `material`, and a Circular-only `construction` choice. Null diameter/length means unfinished input. Missing material means any material is suitable. The list supports multiple rows and removal of all rows; require at least one at your pattern publishing boundary if needed. There are no purpose labels, notes, supplier recommendations, brands, prices, product descriptions or EAN fields. Existing circular drafts without construction are displayed and normalized as `either`; non-circular values omit construction. Changing type clears an inapplicable construction value.

The displayed Single point option retains the stable `straight` type ID for compatibility with existing drafts. Other tool types also retain their existing IDs. Circular length is total assembled tip-to-tip length. Straight and double-pointed needles use needle length; Tunisian hooks use working length. Ordinary crochet hooks have no length field and serialize a null length. All five tool types remain available, including finishing hooks in knitting patterns. Craft sets the default for new entries and never discards or converts existing choices.

Diameters remain in mm and tool lengths in cm for catalogue matching, regardless of the garment measurement units selected in the surrounding Patternizer. The separate preview gauge basis changes between 10 cm and 4 in; designers enter the stitch/row counts for that basis. No automatic gauge-count conversion is performed.

Catalogue matching is a separate service responsibility: map these specifications to eligible variants, identified by EAN. EAN remains the catalogue/store-offer source of truth; designers do not enter or choose it here. Circular requirements can specify `construction`: `either` (default), `fixed`, or `interchangeable`. Catalogue matching must accept both fixed and interchangeable circular products for `either`, and restrict results for the other two values. Component compatibility and included tips/cables remain catalogue product data.

Do not automatically interpret an existing Min/Max range as every required diameter. Have the designer confirm discrete tool entries during migration. The preview’s 3 mm and 3.5 mm entries are illustrative.

## Preview persistence and limits

Save preview validates tool fields and stores this demo on the current device using localStorage. Surrounding craft, gauge and categorization controls illustrate placement; Measurements and Yarn used are context headings. This package does not alter the production Patternizer, upload PDFs, call a backend or publish a pattern. Connect the controlled component to your existing form and save API. The earlier upload/start preview is preserved separately.

## Validation

Type checking, production build and focused model tests cover positive sizes, required lengths, ordinary/Tunisian hook distinctions, normalization and mixed-tool patterns and craft-specific new-entry defaults. Browser checks cover add/remove, form validation, preview saving and responsive layout.
