### Run the development demo Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Commands to install dependencies and start the local development server. ```bash npm install npm run dev # → http://localhost:5173/demo/index.html ``` -------------------------------- ### Initialize the development environment Source: https://github.com/abdofallah/musclemapjs/blob/main/CONTRIBUTING.md Commands to clone the repository, install dependencies, and start the development server or type checker. ```bash git clone https://github.com/abdofallah/MuscleMapJS.git cd MuscleMapJS npm install npm run dev # starts Vite dev server at http://localhost:5173/demo/index.html npm run typecheck # run TypeScript type check ``` -------------------------------- ### Install via Git Submodule Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Recommended installation method for Astro or Vite projects. ```bash git submodule add https://github.com/abdofallah/MuscleMapJS.git src/lib/MuscleMapJS ``` -------------------------------- ### Install via Manual Clone Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Alternative installation method by cloning the repository directly. ```bash git clone https://github.com/abdofallah/MuscleMapJS.git ``` -------------------------------- ### Initialize MuscleMapWidget Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Setup the widget container and initialize the map with configuration options and event listeners. ```html
``` -------------------------------- ### Integrate MuscleMapJS in Astro Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Example of initializing the MuscleMapWidget within an Astro component, including tooltip and history configuration. ```astro --- // src/components/MuscleSelector.astro ---
``` -------------------------------- ### Configuration and Utility Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md General configuration and lifecycle management methods. ```APIDOC ## map.setGender(gender) ## map.setSide(side) ## map.setStyle(style) ## map.redraw() ## map.destroy() ### Description Methods to update the widget configuration, refresh the view, or clean up resources. ``` -------------------------------- ### General Configuration Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Update widget settings, retrieve bounding rectangles, or destroy the instance for cleanup. ```typescript map.setGender('female'); map.setSide('back'); map.setStyle('neon'); // 'default' | 'minimal' | 'neon' | 'medical' map.setInteractive(false); map.setLongPressDuration(700); // ms map.getBoundingRect('chest'); // → { x, y, width, height } in CSS pixels map.redraw(); map.destroy(); // cleanup — removes canvas + listeners ``` -------------------------------- ### Initialize MuscleMapWidget Source: https://github.com/abdofallah/musclemapjs/blob/main/demo/index.html Sets up the MuscleMapWidget instance with specific configuration options and enables history tracking. ```typescript import { MuscleMapWidget, HeatmapLegend, MUSCLE_DISPLAY_NAMES, ALL_MUSCLES, setLocale, getMuscleName, getAllMuscleNames, } from '../src/index.ts'; const container = document.getElementById('muscle-map'); let savedData = null; let currentLocale = 'en'; let legend = null; // ─── Create widget ───────────────────────────────────────────────────── const map = new MuscleMapWidget(container, { gender: 'male', side: 'front', style: 'default', interactive: true, multiSelect: true, }); // Enable undo/redo map.enableHistory(50); // Expose globally for inline onclick handlers window.muscleMap = map; ``` -------------------------------- ### Initialize MuscleMapWidget Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Instantiate the widget by providing a container element and optional configuration settings. ```typescript const map = new MuscleMapWidget(container: HTMLElement, options?: MuscleMapOptions); ``` -------------------------------- ### View project directory structure Source: https://github.com/abdofallah/musclemapjs/blob/main/CONTRIBUTING.md Overview of the source code organization within the project. ```text src/ index.ts ← Public API exports types.ts ← All TypeScript interfaces and type unions core/ body-renderer.ts ← Canvas2D rendering engine + hit-testing body-path-data.ts ← Path data provider + ViewBox configs muscles.ts ← Muscle hierarchy, sub-groups, display names data/ male-front-paths.ts male-back-paths.ts female-front-paths.ts female-back-paths.ts heatmap/ color-scale.ts ← HeatmapColorScale class + 6 presets color-interpolation.ts styles/ body-view-style.ts ← 4 style presets utils/ color.ts ← parseColor, interpolateColor, toCSSColor widget/ muscle-map-widget.ts ← Main public widget (primary entry point) heatmap-legend.ts ← Standalone legend component i18n/ locales.ts ← 11 locale translations ``` -------------------------------- ### Configure Tooltips Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Enable or disable tooltips, with an optional callback for custom HTML rendering. ```typescript // Default: shows muscle display name map.enableTooltip(); // Custom HTML renderer map.enableTooltip((muscle, side) => { return `${muscle}
${side} side`; }); map.disableTooltip(); ``` -------------------------------- ### Initialize Heatmap Legend Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Create a visual legend for heatmap data, requiring an import from the library source. ```typescript import { HeatmapLegend } from './MuscleMapJS/src/index.ts'; const legend = new HeatmapLegend(container, { colorScale: 'workout', orientation: 'horizontal', // or 'vertical' barThickness: 16, labelMin: 'Low', labelMax: 'High', steps: 48, }); ``` -------------------------------- ### Selection Methods Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Methods to manage user selection of muscles. ```APIDOC ## map.select(muscle) ## map.selectMany(muscles) ## map.deselect(muscle) ## map.toggleSelect(muscle) ## map.clearSelection() ### Description Methods to programmatically select, deselect, or toggle the selection state of muscles. ``` -------------------------------- ### Event Handling Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Methods to subscribe to user interactions with the map. ```APIDOC ## map.on(event, handler) ## map.off(event, handler) ### Description Registers or removes event listeners for interactions like muscleClick, muscleEnter, or selectionChange. ``` -------------------------------- ### Initialize HeatmapLegend Source: https://github.com/abdofallah/musclemapjs/blob/main/demo/index.html Configures the legend element with custom color scales, orientation, and step count. ```javascript = new HeatmapLegend(legendEl, { colorScale: preset, orientation: 'horizontal', barThickness: 12, labelMin: '🔵 Low', labelMax: '🔴 High', steps: 48, }); } ``` -------------------------------- ### Highlighting Methods Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Methods to manage visual highlights on specific muscles or groups. ```APIDOC ## map.highlight(muscle, color, opacity) ## map.highlightMany(muscles, color) ## map.highlightLinearGradient(muscle, colors, x1, y1, x2, y2) ## map.highlightRadialGradient(muscle, colors) ## map.removeHighlight(muscle) ## map.clearHighlights() ### Description Methods to apply solid colors or gradients to muscles, or to remove existing highlights. ``` -------------------------------- ### MuscleMapWidget Constructor Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Initializes a new MuscleMapWidget instance within a specified DOM container. ```APIDOC ## new MuscleMapWidget(container, options) ### Description Creates and renders a new muscle map widget. ### Parameters - **container** (HTMLElement) - Required - The DOM element to render the map into. - **options** (MuscleMapOptions) - Optional - Configuration object including gender, side, style, and event handlers. ``` -------------------------------- ### Configure Visual Effects Source: https://github.com/abdofallah/musclemapjs/blob/main/demo/index.html Methods to toggle tooltips, pulse animations, and general muscle animations. ```typescript window.toggleTooltip = (on) => { if (on) { map.enableTooltip((muscle, side) => { return `${getMuscleName(muscle)}
${side} side`; }); } else { map.disableTooltip(); } }; window.togglePulse = (on) => { if (on) map.enablePulse(1.5, 0.5, 1.0); else map.disablePulse(); }; window.toggleAnimation = (on) => { if (on) map.enableAnimation(300); else map.disableAnimation(); }; ``` -------------------------------- ### Internationalization Support Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Set the locale and retrieve localized muscle names or UI strings. ```typescript import { setLocale, getMuscleName, getUIString } from './MuscleMapJS/src/index.ts'; setLocale('ar'); // Arabic getMuscleName('chest'); // → 'الصدر' getMuscleName('biceps', 'ja'); // → '上腕二頭筋' getUIString('legendLow'); // → 'منخفض' ``` -------------------------------- ### Configure Heatmaps Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Apply intensity values to muscles using either simple integer scales or detailed configuration objects. ```typescript // Integer intensity (0–4 scale) map.setIntensities({ chest: 4, biceps: 2, calves: 1 }, 'workout'); // Float intensity (0.0–1.0) with full config map.setHeatmap([ { muscle: 'chest', intensity: 0.9 }, { muscle: 'quadriceps', intensity: 0.7 }, ], { colorScale: 'thermal', // 'workout' | 'thermal' | 'medical' | 'monochrome' | ... interpolation: { type: 'easeInOut' }, threshold: 0.1, // skip muscles below this intensity gradientFill: true, // use intra-muscle gradient gradientDirection: 'topToBottom', gradientLowFactor: 0.2, }); ``` -------------------------------- ### Manage UI and State Source: https://github.com/abdofallah/musclemapjs/blob/main/demo/index.html Functions to update the DOM based on muscle selection, undo/redo state, and global configuration settings. ```typescript function updateMuscleList(muscles) { const list = document.getElementById('muscle-list'); if (muscles.length === 0) { list.innerHTML = '
Click on the body to select muscles
'; return; } list.innerHTML = muscles.map(m => `
${getMuscleName(m)} selected
` ).join(''); } function updateUndoButtons() { document.getElementById('btn-undo').disabled = !map.canUndo; document.getElementById('btn-redo').disabled = !map.canRedo; } window.setGender = (g) => { map.setGender(g); document.getElementById('btn-male').classList.toggle('active', g === 'male'); document.getElementById('btn-female').classList.toggle('active', g === 'female'); }; window.setSide = (s) => { map.setSide(s); document.getElementById('btn-front').classList.toggle('active', s === 'front'); document.getElementById('btn-back').classList.toggle('active', s === 'back'); }; window.setStyle = (s) => { map.setStyle(s); ['default', 'neon', 'medical', 'minimal'].forEach(st => { document.getElementById(`btn-style-${st}`).classList.toggle('active', st === s); }); }; window.changeLocale = (locale) => { currentLocale = locale; setLocale(locale); // Re-render muscle list with new locale updateMuscleList(map.getSelectedMuscles()); console.log(`Locale changed to: ${locale}`); }; window.handleSave = () => { const data = map.getHighlightData(); savedData = data; const output = document.getElementById('output'); output.textContent = JSON.stringify(data, null, 2); output.classList.add('visible'); }; window.handleClear = () => { map.clearHighlights(); map.clearSelection(); document.getElementById('output').classList.remove('visible'); document.getElementById('heatmap-legend').style.display = 'none'; }; window.handleRestore = () => { if (savedData) { map.setHighlightData(savedData); map.selectMany(savedData.map(d => d.muscle)); } }; window.handleUndo = () => { map.undo(); updateUndoButtons(); }; window.handleRedo = () => { map.redo(); updateUndoButtons(); }; ``` -------------------------------- ### Importing MuscleMapJS Types Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Import necessary interfaces and type unions from the library's entry point. ```typescript import type { Muscle, MuscleSide, BodySide, BodyGender, MuscleHighlight, MuscleIntensity, HeatmapConfig, StylePreset, BodyViewStyle, MuscleMapOptions, MuscleEvent, } from './MuscleMapJS/src/index.ts'; ``` -------------------------------- ### Configure Animations Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Control visual transitions and pulse effects for highlighted or selected muscles. ```typescript // Smooth cross-fade on highlight changes map.enableAnimation(300); // duration in ms map.disableAnimation(); // Pulse effect on selected muscles map.enablePulse( 1.5, // speed (cycles/sec) 0.6, // min opacity 1.0, // max opacity ); map.disablePulse(); ``` -------------------------------- ### Heatmap Methods Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Methods to visualize intensity data on the muscle map. ```APIDOC ## map.setIntensities(data, scale) ## map.setHeatmap(data, config) ### Description Applies intensity values to muscles to create a heatmap visualization using predefined color scales. ``` -------------------------------- ### Manage Muscle Highlights Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Apply solid colors, gradients, or raw highlight objects to specific muscles, and manage their removal or inspection. ```typescript // Solid color map.highlight('chest', '#ff4444', 0.9); map.highlightMany(['biceps', 'triceps'], '#00c853'); // Gradients (ported from BodyView.swift modifiers) map.highlightLinearGradient('abs', ['#ffeb3b', '#f44336'], 0, 0, 0, 1); map.highlightRadialGradient('gluteal', ['#ff9800', '#f44336']); // Raw MuscleHighlight object map.setHighlight('chest', { muscle: 'chest', fill: { type: 'color', color: 'red' }, opacity: 1 }); // Removal map.removeHighlight('chest'); map.clearHighlights(); // Inspection map.getHighlightedMuscles(); // → Muscle[] map.getHighlightData(); // → serializable array (for DB storage) map.setHighlightData(saved); // restore from DB ``` -------------------------------- ### Apply Heatmap Visualizations Source: https://github.com/abdofallah/musclemapjs/blob/main/demo/index.html Functions to render heatmap data onto the muscle map, including gradient configurations. ```typescript window.applyHeatmap = (preset) => { const sampleData = [ { muscle: 'chest', intensity: 0.9 }, { muscle: 'biceps', intensity: 0.7 }, { muscle: 'abs', intensity: 0.6 }, { muscle: 'quadriceps', intensity: 0.8 }, { muscle: 'deltoids', intensity: 0.5 }, { muscle: 'forearm', intensity: 0.3 }, { muscle: 'calves', intensity: 0.4 }, { muscle: 'trapezius', intensity: 0.55 }, { muscle: 'obliques', intensity: 0.35 }, { muscle: 'tibialis', intensity: 0.2 }, ]; map.setHeatmap(sampleData, { colorScale: preset }); map.clearSelection(); showLegend(preset); }; window.applyHeatmapGradient = () => { const sampleData = [ { muscle: 'chest', intensity: 0.9 }, { muscle: 'biceps', intensity: 0.7 }, { muscle: 'abs', intensity: 0.6 }, { muscle: 'quadriceps', intensity: 0.8 }, { muscle: 'deltoids', intensity: 0.5 }, ]; map.setHeatmap(sampleData, { colorScale: 'thermal', gradientFill: true, gradientDirection: 'topToBottom', gradientLowFactor: 0.2, }); map.clearSelection(); showLegend('thermal'); }; window.clearHeatmap = () => { map.clearHighlights(); map.clearSelection(); document.getElementById('heatmap-legend').style.display = 'none'; }; function showLegend(preset) { const legendEl = document.getElementById('heatmap-legend'); legendEl.style.display = 'block'; legendEl.innerHTML = ''; legend ``` -------------------------------- ### Manage Undo/Redo History Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Enable history tracking to allow undo and redo operations on selection states. ```typescript map.enableHistory(50); // enable with max 50 entries map.undo(); // → Muscle[] | null (restored selection) map.redo(); // → Muscle[] | null map.canUndo; // → boolean map.canRedo; // → boolean ``` -------------------------------- ### Handle Muscle Selection Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Programmatically select, deselect, or toggle muscle states and retrieve the current selection list. ```typescript map.select('biceps'); map.selectMany(['chest', 'abs', 'obliques']); map.deselect('chest'); map.toggleSelect('biceps'); map.clearSelection(); map.getSelectedMuscles(); // → Muscle[] ``` -------------------------------- ### Register Event Listeners Source: https://github.com/abdofallah/musclemapjs/blob/main/README.md Attach handlers to various interaction events such as clicks, drags, and selection changes. ```typescript map.on('muscleClick', (muscle: Muscle, side: MuscleSide) => void); map.on('muscleEnter', (muscle: Muscle, side: MuscleSide) => void); map.on('muscleLeave', () => void); map.on('selectionChange', (muscles: Muscle[]) => void); map.on('muscleLongPress', (muscle: Muscle, side: MuscleSide) => void); map.on('muscleDrag', (muscle: Muscle, side: MuscleSide) => void); map.on('muscleDragEnd', () => void); map.off('muscleClick', handler); ``` -------------------------------- ### Handle MuscleMap Events Source: https://github.com/abdofallah/musclemapjs/blob/main/demo/index.html Registers event listeners for user interactions such as selection changes, clicks, long presses, and drag events. ```typescript map.on('selectionChange', (muscles) => { updateMuscleList(muscles); updateUndoButtons(); }); map.on('muscleClick', (muscle, side) => { console.log(`Clicked: ${getMuscleName(muscle)} (${side})`); }); map.on('muscleLongPress', (muscle, side) => { console.log(`Long press: ${getMuscleName(muscle)} (${side})`); }); map.on('muscleDrag', (muscle, side) => { console.log(`Drag over: ${getMuscleName(muscle)} (${side})`); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.