react-matchings 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,9 +7,13 @@ Default styles are included automatically when the component is imported. Consum
7
7
  ## Features
8
8
 
9
9
  - Drag-to-connect matching interaction
10
+ - Pointer support for mouse, touch, and pen input
11
+ - Automatic scrolling while dragging near a scroll container edge
12
+ - One-to-one answers by default, with optional answer reuse
10
13
  - Controlled change callback for saving or validating answers
11
14
  - Custom classes for the container, question buttons, and answer buttons
12
15
  - Configurable connector line color, endpoint color, radius, and offset
16
+ - Per-match styles for validation feedback
13
17
  - Disabled state for submitted or read-only flows
14
18
  - TypeScript definitions included
15
19
 
@@ -70,6 +74,9 @@ function App() {
70
74
  | `circleRadius` | `number` | `8` | Radius of connector endpoints in pixels. |
71
75
  | `offset` | `number` | `10` | Distance from button edges to connector endpoints in pixels. |
72
76
  | `disabled` | `boolean` | `false` | Prevents users from creating or removing matches. |
77
+ | `allowAnswerReuse` | `boolean` | `false` | Allows multiple questions to connect to the same answer. |
78
+ | `autoScroll` | `boolean \| TAutoScrollOptions` | `true` | Scrolls the nearest overflow container while dragging near an edge. |
79
+ | `getMatchStyles` | `(match: TMatch) => TMatchStyles \| undefined` | `undefined` | Returns connector and item styles for an established match. |
73
80
 
74
81
  ## Types
75
82
 
@@ -78,6 +85,18 @@ type TMatch = {
78
85
  questionId: number;
79
86
  answerId: number;
80
87
  };
88
+
89
+ type TMatchStyles = {
90
+ lineColor?: string;
91
+ circleColor?: string;
92
+ questionClassName?: string;
93
+ answerClassName?: string;
94
+ };
95
+
96
+ type TAutoScrollOptions = {
97
+ edgeThreshold?: number;
98
+ maxSpeed?: number;
99
+ };
81
100
  ```
82
101
 
83
102
  `onChange` receives the full list of current matches:
@@ -151,6 +170,21 @@ export function Assessment() {
151
170
  answers={answers}
152
171
  onChange={setMatches}
153
172
  disabled={submitted}
173
+ getMatchStyles={(match) =>
174
+ submitted &&
175
+ !correctMatches.some(
176
+ (correct) =>
177
+ correct.questionId === match.questionId &&
178
+ correct.answerId === match.answerId,
179
+ )
180
+ ? {
181
+ lineColor: "#ef4444",
182
+ circleColor: "#ef4444",
183
+ questionClassName: "bg-red-500",
184
+ answerClassName: "bg-red-500",
185
+ }
186
+ : undefined
187
+ }
154
188
  />
155
189
 
156
190
  <button
@@ -174,9 +208,11 @@ export function Assessment() {
174
208
  ## Behavior
175
209
 
176
210
  - Press and drag from a question to an answer to create a match.
211
+ - Drag near the edge of an overflow container to scroll it.
177
212
  - Click a matched question to remove its current match.
178
213
  - A question can have one answer at a time.
179
- - An answer can be connected to more than one question.
214
+ - An answer can have one question by default. Connecting it again replaces its previous match.
215
+ - Set `allowAnswerReuse` to `true` to connect an answer to more than one question.
180
216
  - `onChange` receives the complete match list after each create or remove action.
181
217
 
182
218
  ## Local Testing
package/dist/index.css CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
2
- @layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-900:oklch(20.8% .042 265.755);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--font-weight-medium:500;--radius-md:.375rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.z-10{z-index:10}.z-20{z-index:20}.contents{display:contents}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-10{gap:calc(var(--spacing) * 10)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-200{border-color:var(--color-gray-200)}.border-slate-300{border-color:var(--color-slate-300)}.bg-black{background-color:var(--color-black)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-6{padding:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\:bg-slate-700:hover{background-color:var(--color-slate-700)}}.focus\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus\:ring-gray-500:focus{--tw-ring-color:var(--color-gray-500)}.focus\:outline-none:focus{--tw-outline-style:none;outline-style:none}}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}
2
+ @layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-red-500:oklch(63.7% .237 25.331);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-900:oklch(20.8% .042 265.755);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--font-weight-medium:500;--radius-md:.375rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.z-10{z-index:10}.z-20{z-index:20}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.contents{display:contents}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.touch-none{touch-action:none}.resize{resize:both}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-10{gap:calc(var(--spacing) * 10)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-200{border-color:var(--color-gray-200)}.border-slate-300{border-color:var(--color-slate-300)}.bg-black{background-color:var(--color-black)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-red-500{background-color:var(--color-red-500)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-6{padding:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\:bg-slate-700:hover{background-color:var(--color-slate-700)}}.focus\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus\:ring-gray-500:focus{--tw-ring-color:var(--color-gray-500)}.focus\:outline-none:focus{--tw-outline-style:none;outline-style:none}}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}
package/dist/index.d.mts CHANGED
@@ -4,7 +4,17 @@ type TMatch = {
4
4
  questionId: number;
5
5
  answerId: number;
6
6
  };
7
- type Props = {
7
+ type TMatchStyles = {
8
+ lineColor?: string;
9
+ circleColor?: string;
10
+ questionClassName?: string;
11
+ answerClassName?: string;
12
+ };
13
+ type TAutoScrollOptions = {
14
+ edgeThreshold?: number;
15
+ maxSpeed?: number;
16
+ };
17
+ type MatchingProps = {
8
18
  questions: {
9
19
  id: number;
10
20
  text: string;
@@ -21,8 +31,11 @@ type Props = {
21
31
  circleRadius?: number;
22
32
  offset?: number;
23
33
  disabled?: boolean;
34
+ allowAnswerReuse?: boolean;
35
+ autoScroll?: boolean | TAutoScrollOptions;
36
+ getMatchStyles?: (match: TMatch) => TMatchStyles | undefined;
24
37
  onChange?: (matches: TMatch[]) => void;
25
38
  };
26
- declare function Matching({ questions, answers, className, questionClassName, answerClassName, lineColor, circleColor, circleRadius, offset, disabled, onChange, }: Props): react_jsx_runtime.JSX.Element;
39
+ declare function Matching({ questions, answers, className, questionClassName, answerClassName, lineColor, circleColor, circleRadius, offset, disabled, allowAnswerReuse, autoScroll, getMatchStyles, onChange, }: MatchingProps): react_jsx_runtime.JSX.Element;
27
40
 
28
- export { Matching, type TMatch };
41
+ export { Matching, type MatchingProps, type TAutoScrollOptions, type TMatch, type TMatchStyles };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,17 @@ type TMatch = {
4
4
  questionId: number;
5
5
  answerId: number;
6
6
  };
7
- type Props = {
7
+ type TMatchStyles = {
8
+ lineColor?: string;
9
+ circleColor?: string;
10
+ questionClassName?: string;
11
+ answerClassName?: string;
12
+ };
13
+ type TAutoScrollOptions = {
14
+ edgeThreshold?: number;
15
+ maxSpeed?: number;
16
+ };
17
+ type MatchingProps = {
8
18
  questions: {
9
19
  id: number;
10
20
  text: string;
@@ -21,8 +31,11 @@ type Props = {
21
31
  circleRadius?: number;
22
32
  offset?: number;
23
33
  disabled?: boolean;
34
+ allowAnswerReuse?: boolean;
35
+ autoScroll?: boolean | TAutoScrollOptions;
36
+ getMatchStyles?: (match: TMatch) => TMatchStyles | undefined;
24
37
  onChange?: (matches: TMatch[]) => void;
25
38
  };
26
- declare function Matching({ questions, answers, className, questionClassName, answerClassName, lineColor, circleColor, circleRadius, offset, disabled, onChange, }: Props): react_jsx_runtime.JSX.Element;
39
+ declare function Matching({ questions, answers, className, questionClassName, answerClassName, lineColor, circleColor, circleRadius, offset, disabled, allowAnswerReuse, autoScroll, getMatchStyles, onChange, }: MatchingProps): react_jsx_runtime.JSX.Element;
27
40
 
28
- export { Matching, type TMatch };
41
+ export { Matching, type MatchingProps, type TAutoScrollOptions, type TMatch, type TMatchStyles };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const __REACT_MATCHINGS_AUTO_CSS__ = "/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-900:oklch(20.8% .042 265.755);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--font-weight-medium:500;--radius-md:.375rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.z-10{z-index:10}.z-20{z-index:20}.contents{display:contents}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-10{gap:calc(var(--spacing) * 10)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-200{border-color:var(--color-gray-200)}.border-slate-300{border-color:var(--color-slate-300)}.bg-black{background-color:var(--color-black)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-6{padding:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\\:bg-slate-700:hover{background-color:var(--color-slate-700)}}.focus\\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus\\:ring-gray-500:focus{--tw-ring-color:var(--color-gray-500)}.focus\\:outline-none:focus{--tw-outline-style:none;outline-style:none}}@property --tw-space-y-reverse{syntax:\"*\";inherits:false;initial-value:0}@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:\"*\";inherits:false}@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:\"*\";inherits:false}@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:\"*\";inherits:false}@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:\"*\";inherits:false}@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:\"*\";inherits:false}@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}";
1
+ const __REACT_MATCHINGS_AUTO_CSS__ = "/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;--color-red-500:oklch(63.7% .237 25.331);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-900:oklch(20.8% .042 265.755);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--font-weight-medium:500;--radius-md:.375rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.z-10{z-index:10}.z-20{z-index:20}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.contents{display:contents}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.touch-none{touch-action:none}.resize{resize:both}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-10{gap:calc(var(--spacing) * 10)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-200{border-color:var(--color-gray-200)}.border-slate-300{border-color:var(--color-slate-300)}.bg-black{background-color:var(--color-black)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-red-500{background-color:var(--color-red-500)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-6{padding:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\\:bg-slate-700:hover{background-color:var(--color-slate-700)}}.focus\\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus\\:ring-gray-500:focus{--tw-ring-color:var(--color-gray-500)}.focus\\:outline-none:focus{--tw-outline-style:none;outline-style:none}}@property --tw-space-y-reverse{syntax:\"*\";inherits:false;initial-value:0}@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:\"*\";inherits:false}@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:\"*\";inherits:false}@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:\"*\";inherits:false}@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:\"*\";inherits:false}@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:\"*\";inherits:false}@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}";
2
2
  function __injectReactMatchingsCss() {
3
3
  if (typeof document === "undefined" || document.getElementById("__REACT_MATCHINGS_AUTO_CSS__")) return;
4
4
  const style = document.createElement("style");
@@ -45,6 +45,25 @@ function cn(...inputs) {
45
45
 
46
46
  // src/matching.tsx
47
47
  var import_jsx_runtime = require("react/jsx-runtime");
48
+ var DEFAULT_EDGE_THRESHOLD = 64;
49
+ var DEFAULT_MAX_SCROLL_SPEED = 16;
50
+ function toMatches(matches) {
51
+ return Object.entries(matches).map(([questionId, answerId]) => ({
52
+ questionId: Number(questionId),
53
+ answerId
54
+ }));
55
+ }
56
+ function findScrollableAncestor(element) {
57
+ let current = element.parentElement;
58
+ while (current) {
59
+ const { overflowY } = window.getComputedStyle(current);
60
+ if (/(auto|scroll|overlay)/.test(overflowY) && current.scrollHeight > current.clientHeight) {
61
+ return current;
62
+ }
63
+ current = current.parentElement;
64
+ }
65
+ return document.scrollingElement ?? document.documentElement;
66
+ }
48
67
  function Matching({
49
68
  questions,
50
69
  answers,
@@ -56,6 +75,9 @@ function Matching({
56
75
  circleRadius = 8,
57
76
  offset = 10,
58
77
  disabled,
78
+ allowAnswerReuse = false,
79
+ autoScroll = true,
80
+ getMatchStyles,
59
81
  onChange
60
82
  }) {
61
83
  const [matches, setMatches] = (0, import_react.useState)({});
@@ -65,10 +87,13 @@ function Matching({
65
87
  const containerRef = (0, import_react.useRef)(null);
66
88
  const questionRefs = (0, import_react.useRef)({});
67
89
  const answerRefs = (0, import_react.useRef)({});
90
+ const pointerRef = (0, import_react.useRef)(null);
91
+ const scrollElementRef = (0, import_react.useRef)(null);
92
+ const scrollFrameRef = (0, import_react.useRef)(null);
68
93
  const getElementCenter = (0, import_react.useCallback)(
69
- (el, isAnswer = false) => {
70
- if (!el || !containerRef.current) return null;
71
- const rect = el.getBoundingClientRect();
94
+ (element, isAnswer = false) => {
95
+ if (!element || !containerRef.current) return null;
96
+ const rect = element.getBoundingClientRect();
72
97
  const containerRect = containerRef.current.getBoundingClientRect();
73
98
  return {
74
99
  x: isAnswer ? rect.left - containerRect.left + circleRadius + offset : rect.right - containerRect.left - circleRadius - offset,
@@ -77,90 +102,137 @@ function Matching({
77
102
  },
78
103
  [circleRadius, offset]
79
104
  );
80
- const handleMouseDown = (qId) => {
81
- if (disabled) return;
82
- setDragging(qId);
83
- requestAnimationFrame(() => {
84
- const start = getElementCenter(questionRefs.current[qId]);
85
- if (start) setDragLine({ start, end: start, questionId: qId });
105
+ const refreshLines = (0, import_react.useCallback)(() => {
106
+ const nextLines = toMatches(matches).map(({ questionId, answerId }) => {
107
+ const start = getElementCenter(questionRefs.current[questionId]);
108
+ const end = getElementCenter(answerRefs.current[answerId], true);
109
+ return start && end ? { questionId, answerId, start, end } : null;
110
+ }).filter((line) => line !== null);
111
+ setLines(nextLines);
112
+ }, [getElementCenter, matches]);
113
+ const refreshDragLine = (0, import_react.useCallback)(() => {
114
+ if (dragging == null || !containerRef.current || !pointerRef.current) return;
115
+ const start = getElementCenter(questionRefs.current[dragging]);
116
+ if (!start) return;
117
+ const rect = containerRef.current.getBoundingClientRect();
118
+ setDragLine({
119
+ start,
120
+ end: {
121
+ x: pointerRef.current.clientX - rect.left,
122
+ y: pointerRef.current.clientY - rect.top
123
+ }
86
124
  });
125
+ }, [dragging, getElementCenter]);
126
+ const stopAutoScroll = (0, import_react.useCallback)(() => {
127
+ if (scrollFrameRef.current !== null) cancelAnimationFrame(scrollFrameRef.current);
128
+ scrollFrameRef.current = null;
129
+ scrollElementRef.current = null;
130
+ }, []);
131
+ const runAutoScroll = (0, import_react.useCallback)(() => {
132
+ scrollFrameRef.current = null;
133
+ if (autoScroll === false || dragging == null || !pointerRef.current) return;
134
+ const scrollElement = scrollElementRef.current;
135
+ if (!scrollElement) return;
136
+ const isDocument = scrollElement === document.scrollingElement;
137
+ const rect = isDocument ? { top: 0, bottom: window.innerHeight } : scrollElement.getBoundingClientRect();
138
+ const edgeThreshold = typeof autoScroll === "object" ? autoScroll.edgeThreshold ?? DEFAULT_EDGE_THRESHOLD : DEFAULT_EDGE_THRESHOLD;
139
+ const maxSpeed = typeof autoScroll === "object" ? autoScroll.maxSpeed ?? DEFAULT_MAX_SCROLL_SPEED : DEFAULT_MAX_SCROLL_SPEED;
140
+ const { clientY } = pointerRef.current;
141
+ let speed = 0;
142
+ if (clientY < rect.top + edgeThreshold) {
143
+ speed = -maxSpeed * (1 - Math.max(0, clientY - rect.top) / edgeThreshold);
144
+ } else if (clientY > rect.bottom - edgeThreshold) {
145
+ speed = maxSpeed * (1 - Math.max(0, rect.bottom - clientY) / edgeThreshold);
146
+ }
147
+ if (speed !== 0) {
148
+ const previousScrollTop = scrollElement.scrollTop;
149
+ scrollElement.scrollTop += speed;
150
+ if (scrollElement.scrollTop !== previousScrollTop) {
151
+ refreshLines();
152
+ refreshDragLine();
153
+ }
154
+ }
155
+ scrollFrameRef.current = requestAnimationFrame(runAutoScroll);
156
+ }, [autoScroll, dragging, refreshDragLine, refreshLines]);
157
+ const cancelDragging = (0, import_react.useCallback)(() => {
158
+ setDragging(null);
159
+ setDragLine(null);
160
+ pointerRef.current = null;
161
+ stopAutoScroll();
162
+ }, [stopAutoScroll]);
163
+ const handlePointerDown = (event, questionId) => {
164
+ if (disabled || !containerRef.current) return;
165
+ event.preventDefault();
166
+ pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };
167
+ scrollElementRef.current = findScrollableAncestor(containerRef.current);
168
+ setDragging(questionId);
87
169
  };
88
- const handleMouseMove = (0, import_react.useCallback)(
89
- (e) => {
90
- if (dragging == null || !containerRef.current) return;
91
- const rect = containerRef.current.getBoundingClientRect();
92
- setDragLine(
93
- (prev) => prev ? {
94
- ...prev,
95
- end: { x: e.clientX - rect.left, y: e.clientY - rect.top }
96
- } : null
97
- );
170
+ const handlePointerMove = (0, import_react.useCallback)(
171
+ (event) => {
172
+ if (dragging == null || pointerRef.current?.id !== event.pointerId) return;
173
+ pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };
174
+ refreshDragLine();
98
175
  },
99
- [dragging]
176
+ [dragging, refreshDragLine]
100
177
  );
101
- const handleMouseUp = (aId) => {
102
- if (dragging != null) {
103
- setMatches((prev) => {
104
- const newMatches = { ...prev, [dragging]: aId };
105
- if (onChange) {
106
- queueMicrotask(
107
- () => onChange(
108
- Object.entries(newMatches).map(([qId, aId2]) => ({
109
- questionId: Number(qId),
110
- answerId: aId2
111
- }))
112
- )
113
- );
178
+ const handlePointerUp = (event, answerId) => {
179
+ if (dragging != null && pointerRef.current?.id === event.pointerId) {
180
+ setMatches((current) => {
181
+ const next = { ...current };
182
+ if (!allowAnswerReuse) {
183
+ for (const [questionId, matchedAnswerId] of Object.entries(next)) {
184
+ if (matchedAnswerId === answerId) delete next[Number(questionId)];
185
+ }
114
186
  }
115
- return newMatches;
187
+ next[dragging] = answerId;
188
+ queueMicrotask(() => onChange?.(toMatches(next)));
189
+ return next;
116
190
  });
117
191
  }
118
- setDragging(null);
119
- setDragLine(null);
192
+ cancelDragging();
120
193
  };
121
- const removeMatch = (qId) => {
122
- setMatches((prev) => {
123
- const newMatches = { ...prev };
124
- delete newMatches[qId];
125
- if (onChange) {
126
- queueMicrotask(
127
- () => onChange(
128
- Object.entries(newMatches).map(([qId2, aId]) => ({
129
- questionId: Number(qId2),
130
- answerId: aId
131
- }))
132
- )
133
- );
134
- }
135
- return newMatches;
194
+ const removeMatch = (questionId) => {
195
+ setMatches((current) => {
196
+ const next = { ...current };
197
+ delete next[questionId];
198
+ queueMicrotask(() => onChange?.(toMatches(next)));
199
+ return next;
136
200
  });
137
201
  };
138
202
  (0, import_react.useEffect)(() => {
139
203
  if (dragging == null) return;
140
- const handleUp = () => {
141
- setDragging(null);
142
- setDragLine(null);
204
+ refreshDragLine();
205
+ if (autoScroll !== false && scrollFrameRef.current === null) {
206
+ scrollFrameRef.current = requestAnimationFrame(runAutoScroll);
207
+ }
208
+ const handleUp = (event) => {
209
+ if (pointerRef.current?.id === event.pointerId) cancelDragging();
143
210
  };
144
- document.addEventListener("mousemove", handleMouseMove);
145
- document.addEventListener("mouseup", handleUp);
211
+ document.addEventListener("pointermove", handlePointerMove);
212
+ document.addEventListener("pointerup", handleUp);
213
+ document.addEventListener("pointercancel", handleUp);
146
214
  return () => {
147
- document.removeEventListener("mousemove", handleMouseMove);
148
- document.removeEventListener("mouseup", handleUp);
215
+ document.removeEventListener("pointermove", handlePointerMove);
216
+ document.removeEventListener("pointerup", handleUp);
217
+ document.removeEventListener("pointercancel", handleUp);
218
+ stopAutoScroll();
149
219
  };
150
- }, [dragging, handleMouseMove]);
220
+ }, [
221
+ autoScroll,
222
+ cancelDragging,
223
+ dragging,
224
+ handlePointerMove,
225
+ refreshDragLine,
226
+ runAutoScroll,
227
+ stopAutoScroll
228
+ ]);
151
229
  (0, import_react.useEffect)(() => {
152
- if (!containerRef.current) return;
153
- const newLines = Object.entries(matches).map(([qId, aId]) => {
154
- const startEl = questionRefs.current[Number(qId)];
155
- const endEl = answerRefs.current[Number(aId)];
156
- if (!startEl || !endEl) return null;
157
- const start = getElementCenter(startEl, false);
158
- const end = getElementCenter(endEl, true);
159
- if (!start || !end) return null;
160
- return { qId, aId: aId.toString(), start, end };
161
- }).filter(Boolean);
162
- setLines(newLines);
163
- }, [matches, getElementCenter]);
230
+ refreshLines();
231
+ }, [refreshLines]);
232
+ (0, import_react.useEffect)(() => {
233
+ window.addEventListener("resize", refreshLines);
234
+ return () => window.removeEventListener("resize", refreshLines);
235
+ }, [refreshLines]);
164
236
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
165
237
  "div",
166
238
  {
@@ -168,30 +240,41 @@ function Matching({
168
240
  ref: containerRef,
169
241
  children: [
170
242
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { className: "absolute z-20 w-full h-full pointer-events-none", children: [
171
- lines.map(({ qId, aId, start, end }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
172
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
173
- "line",
174
- {
175
- x1: start.x,
176
- y1: start.y,
177
- x2: end.x,
178
- y2: end.y,
179
- stroke: lineColor,
180
- strokeWidth: 3,
181
- strokeLinecap: "round"
182
- }
183
- ),
184
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
185
- "circle",
186
- {
187
- cx: start.x,
188
- cy: start.y,
189
- r: circleRadius,
190
- fill: circleColor
191
- }
192
- ),
193
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: end.x, cy: end.y, r: circleRadius, fill: circleColor })
194
- ] }, `${qId}-${aId}`)),
243
+ lines.map((line) => {
244
+ const styles = getMatchStyles?.(line);
245
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
246
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
247
+ "line",
248
+ {
249
+ x1: line.start.x,
250
+ y1: line.start.y,
251
+ x2: line.end.x,
252
+ y2: line.end.y,
253
+ stroke: styles?.lineColor ?? lineColor,
254
+ strokeWidth: 3,
255
+ strokeLinecap: "round"
256
+ }
257
+ ),
258
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
259
+ "circle",
260
+ {
261
+ cx: line.start.x,
262
+ cy: line.start.y,
263
+ r: circleRadius,
264
+ fill: styles?.circleColor ?? circleColor
265
+ }
266
+ ),
267
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
268
+ "circle",
269
+ {
270
+ cx: line.end.x,
271
+ cy: line.end.y,
272
+ r: circleRadius,
273
+ fill: styles?.circleColor ?? circleColor
274
+ }
275
+ )
276
+ ] }, `${line.questionId}-${line.answerId}`);
277
+ }),
195
278
  dragLine && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
196
279
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
197
280
  "line",
@@ -206,63 +289,50 @@ function Matching({
206
289
  strokeLinecap: "round"
207
290
  }
208
291
  ),
209
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
210
- "circle",
211
- {
212
- cx: dragLine.start.x,
213
- cy: dragLine.start.y,
214
- r: circleRadius,
215
- fill: circleColor
216
- }
217
- ),
218
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
219
- "circle",
220
- {
221
- cx: dragLine.end.x,
222
- cy: dragLine.end.y,
223
- r: circleRadius,
224
- fill: circleColor
225
- }
226
- )
292
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: dragLine.start.x, cy: dragLine.start.y, r: circleRadius, fill: circleColor }),
293
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: dragLine.end.x, cy: dragLine.end.y, r: circleRadius, fill: circleColor })
227
294
  ] })
228
295
  ] }),
229
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "relative z-10 space-y-3", children: questions.map((q) => {
230
- const isMatched = matches[q.id] !== void 0;
296
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "relative z-10 space-y-3", children: questions.map((question) => {
297
+ const answerId = matches[question.id];
298
+ const styles = answerId === void 0 ? void 0 : getMatchStyles?.({ questionId: question.id, answerId });
231
299
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
232
300
  "button",
233
301
  {
234
- ref: (el) => void (questionRefs.current[q.id] = el),
302
+ ref: (element) => void (questionRefs.current[question.id] = element),
235
303
  type: "button",
236
304
  disabled,
237
- onMouseDown: () => handleMouseDown(q.id),
238
- onClick: () => isMatched && removeMatch(q.id),
305
+ onPointerDown: (event) => handlePointerDown(event, question.id),
306
+ onClick: () => answerId !== void 0 && removeMatch(question.id),
239
307
  className: cn(
240
- "p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
241
- isMatched && "bg-gray-700",
242
- questionClassName
308
+ "p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
309
+ answerId !== void 0 && "bg-gray-700",
310
+ questionClassName,
311
+ styles?.questionClassName
243
312
  ),
244
- children: q.text
313
+ children: question.text
245
314
  },
246
- q.id
315
+ question.id
247
316
  );
248
317
  }) }),
249
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "relative z-10 space-y-3", children: answers.map((a) => {
250
- const isMatched = Object.values(matches).includes(a.id);
318
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "relative z-10 space-y-3", children: answers.map((answer) => {
319
+ const answerMatches = toMatches(matches).filter((match) => match.answerId === answer.id);
251
320
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
252
321
  "button",
253
322
  {
254
- ref: (el) => void (answerRefs.current[a.id] = el),
323
+ ref: (element) => void (answerRefs.current[answer.id] = element),
255
324
  type: "button",
256
325
  disabled,
257
- onMouseUp: () => handleMouseUp(a.id),
326
+ onPointerUp: (event) => handlePointerUp(event, answer.id),
258
327
  className: cn(
259
- "p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
260
- isMatched && "bg-gray-700",
261
- answerClassName
328
+ "p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
329
+ answerMatches.length > 0 && "bg-gray-700",
330
+ answerClassName,
331
+ answerMatches.map((match) => getMatchStyles?.(match)?.answerClassName)
262
332
  ),
263
- children: a.text
333
+ children: answer.text
264
334
  },
265
- a.id
335
+ answer.id
266
336
  );
267
337
  }) })
268
338
  ]
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/matching.tsx","../src/lib/utils.ts"],"sourcesContent":["export { Matching } from \"./matching\";\nexport type { TMatch } from \"./matching\";\n","import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { cn } from \"./lib/utils\";\n\nexport type TMatch = {\n questionId: number;\n answerId: number;\n};\n\ntype Props = {\n questions: { id: number; text: string }[];\n answers: { id: number; text: string }[];\n className?: string;\n questionClassName?: string;\n answerClassName?: string;\n lineColor?: string;\n circleColor?: string;\n circleRadius?: number;\n offset?: number;\n disabled?: boolean;\n onChange?: (matches: TMatch[]) => void;\n};\n\ntype Line = {\n qId: string;\n aId: string;\n start: { x: number; y: number };\n end: { x: number; y: number };\n};\n\nexport function Matching({\n questions,\n answers,\n className,\n questionClassName,\n answerClassName,\n lineColor = \"black\",\n circleColor = \"white\",\n circleRadius = 8,\n offset = 10,\n disabled,\n onChange,\n}: Props) {\n const [matches, setMatches] = useState<Record<number, number>>({});\n const [lines, setLines] = useState<Line[]>([]);\n const [dragging, setDragging] = useState<number | null>(null);\n const [dragLine, setDragLine] = useState<{\n start: { x: number; y: number };\n end: { x: number; y: number };\n questionId: number;\n } | null>(null);\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const questionRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const answerRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n\n const getElementCenter = useCallback(\n (el: HTMLElement | null, isAnswer = false) => {\n if (!el || !containerRef.current) return null;\n const rect = el.getBoundingClientRect();\n const containerRect = containerRef.current.getBoundingClientRect();\n return {\n x: isAnswer\n ? rect.left - containerRect.left + circleRadius + offset\n : rect.right - containerRect.left - circleRadius - offset,\n y: rect.top + rect.height / 2 - containerRect.top,\n };\n },\n [circleRadius, offset]\n );\n\n const handleMouseDown = (qId: number) => {\n if (disabled) return;\n setDragging(qId);\n requestAnimationFrame(() => {\n const start = getElementCenter(questionRefs.current[qId]);\n if (start) setDragLine({ start, end: start, questionId: qId });\n });\n };\n\n const handleMouseMove = useCallback(\n (e: MouseEvent) => {\n if (dragging == null || !containerRef.current) return;\n const rect = containerRef.current.getBoundingClientRect();\n setDragLine((prev) =>\n prev\n ? {\n ...prev,\n end: { x: e.clientX - rect.left, y: e.clientY - rect.top },\n }\n : null\n );\n },\n [dragging]\n );\n\n const handleMouseUp = (aId: number) => {\n if (dragging != null) {\n setMatches((prev) => {\n const newMatches = { ...prev, [dragging]: aId };\n if (onChange) {\n // notify parent immediately on every change\n queueMicrotask(() =>\n onChange(\n Object.entries(newMatches).map(([qId, aId]) => ({\n questionId: Number(qId),\n answerId: aId,\n }))\n )\n );\n }\n return newMatches;\n });\n }\n setDragging(null);\n setDragLine(null);\n };\n\n const removeMatch = (qId: number) => {\n setMatches((prev) => {\n const newMatches = { ...prev };\n delete newMatches[qId];\n if (onChange) {\n queueMicrotask(() =>\n onChange(\n Object.entries(newMatches).map(([qId, aId]) => ({\n questionId: Number(qId),\n answerId: aId,\n }))\n )\n );\n }\n return newMatches;\n });\n };\n\n useEffect(() => {\n if (dragging == null) return;\n const handleUp = () => {\n setDragging(null);\n setDragLine(null);\n };\n document.addEventListener(\"mousemove\", handleMouseMove);\n document.addEventListener(\"mouseup\", handleUp);\n return () => {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n document.removeEventListener(\"mouseup\", handleUp);\n };\n }, [dragging, handleMouseMove]);\n\n useEffect(() => {\n if (!containerRef.current) return;\n\n const newLines: Line[] = Object.entries(matches)\n .map(([qId, aId]) => {\n const startEl = questionRefs.current[Number(qId)];\n const endEl = answerRefs.current[Number(aId)];\n if (!startEl || !endEl) return null;\n const start = getElementCenter(startEl, false);\n const end = getElementCenter(endEl, true);\n if (!start || !end) return null;\n return { qId, aId: aId.toString(), start, end };\n })\n .filter(Boolean) as Line[];\n\n setLines(newLines);\n }, [matches, getElementCenter]);\n\n return (\n <div\n className={cn(\"grid relative grid-cols-2 gap-10 select-none\", className)}\n ref={containerRef}\n >\n <svg className=\"absolute z-20 w-full h-full pointer-events-none\">\n {lines.map(({ qId, aId, start, end }) => (\n <g key={`${qId}-${aId}`}>\n <line\n x1={start.x}\n y1={start.y}\n x2={end.x}\n y2={end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeLinecap=\"round\"\n />\n <circle\n cx={start.x}\n cy={start.y}\n r={circleRadius}\n fill={circleColor}\n />\n <circle cx={end.x} cy={end.y} r={circleRadius} fill={circleColor} />\n </g>\n ))}\n {dragLine && (\n <g>\n <line\n x1={dragLine.start.x}\n y1={dragLine.start.y}\n x2={dragLine.end.x}\n y2={dragLine.end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeDasharray=\"5,5\"\n strokeLinecap=\"round\"\n />\n <circle\n cx={dragLine.start.x}\n cy={dragLine.start.y}\n r={circleRadius}\n fill={circleColor}\n />\n <circle\n cx={dragLine.end.x}\n cy={dragLine.end.y}\n r={circleRadius}\n fill={circleColor}\n />\n </g>\n )}\n </svg>\n\n <div className=\"relative z-10 space-y-3\">\n {questions.map((q) => {\n const isMatched = matches[q.id] !== undefined;\n return (\n <button\n key={q.id}\n ref={(el) => void (questionRefs.current[q.id] = el)}\n type=\"button\"\n disabled={disabled}\n onMouseDown={() => handleMouseDown(q.id)}\n onClick={() => isMatched && removeMatch(q.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n isMatched && \"bg-gray-700\",\n questionClassName\n )}\n >\n {q.text}\n </button>\n );\n })}\n </div>\n\n <div className=\"relative z-10 space-y-3\">\n {answers.map((a) => {\n const isMatched = Object.values(matches).includes(a.id);\n return (\n <button\n key={a.id}\n ref={(el) => void (answerRefs.current[a.id] = el)}\n type=\"button\"\n disabled={disabled}\n onMouseUp={() => handleMouseUp(a.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n isMatched && \"bg-gray-700\",\n answerClassName\n )}\n >\n {a.text}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyD;;;ACAzD,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AAC1C,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC7B;;;ADyKU;AAjJH,SAAS,SAAS;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,eAAe;AAAA,EACf,SAAS;AAAA,EACT;AAAA,EACA;AACF,GAAU;AACR,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAiC,CAAC,CAAC;AACjE,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAiB,CAAC,CAAC;AAC7C,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAwB,IAAI;AAC5D,QAAM,CAAC,UAAU,WAAW,QAAI,uBAItB,IAAI;AAEd,QAAM,mBAAe,qBAA8B,IAAI;AACvD,QAAM,mBAAe,qBAAiD,CAAC,CAAC;AACxE,QAAM,iBAAa,qBAAiD,CAAC,CAAC;AAEtE,QAAM,uBAAmB;AAAA,IACvB,CAAC,IAAwB,WAAW,UAAU;AAC5C,UAAI,CAAC,MAAM,CAAC,aAAa,QAAS,QAAO;AACzC,YAAM,OAAO,GAAG,sBAAsB;AACtC,YAAM,gBAAgB,aAAa,QAAQ,sBAAsB;AACjE,aAAO;AAAA,QACL,GAAG,WACC,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ACF;AAAA,WAEJ;AAAA,QAEA,4CAAC,SAAI,WAAU,2BACZ,oBAAU,IAAI,CAAC,MAAM;AACpB,gBAAM,YAAY,QAAQ,EAAE,EAAE,MAAM;AACpC,iBACE;AAAA,YAAC;AAAA;AAAA,cAEC,KAAK,CAAC,OAAO,MAAM,aAAa,QAAQ,EAAE,EAAE,IAAI;AAAA,cAChD,MAAK;AAAA,cACL;AAAA,cACA,aAAa,MAAM,gBAAgB,EAAE,EAAE;AAAA,cACvC,SAAS,MAAM,aAAa,YAAY,EAAE,EAAE;AAAA,cAC5C,WAAW;AAAA,gBACT;AAAA,gBACA,aAAa;AAAA,gBACb;AAAA,cACF;AAAA,cAEC,YAAE;AAAA;AAAA,YAZE,EAAE;AAAA,UAaT;AAAA,QAEJ,CAAC,GACH;AAAA,QAEA,4CAAC,SAAI,WAAU,2BACZ,kBAAQ,IAAI,CAAC,MAAM;AAClB,gBAAM,YAAY,OAAO,OAAO,OAAO,EAAE,SAAS,EAAE,EAAE;AACtD,iBACE;AAAA,YAAC;AAAA;AAAA,cAEC,KAAK,CAAC,OAAO,MAAM,WAAW,QAAQ,EAAE,EAAE,IAAI;AAAA,cAC9C,MAAK;AAAA,cACL;AAAA,cACA,WAAW,MAAM,cAAc,EAAE,EAAE;AAAA,cACnC,WAAW;AAAA,gBACT;AAAA,gBACA,aAAa;AAAA,gBACb;AAAA,cACF;AAAA,cAEC,YAAE;AAAA;AAAA,YAXE,EAAE;AAAA,UAYT;AAAA,QAEJ,CAAC,GACH;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["aId","qId"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/matching.tsx","../src/lib/utils.ts"],"sourcesContent":["export { Matching } from \"./matching\";\nexport type {\n MatchingProps,\n TAutoScrollOptions,\n TMatch,\n TMatchStyles,\n} from \"./matching\";\n","import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { cn } from \"./lib/utils\";\n\nexport type TMatch = {\n questionId: number;\n answerId: number;\n};\n\nexport type TMatchStyles = {\n lineColor?: string;\n circleColor?: string;\n questionClassName?: string;\n answerClassName?: string;\n};\n\nexport type TAutoScrollOptions = {\n edgeThreshold?: number;\n maxSpeed?: number;\n};\n\nexport type MatchingProps = {\n questions: { id: number; text: string }[];\n answers: { id: number; text: string }[];\n className?: string;\n questionClassName?: string;\n answerClassName?: string;\n lineColor?: string;\n circleColor?: string;\n circleRadius?: number;\n offset?: number;\n disabled?: boolean;\n allowAnswerReuse?: boolean;\n autoScroll?: boolean | TAutoScrollOptions;\n getMatchStyles?: (match: TMatch) => TMatchStyles | undefined;\n onChange?: (matches: TMatch[]) => void;\n};\n\ntype Point = { x: number; y: number };\n\ntype Line = TMatch & {\n start: Point;\n end: Point;\n};\n\nconst DEFAULT_EDGE_THRESHOLD = 64;\nconst DEFAULT_MAX_SCROLL_SPEED = 16;\n\nfunction toMatches(matches: Record<number, number>): TMatch[] {\n return Object.entries(matches).map(([questionId, answerId]) => ({\n questionId: Number(questionId),\n answerId,\n }));\n}\n\nfunction findScrollableAncestor(element: HTMLElement): HTMLElement {\n let current = element.parentElement;\n\n while (current) {\n const { overflowY } = window.getComputedStyle(current);\n if (/(auto|scroll|overlay)/.test(overflowY) && current.scrollHeight > current.clientHeight) {\n return current;\n }\n current = current.parentElement;\n }\n\n return (document.scrollingElement as HTMLElement | null) ?? document.documentElement;\n}\n\nexport function Matching({\n questions,\n answers,\n className,\n questionClassName,\n answerClassName,\n lineColor = \"black\",\n circleColor = \"white\",\n circleRadius = 8,\n offset = 10,\n disabled,\n allowAnswerReuse = false,\n autoScroll = true,\n getMatchStyles,\n onChange,\n}: MatchingProps) {\n const [matches, setMatches] = useState<Record<number, number>>({});\n const [lines, setLines] = useState<Line[]>([]);\n const [dragging, setDragging] = useState<number | null>(null);\n const [dragLine, setDragLine] = useState<{ start: Point; end: Point } | null>(null);\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const questionRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const answerRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const pointerRef = useRef<{ id: number; clientX: number; clientY: number } | null>(null);\n const scrollElementRef = useRef<HTMLElement | null>(null);\n const scrollFrameRef = useRef<number | null>(null);\n\n const getElementCenter = useCallback(\n (element: HTMLElement | null, isAnswer = false) => {\n if (!element || !containerRef.current) return null;\n const rect = element.getBoundingClientRect();\n const containerRect = containerRef.current.getBoundingClientRect();\n return {\n x: isAnswer\n ? rect.left - containerRect.left + circleRadius + offset\n : rect.right - containerRect.left - circleRadius - offset,\n y: rect.top + rect.height / 2 - containerRect.top,\n };\n },\n [circleRadius, offset]\n );\n\n const refreshLines = useCallback(() => {\n const nextLines = toMatches(matches)\n .map(({ questionId, answerId }) => {\n const start = getElementCenter(questionRefs.current[questionId]);\n const end = getElementCenter(answerRefs.current[answerId], true);\n return start && end ? { questionId, answerId, start, end } : null;\n })\n .filter((line): line is Line => line !== null);\n\n setLines(nextLines);\n }, [getElementCenter, matches]);\n\n const refreshDragLine = useCallback(() => {\n if (dragging == null || !containerRef.current || !pointerRef.current) return;\n const start = getElementCenter(questionRefs.current[dragging]);\n if (!start) return;\n const rect = containerRef.current.getBoundingClientRect();\n setDragLine({\n start,\n end: {\n x: pointerRef.current.clientX - rect.left,\n y: pointerRef.current.clientY - rect.top,\n },\n });\n }, [dragging, getElementCenter]);\n\n const stopAutoScroll = useCallback(() => {\n if (scrollFrameRef.current !== null) cancelAnimationFrame(scrollFrameRef.current);\n scrollFrameRef.current = null;\n scrollElementRef.current = null;\n }, []);\n\n const runAutoScroll = useCallback(() => {\n scrollFrameRef.current = null;\n if (autoScroll === false || dragging == null || !pointerRef.current) return;\n\n const scrollElement = scrollElementRef.current;\n if (!scrollElement) return;\n\n const isDocument = scrollElement === document.scrollingElement;\n const rect = isDocument\n ? { top: 0, bottom: window.innerHeight }\n : scrollElement.getBoundingClientRect();\n const edgeThreshold =\n typeof autoScroll === \"object\"\n ? (autoScroll.edgeThreshold ?? DEFAULT_EDGE_THRESHOLD)\n : DEFAULT_EDGE_THRESHOLD;\n const maxSpeed =\n typeof autoScroll === \"object\"\n ? (autoScroll.maxSpeed ?? DEFAULT_MAX_SCROLL_SPEED)\n : DEFAULT_MAX_SCROLL_SPEED;\n const { clientY } = pointerRef.current;\n let speed = 0;\n\n if (clientY < rect.top + edgeThreshold) {\n speed = -maxSpeed * (1 - Math.max(0, clientY - rect.top) / edgeThreshold);\n } else if (clientY > rect.bottom - edgeThreshold) {\n speed = maxSpeed * (1 - Math.max(0, rect.bottom - clientY) / edgeThreshold);\n }\n\n if (speed !== 0) {\n const previousScrollTop = scrollElement.scrollTop;\n scrollElement.scrollTop += speed;\n if (scrollElement.scrollTop !== previousScrollTop) {\n refreshLines();\n refreshDragLine();\n }\n }\n\n scrollFrameRef.current = requestAnimationFrame(runAutoScroll);\n }, [autoScroll, dragging, refreshDragLine, refreshLines]);\n\n const cancelDragging = useCallback(() => {\n setDragging(null);\n setDragLine(null);\n pointerRef.current = null;\n stopAutoScroll();\n }, [stopAutoScroll]);\n\n const handlePointerDown = (event: React.PointerEvent, questionId: number) => {\n if (disabled || !containerRef.current) return;\n event.preventDefault();\n pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };\n scrollElementRef.current = findScrollableAncestor(containerRef.current);\n setDragging(questionId);\n };\n\n const handlePointerMove = useCallback(\n (event: PointerEvent) => {\n if (dragging == null || pointerRef.current?.id !== event.pointerId) return;\n pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };\n refreshDragLine();\n },\n [dragging, refreshDragLine]\n );\n\n const handlePointerUp = (event: React.PointerEvent, answerId: number) => {\n if (dragging != null && pointerRef.current?.id === event.pointerId) {\n setMatches((current) => {\n const next = { ...current };\n if (!allowAnswerReuse) {\n for (const [questionId, matchedAnswerId] of Object.entries(next)) {\n if (matchedAnswerId === answerId) delete next[Number(questionId)];\n }\n }\n next[dragging] = answerId;\n queueMicrotask(() => onChange?.(toMatches(next)));\n return next;\n });\n }\n cancelDragging();\n };\n\n const removeMatch = (questionId: number) => {\n setMatches((current) => {\n const next = { ...current };\n delete next[questionId];\n queueMicrotask(() => onChange?.(toMatches(next)));\n return next;\n });\n };\n\n useEffect(() => {\n if (dragging == null) return;\n refreshDragLine();\n if (autoScroll !== false && scrollFrameRef.current === null) {\n scrollFrameRef.current = requestAnimationFrame(runAutoScroll);\n }\n\n const handleUp = (event: PointerEvent) => {\n if (pointerRef.current?.id === event.pointerId) cancelDragging();\n };\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handleUp);\n document.addEventListener(\"pointercancel\", handleUp);\n return () => {\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handleUp);\n document.removeEventListener(\"pointercancel\", handleUp);\n stopAutoScroll();\n };\n }, [\n autoScroll,\n cancelDragging,\n dragging,\n handlePointerMove,\n refreshDragLine,\n runAutoScroll,\n stopAutoScroll,\n ]);\n\n useEffect(() => {\n refreshLines();\n }, [refreshLines]);\n\n useEffect(() => {\n window.addEventListener(\"resize\", refreshLines);\n return () => window.removeEventListener(\"resize\", refreshLines);\n }, [refreshLines]);\n\n return (\n <div\n className={cn(\"grid relative grid-cols-2 gap-10 select-none\", className)}\n ref={containerRef}\n >\n <svg className=\"absolute z-20 w-full h-full pointer-events-none\">\n {lines.map((line) => {\n const styles = getMatchStyles?.(line);\n return (\n <g key={`${line.questionId}-${line.answerId}`}>\n <line\n x1={line.start.x}\n y1={line.start.y}\n x2={line.end.x}\n y2={line.end.y}\n stroke={styles?.lineColor ?? lineColor}\n strokeWidth={3}\n strokeLinecap=\"round\"\n />\n <circle\n cx={line.start.x}\n cy={line.start.y}\n r={circleRadius}\n fill={styles?.circleColor ?? circleColor}\n />\n <circle\n cx={line.end.x}\n cy={line.end.y}\n r={circleRadius}\n fill={styles?.circleColor ?? circleColor}\n />\n </g>\n );\n })}\n {dragLine && (\n <g>\n <line\n x1={dragLine.start.x}\n y1={dragLine.start.y}\n x2={dragLine.end.x}\n y2={dragLine.end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeDasharray=\"5,5\"\n strokeLinecap=\"round\"\n />\n <circle cx={dragLine.start.x} cy={dragLine.start.y} r={circleRadius} fill={circleColor} />\n <circle cx={dragLine.end.x} cy={dragLine.end.y} r={circleRadius} fill={circleColor} />\n </g>\n )}\n </svg>\n\n <div className=\"relative z-10 space-y-3\">\n {questions.map((question) => {\n const answerId = matches[question.id];\n const styles =\n answerId === undefined\n ? undefined\n : getMatchStyles?.({ questionId: question.id, answerId });\n return (\n <button\n key={question.id}\n ref={(element) => void (questionRefs.current[question.id] = element)}\n type=\"button\"\n disabled={disabled}\n onPointerDown={(event) => handlePointerDown(event, question.id)}\n onClick={() => answerId !== undefined && removeMatch(question.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n answerId !== undefined && \"bg-gray-700\",\n questionClassName,\n styles?.questionClassName\n )}\n >\n {question.text}\n </button>\n );\n })}\n </div>\n\n <div className=\"relative z-10 space-y-3\">\n {answers.map((answer) => {\n const answerMatches = toMatches(matches).filter((match) => match.answerId === answer.id);\n return (\n <button\n key={answer.id}\n ref={(element) => void (answerRefs.current[answer.id] = element)}\n type=\"button\"\n disabled={disabled}\n onPointerUp={(event) => handlePointerUp(event, answer.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n answerMatches.length > 0 && \"bg-gray-700\",\n answerClassName,\n answerMatches.map((match) => getMatchStyles?.(match)?.answerClassName)\n )}\n >\n {answer.text}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyD;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AAAA,cAC9D,SAAS,MAAM,aAAa,UAAa,YAAY,SAAS,EAAE;AAAA,cAChE,WAAW;AAAA,gBACT;AAAA,gBACA,aAAa,UAAa;AAAA,gBAC1B;AAAA,gBACA,QAAQ;AAAA,cACV;AAAA,cAEC,mBAAS;AAAA;AAAA,YAbL,SAAS;AAAA,UAchB;AAAA,QAEJ,CAAC,GACH;AAAA,QAEA,4CAAC,SAAI,WAAU,2BACZ,kBAAQ,IAAI,CAAC,WAAW;AACvB,gBAAM,gBAAgB,UAAU,OAAO,EAAE,OAAO,CAAC,UAAU,MAAM,aAAa,OAAO,EAAE;AACvF,iBACE;AAAA,YAAC;AAAA;AAAA,cAEC,KAAK,CAAC,YAAY,MAAM,WAAW,QAAQ,OAAO,EAAE,IAAI;AAAA,cACxD,MAAK;AAAA,cACL;AAAA,cACA,aAAa,CAAC,UAAU,gBAAgB,OAAO,OAAO,EAAE;AAAA,cACxD,WAAW;AAAA,gBACT;AAAA,gBACA,cAAc,SAAS,KAAK;AAAA,gBAC5B;AAAA,gBACA,cAAc,IAAI,CAAC,UAAU,iBAAiB,KAAK,GAAG,eAAe;AAAA,cACvE;AAAA,cAEC,iBAAO;AAAA;AAAA,YAZH,OAAO;AAAA,UAad;AAAA,QAEJ,CAAC,GACH;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const __REACT_MATCHINGS_AUTO_CSS__ = "/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-900:oklch(20.8% .042 265.755);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--font-weight-medium:500;--radius-md:.375rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.z-10{z-index:10}.z-20{z-index:20}.contents{display:contents}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-10{gap:calc(var(--spacing) * 10)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-200{border-color:var(--color-gray-200)}.border-slate-300{border-color:var(--color-slate-300)}.bg-black{background-color:var(--color-black)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-6{padding:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\\:bg-slate-700:hover{background-color:var(--color-slate-700)}}.focus\\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus\\:ring-gray-500:focus{--tw-ring-color:var(--color-gray-500)}.focus\\:outline-none:focus{--tw-outline-style:none;outline-style:none}}@property --tw-space-y-reverse{syntax:\"*\";inherits:false;initial-value:0}@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:\"*\";inherits:false}@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:\"*\";inherits:false}@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:\"*\";inherits:false}@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:\"*\";inherits:false}@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:\"*\";inherits:false}@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}";
1
+ const __REACT_MATCHINGS_AUTO_CSS__ = "/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;--color-red-500:oklch(63.7% .237 25.331);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-900:oklch(20.8% .042 265.755);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--font-weight-medium:500;--radius-md:.375rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.z-10{z-index:10}.z-20{z-index:20}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.contents{display:contents}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.touch-none{touch-action:none}.resize{resize:both}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-10{gap:calc(var(--spacing) * 10)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-200{border-color:var(--color-gray-200)}.border-slate-300{border-color:var(--color-slate-300)}.bg-black{background-color:var(--color-black)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-red-500{background-color:var(--color-red-500)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-6{padding:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\\:bg-slate-700:hover{background-color:var(--color-slate-700)}}.focus\\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus\\:ring-gray-500:focus{--tw-ring-color:var(--color-gray-500)}.focus\\:outline-none:focus{--tw-outline-style:none;outline-style:none}}@property --tw-space-y-reverse{syntax:\"*\";inherits:false;initial-value:0}@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:\"*\";inherits:false}@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:\"*\";inherits:false}@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:\"*\";inherits:false}@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:\"*\";inherits:false}@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:\"*\";inherits:false}@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}";
2
2
  function __injectReactMatchingsCss() {
3
3
  if (typeof document === "undefined" || document.getElementById("__REACT_MATCHINGS_AUTO_CSS__")) return;
4
4
  const style = document.createElement("style");
@@ -19,6 +19,25 @@ function cn(...inputs) {
19
19
 
20
20
  // src/matching.tsx
21
21
  import { jsx, jsxs } from "react/jsx-runtime";
22
+ var DEFAULT_EDGE_THRESHOLD = 64;
23
+ var DEFAULT_MAX_SCROLL_SPEED = 16;
24
+ function toMatches(matches) {
25
+ return Object.entries(matches).map(([questionId, answerId]) => ({
26
+ questionId: Number(questionId),
27
+ answerId
28
+ }));
29
+ }
30
+ function findScrollableAncestor(element) {
31
+ let current = element.parentElement;
32
+ while (current) {
33
+ const { overflowY } = window.getComputedStyle(current);
34
+ if (/(auto|scroll|overlay)/.test(overflowY) && current.scrollHeight > current.clientHeight) {
35
+ return current;
36
+ }
37
+ current = current.parentElement;
38
+ }
39
+ return document.scrollingElement ?? document.documentElement;
40
+ }
22
41
  function Matching({
23
42
  questions,
24
43
  answers,
@@ -30,6 +49,9 @@ function Matching({
30
49
  circleRadius = 8,
31
50
  offset = 10,
32
51
  disabled,
52
+ allowAnswerReuse = false,
53
+ autoScroll = true,
54
+ getMatchStyles,
33
55
  onChange
34
56
  }) {
35
57
  const [matches, setMatches] = useState({});
@@ -39,10 +61,13 @@ function Matching({
39
61
  const containerRef = useRef(null);
40
62
  const questionRefs = useRef({});
41
63
  const answerRefs = useRef({});
64
+ const pointerRef = useRef(null);
65
+ const scrollElementRef = useRef(null);
66
+ const scrollFrameRef = useRef(null);
42
67
  const getElementCenter = useCallback(
43
- (el, isAnswer = false) => {
44
- if (!el || !containerRef.current) return null;
45
- const rect = el.getBoundingClientRect();
68
+ (element, isAnswer = false) => {
69
+ if (!element || !containerRef.current) return null;
70
+ const rect = element.getBoundingClientRect();
46
71
  const containerRect = containerRef.current.getBoundingClientRect();
47
72
  return {
48
73
  x: isAnswer ? rect.left - containerRect.left + circleRadius + offset : rect.right - containerRect.left - circleRadius - offset,
@@ -51,90 +76,137 @@ function Matching({
51
76
  },
52
77
  [circleRadius, offset]
53
78
  );
54
- const handleMouseDown = (qId) => {
55
- if (disabled) return;
56
- setDragging(qId);
57
- requestAnimationFrame(() => {
58
- const start = getElementCenter(questionRefs.current[qId]);
59
- if (start) setDragLine({ start, end: start, questionId: qId });
79
+ const refreshLines = useCallback(() => {
80
+ const nextLines = toMatches(matches).map(({ questionId, answerId }) => {
81
+ const start = getElementCenter(questionRefs.current[questionId]);
82
+ const end = getElementCenter(answerRefs.current[answerId], true);
83
+ return start && end ? { questionId, answerId, start, end } : null;
84
+ }).filter((line) => line !== null);
85
+ setLines(nextLines);
86
+ }, [getElementCenter, matches]);
87
+ const refreshDragLine = useCallback(() => {
88
+ if (dragging == null || !containerRef.current || !pointerRef.current) return;
89
+ const start = getElementCenter(questionRefs.current[dragging]);
90
+ if (!start) return;
91
+ const rect = containerRef.current.getBoundingClientRect();
92
+ setDragLine({
93
+ start,
94
+ end: {
95
+ x: pointerRef.current.clientX - rect.left,
96
+ y: pointerRef.current.clientY - rect.top
97
+ }
60
98
  });
99
+ }, [dragging, getElementCenter]);
100
+ const stopAutoScroll = useCallback(() => {
101
+ if (scrollFrameRef.current !== null) cancelAnimationFrame(scrollFrameRef.current);
102
+ scrollFrameRef.current = null;
103
+ scrollElementRef.current = null;
104
+ }, []);
105
+ const runAutoScroll = useCallback(() => {
106
+ scrollFrameRef.current = null;
107
+ if (autoScroll === false || dragging == null || !pointerRef.current) return;
108
+ const scrollElement = scrollElementRef.current;
109
+ if (!scrollElement) return;
110
+ const isDocument = scrollElement === document.scrollingElement;
111
+ const rect = isDocument ? { top: 0, bottom: window.innerHeight } : scrollElement.getBoundingClientRect();
112
+ const edgeThreshold = typeof autoScroll === "object" ? autoScroll.edgeThreshold ?? DEFAULT_EDGE_THRESHOLD : DEFAULT_EDGE_THRESHOLD;
113
+ const maxSpeed = typeof autoScroll === "object" ? autoScroll.maxSpeed ?? DEFAULT_MAX_SCROLL_SPEED : DEFAULT_MAX_SCROLL_SPEED;
114
+ const { clientY } = pointerRef.current;
115
+ let speed = 0;
116
+ if (clientY < rect.top + edgeThreshold) {
117
+ speed = -maxSpeed * (1 - Math.max(0, clientY - rect.top) / edgeThreshold);
118
+ } else if (clientY > rect.bottom - edgeThreshold) {
119
+ speed = maxSpeed * (1 - Math.max(0, rect.bottom - clientY) / edgeThreshold);
120
+ }
121
+ if (speed !== 0) {
122
+ const previousScrollTop = scrollElement.scrollTop;
123
+ scrollElement.scrollTop += speed;
124
+ if (scrollElement.scrollTop !== previousScrollTop) {
125
+ refreshLines();
126
+ refreshDragLine();
127
+ }
128
+ }
129
+ scrollFrameRef.current = requestAnimationFrame(runAutoScroll);
130
+ }, [autoScroll, dragging, refreshDragLine, refreshLines]);
131
+ const cancelDragging = useCallback(() => {
132
+ setDragging(null);
133
+ setDragLine(null);
134
+ pointerRef.current = null;
135
+ stopAutoScroll();
136
+ }, [stopAutoScroll]);
137
+ const handlePointerDown = (event, questionId) => {
138
+ if (disabled || !containerRef.current) return;
139
+ event.preventDefault();
140
+ pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };
141
+ scrollElementRef.current = findScrollableAncestor(containerRef.current);
142
+ setDragging(questionId);
61
143
  };
62
- const handleMouseMove = useCallback(
63
- (e) => {
64
- if (dragging == null || !containerRef.current) return;
65
- const rect = containerRef.current.getBoundingClientRect();
66
- setDragLine(
67
- (prev) => prev ? {
68
- ...prev,
69
- end: { x: e.clientX - rect.left, y: e.clientY - rect.top }
70
- } : null
71
- );
144
+ const handlePointerMove = useCallback(
145
+ (event) => {
146
+ if (dragging == null || pointerRef.current?.id !== event.pointerId) return;
147
+ pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };
148
+ refreshDragLine();
72
149
  },
73
- [dragging]
150
+ [dragging, refreshDragLine]
74
151
  );
75
- const handleMouseUp = (aId) => {
76
- if (dragging != null) {
77
- setMatches((prev) => {
78
- const newMatches = { ...prev, [dragging]: aId };
79
- if (onChange) {
80
- queueMicrotask(
81
- () => onChange(
82
- Object.entries(newMatches).map(([qId, aId2]) => ({
83
- questionId: Number(qId),
84
- answerId: aId2
85
- }))
86
- )
87
- );
152
+ const handlePointerUp = (event, answerId) => {
153
+ if (dragging != null && pointerRef.current?.id === event.pointerId) {
154
+ setMatches((current) => {
155
+ const next = { ...current };
156
+ if (!allowAnswerReuse) {
157
+ for (const [questionId, matchedAnswerId] of Object.entries(next)) {
158
+ if (matchedAnswerId === answerId) delete next[Number(questionId)];
159
+ }
88
160
  }
89
- return newMatches;
161
+ next[dragging] = answerId;
162
+ queueMicrotask(() => onChange?.(toMatches(next)));
163
+ return next;
90
164
  });
91
165
  }
92
- setDragging(null);
93
- setDragLine(null);
166
+ cancelDragging();
94
167
  };
95
- const removeMatch = (qId) => {
96
- setMatches((prev) => {
97
- const newMatches = { ...prev };
98
- delete newMatches[qId];
99
- if (onChange) {
100
- queueMicrotask(
101
- () => onChange(
102
- Object.entries(newMatches).map(([qId2, aId]) => ({
103
- questionId: Number(qId2),
104
- answerId: aId
105
- }))
106
- )
107
- );
108
- }
109
- return newMatches;
168
+ const removeMatch = (questionId) => {
169
+ setMatches((current) => {
170
+ const next = { ...current };
171
+ delete next[questionId];
172
+ queueMicrotask(() => onChange?.(toMatches(next)));
173
+ return next;
110
174
  });
111
175
  };
112
176
  useEffect(() => {
113
177
  if (dragging == null) return;
114
- const handleUp = () => {
115
- setDragging(null);
116
- setDragLine(null);
178
+ refreshDragLine();
179
+ if (autoScroll !== false && scrollFrameRef.current === null) {
180
+ scrollFrameRef.current = requestAnimationFrame(runAutoScroll);
181
+ }
182
+ const handleUp = (event) => {
183
+ if (pointerRef.current?.id === event.pointerId) cancelDragging();
117
184
  };
118
- document.addEventListener("mousemove", handleMouseMove);
119
- document.addEventListener("mouseup", handleUp);
185
+ document.addEventListener("pointermove", handlePointerMove);
186
+ document.addEventListener("pointerup", handleUp);
187
+ document.addEventListener("pointercancel", handleUp);
120
188
  return () => {
121
- document.removeEventListener("mousemove", handleMouseMove);
122
- document.removeEventListener("mouseup", handleUp);
189
+ document.removeEventListener("pointermove", handlePointerMove);
190
+ document.removeEventListener("pointerup", handleUp);
191
+ document.removeEventListener("pointercancel", handleUp);
192
+ stopAutoScroll();
123
193
  };
124
- }, [dragging, handleMouseMove]);
194
+ }, [
195
+ autoScroll,
196
+ cancelDragging,
197
+ dragging,
198
+ handlePointerMove,
199
+ refreshDragLine,
200
+ runAutoScroll,
201
+ stopAutoScroll
202
+ ]);
125
203
  useEffect(() => {
126
- if (!containerRef.current) return;
127
- const newLines = Object.entries(matches).map(([qId, aId]) => {
128
- const startEl = questionRefs.current[Number(qId)];
129
- const endEl = answerRefs.current[Number(aId)];
130
- if (!startEl || !endEl) return null;
131
- const start = getElementCenter(startEl, false);
132
- const end = getElementCenter(endEl, true);
133
- if (!start || !end) return null;
134
- return { qId, aId: aId.toString(), start, end };
135
- }).filter(Boolean);
136
- setLines(newLines);
137
- }, [matches, getElementCenter]);
204
+ refreshLines();
205
+ }, [refreshLines]);
206
+ useEffect(() => {
207
+ window.addEventListener("resize", refreshLines);
208
+ return () => window.removeEventListener("resize", refreshLines);
209
+ }, [refreshLines]);
138
210
  return /* @__PURE__ */ jsxs(
139
211
  "div",
140
212
  {
@@ -142,30 +214,41 @@ function Matching({
142
214
  ref: containerRef,
143
215
  children: [
144
216
  /* @__PURE__ */ jsxs("svg", { className: "absolute z-20 w-full h-full pointer-events-none", children: [
145
- lines.map(({ qId, aId, start, end }) => /* @__PURE__ */ jsxs("g", { children: [
146
- /* @__PURE__ */ jsx(
147
- "line",
148
- {
149
- x1: start.x,
150
- y1: start.y,
151
- x2: end.x,
152
- y2: end.y,
153
- stroke: lineColor,
154
- strokeWidth: 3,
155
- strokeLinecap: "round"
156
- }
157
- ),
158
- /* @__PURE__ */ jsx(
159
- "circle",
160
- {
161
- cx: start.x,
162
- cy: start.y,
163
- r: circleRadius,
164
- fill: circleColor
165
- }
166
- ),
167
- /* @__PURE__ */ jsx("circle", { cx: end.x, cy: end.y, r: circleRadius, fill: circleColor })
168
- ] }, `${qId}-${aId}`)),
217
+ lines.map((line) => {
218
+ const styles = getMatchStyles?.(line);
219
+ return /* @__PURE__ */ jsxs("g", { children: [
220
+ /* @__PURE__ */ jsx(
221
+ "line",
222
+ {
223
+ x1: line.start.x,
224
+ y1: line.start.y,
225
+ x2: line.end.x,
226
+ y2: line.end.y,
227
+ stroke: styles?.lineColor ?? lineColor,
228
+ strokeWidth: 3,
229
+ strokeLinecap: "round"
230
+ }
231
+ ),
232
+ /* @__PURE__ */ jsx(
233
+ "circle",
234
+ {
235
+ cx: line.start.x,
236
+ cy: line.start.y,
237
+ r: circleRadius,
238
+ fill: styles?.circleColor ?? circleColor
239
+ }
240
+ ),
241
+ /* @__PURE__ */ jsx(
242
+ "circle",
243
+ {
244
+ cx: line.end.x,
245
+ cy: line.end.y,
246
+ r: circleRadius,
247
+ fill: styles?.circleColor ?? circleColor
248
+ }
249
+ )
250
+ ] }, `${line.questionId}-${line.answerId}`);
251
+ }),
169
252
  dragLine && /* @__PURE__ */ jsxs("g", { children: [
170
253
  /* @__PURE__ */ jsx(
171
254
  "line",
@@ -180,63 +263,50 @@ function Matching({
180
263
  strokeLinecap: "round"
181
264
  }
182
265
  ),
183
- /* @__PURE__ */ jsx(
184
- "circle",
185
- {
186
- cx: dragLine.start.x,
187
- cy: dragLine.start.y,
188
- r: circleRadius,
189
- fill: circleColor
190
- }
191
- ),
192
- /* @__PURE__ */ jsx(
193
- "circle",
194
- {
195
- cx: dragLine.end.x,
196
- cy: dragLine.end.y,
197
- r: circleRadius,
198
- fill: circleColor
199
- }
200
- )
266
+ /* @__PURE__ */ jsx("circle", { cx: dragLine.start.x, cy: dragLine.start.y, r: circleRadius, fill: circleColor }),
267
+ /* @__PURE__ */ jsx("circle", { cx: dragLine.end.x, cy: dragLine.end.y, r: circleRadius, fill: circleColor })
201
268
  ] })
202
269
  ] }),
203
- /* @__PURE__ */ jsx("div", { className: "relative z-10 space-y-3", children: questions.map((q) => {
204
- const isMatched = matches[q.id] !== void 0;
270
+ /* @__PURE__ */ jsx("div", { className: "relative z-10 space-y-3", children: questions.map((question) => {
271
+ const answerId = matches[question.id];
272
+ const styles = answerId === void 0 ? void 0 : getMatchStyles?.({ questionId: question.id, answerId });
205
273
  return /* @__PURE__ */ jsx(
206
274
  "button",
207
275
  {
208
- ref: (el) => void (questionRefs.current[q.id] = el),
276
+ ref: (element) => void (questionRefs.current[question.id] = element),
209
277
  type: "button",
210
278
  disabled,
211
- onMouseDown: () => handleMouseDown(q.id),
212
- onClick: () => isMatched && removeMatch(q.id),
279
+ onPointerDown: (event) => handlePointerDown(event, question.id),
280
+ onClick: () => answerId !== void 0 && removeMatch(question.id),
213
281
  className: cn(
214
- "p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
215
- isMatched && "bg-gray-700",
216
- questionClassName
282
+ "p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
283
+ answerId !== void 0 && "bg-gray-700",
284
+ questionClassName,
285
+ styles?.questionClassName
217
286
  ),
218
- children: q.text
287
+ children: question.text
219
288
  },
220
- q.id
289
+ question.id
221
290
  );
222
291
  }) }),
223
- /* @__PURE__ */ jsx("div", { className: "relative z-10 space-y-3", children: answers.map((a) => {
224
- const isMatched = Object.values(matches).includes(a.id);
292
+ /* @__PURE__ */ jsx("div", { className: "relative z-10 space-y-3", children: answers.map((answer) => {
293
+ const answerMatches = toMatches(matches).filter((match) => match.answerId === answer.id);
225
294
  return /* @__PURE__ */ jsx(
226
295
  "button",
227
296
  {
228
- ref: (el) => void (answerRefs.current[a.id] = el),
297
+ ref: (element) => void (answerRefs.current[answer.id] = element),
229
298
  type: "button",
230
299
  disabled,
231
- onMouseUp: () => handleMouseUp(a.id),
300
+ onPointerUp: (event) => handlePointerUp(event, answer.id),
232
301
  className: cn(
233
- "p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
234
- isMatched && "bg-gray-700",
235
- answerClassName
302
+ "p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
303
+ answerMatches.length > 0 && "bg-gray-700",
304
+ answerClassName,
305
+ answerMatches.map((match) => getMatchStyles?.(match)?.answerClassName)
236
306
  ),
237
- children: a.text
307
+ children: answer.text
238
308
  },
239
- a.id
309
+ answer.id
240
310
  );
241
311
  }) })
242
312
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/matching.tsx","../src/lib/utils.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { cn } from \"./lib/utils\";\n\nexport type TMatch = {\n questionId: number;\n answerId: number;\n};\n\ntype Props = {\n questions: { id: number; text: string }[];\n answers: { id: number; text: string }[];\n className?: string;\n questionClassName?: string;\n answerClassName?: string;\n lineColor?: string;\n circleColor?: string;\n circleRadius?: number;\n offset?: number;\n disabled?: boolean;\n onChange?: (matches: TMatch[]) => void;\n};\n\ntype Line = {\n qId: string;\n aId: string;\n start: { x: number; y: number };\n end: { x: number; y: number };\n};\n\nexport function Matching({\n questions,\n answers,\n className,\n questionClassName,\n answerClassName,\n lineColor = \"black\",\n circleColor = \"white\",\n circleRadius = 8,\n offset = 10,\n disabled,\n onChange,\n}: Props) {\n const [matches, setMatches] = useState<Record<number, number>>({});\n const [lines, setLines] = useState<Line[]>([]);\n const [dragging, setDragging] = useState<number | null>(null);\n const [dragLine, setDragLine] = useState<{\n start: { x: number; y: number };\n end: { x: number; y: number };\n questionId: number;\n } | null>(null);\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const questionRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const answerRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n\n const getElementCenter = useCallback(\n (el: HTMLElement | null, isAnswer = false) => {\n if (!el || !containerRef.current) return null;\n const rect = el.getBoundingClientRect();\n const containerRect = containerRef.current.getBoundingClientRect();\n return {\n x: isAnswer\n ? rect.left - containerRect.left + circleRadius + offset\n : rect.right - containerRect.left - circleRadius - offset,\n y: rect.top + rect.height / 2 - containerRect.top,\n };\n },\n [circleRadius, offset]\n );\n\n const handleMouseDown = (qId: number) => {\n if (disabled) return;\n setDragging(qId);\n requestAnimationFrame(() => {\n const start = getElementCenter(questionRefs.current[qId]);\n if (start) setDragLine({ start, end: start, questionId: qId });\n });\n };\n\n const handleMouseMove = useCallback(\n (e: MouseEvent) => {\n if (dragging == null || !containerRef.current) return;\n const rect = containerRef.current.getBoundingClientRect();\n setDragLine((prev) =>\n prev\n ? {\n ...prev,\n end: { x: e.clientX - rect.left, y: e.clientY - rect.top },\n }\n : null\n );\n },\n [dragging]\n );\n\n const handleMouseUp = (aId: number) => {\n if (dragging != null) {\n setMatches((prev) => {\n const newMatches = { ...prev, [dragging]: aId };\n if (onChange) {\n // notify parent immediately on every change\n queueMicrotask(() =>\n onChange(\n Object.entries(newMatches).map(([qId, aId]) => ({\n questionId: Number(qId),\n answerId: aId,\n }))\n )\n );\n }\n return newMatches;\n });\n }\n setDragging(null);\n setDragLine(null);\n };\n\n const removeMatch = (qId: number) => {\n setMatches((prev) => {\n const newMatches = { ...prev };\n delete newMatches[qId];\n if (onChange) {\n queueMicrotask(() =>\n onChange(\n Object.entries(newMatches).map(([qId, aId]) => ({\n questionId: Number(qId),\n answerId: aId,\n }))\n )\n );\n }\n return newMatches;\n });\n };\n\n useEffect(() => {\n if (dragging == null) return;\n const handleUp = () => {\n setDragging(null);\n setDragLine(null);\n };\n document.addEventListener(\"mousemove\", handleMouseMove);\n document.addEventListener(\"mouseup\", handleUp);\n return () => {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n document.removeEventListener(\"mouseup\", handleUp);\n };\n }, [dragging, handleMouseMove]);\n\n useEffect(() => {\n if (!containerRef.current) return;\n\n const newLines: Line[] = Object.entries(matches)\n .map(([qId, aId]) => {\n const startEl = questionRefs.current[Number(qId)];\n const endEl = answerRefs.current[Number(aId)];\n if (!startEl || !endEl) return null;\n const start = getElementCenter(startEl, false);\n const end = getElementCenter(endEl, true);\n if (!start || !end) return null;\n return { qId, aId: aId.toString(), start, end };\n })\n .filter(Boolean) as Line[];\n\n setLines(newLines);\n }, [matches, getElementCenter]);\n\n return (\n <div\n className={cn(\"grid relative grid-cols-2 gap-10 select-none\", className)}\n ref={containerRef}\n >\n <svg className=\"absolute z-20 w-full h-full pointer-events-none\">\n {lines.map(({ qId, aId, start, end }) => (\n <g key={`${qId}-${aId}`}>\n <line\n x1={start.x}\n y1={start.y}\n x2={end.x}\n y2={end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeLinecap=\"round\"\n />\n <circle\n cx={start.x}\n cy={start.y}\n r={circleRadius}\n fill={circleColor}\n />\n <circle cx={end.x} cy={end.y} r={circleRadius} fill={circleColor} />\n </g>\n ))}\n {dragLine && (\n <g>\n <line\n x1={dragLine.start.x}\n y1={dragLine.start.y}\n x2={dragLine.end.x}\n y2={dragLine.end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeDasharray=\"5,5\"\n strokeLinecap=\"round\"\n />\n <circle\n cx={dragLine.start.x}\n cy={dragLine.start.y}\n r={circleRadius}\n fill={circleColor}\n />\n <circle\n cx={dragLine.end.x}\n cy={dragLine.end.y}\n r={circleRadius}\n fill={circleColor}\n />\n </g>\n )}\n </svg>\n\n <div className=\"relative z-10 space-y-3\">\n {questions.map((q) => {\n const isMatched = matches[q.id] !== undefined;\n return (\n <button\n key={q.id}\n ref={(el) => void (questionRefs.current[q.id] = el)}\n type=\"button\"\n disabled={disabled}\n onMouseDown={() => handleMouseDown(q.id)}\n onClick={() => isMatched && removeMatch(q.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n isMatched && \"bg-gray-700\",\n questionClassName\n )}\n >\n {q.text}\n </button>\n );\n })}\n </div>\n\n <div className=\"relative z-10 space-y-3\">\n {answers.map((a) => {\n const isMatched = Object.values(matches).includes(a.id);\n return (\n <button\n key={a.id}\n ref={(el) => void (answerRefs.current[a.id] = el)}\n type=\"button\"\n disabled={disabled}\n onMouseUp={() => handleMouseUp(a.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n isMatched && \"bg-gray-700\",\n answerClassName\n )}\n >\n {a.text}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;;;ACAzD,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MA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,EAAE;AAAA,UAaT;AAAA,QAEJ,CAAC,GACH;AAAA,QAEA,oBAAC,SAAI,WAAU,2BACZ,kBAAQ,IAAI,CAAC,MAAM;AAClB,gBAAM,YAAY,OAAO,OAAO,OAAO,EAAE,SAAS,EAAE,EAAE;AACtD,iBACE;AAAA,YAAC;AAAA;AAAA,cAEC,KAAK,CAAC,OAAO,MAAM,WAAW,QAAQ,EAAE,EAAE,IAAI;AAAA,cAC9C,MAAK;AAAA,cACL;AAAA,cACA,WAAW,MAAM,cAAc,EAAE,EAAE;AAAA,cACnC,WAAW;AAAA,gBACT;AAAA,gBACA,aAAa;AAAA,gBACb;AAAA,cACF;AAAA,cAEC,YAAE;AAAA;AAAA,YAXE,EAAE;AAAA,UAYT;AAAA,QAEJ,CAAC,GACH;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["aId","qId"]}
1
+ {"version":3,"sources":["../src/matching.tsx","../src/lib/utils.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { cn } from \"./lib/utils\";\n\nexport type TMatch = {\n questionId: number;\n answerId: number;\n};\n\nexport type TMatchStyles = {\n lineColor?: string;\n circleColor?: string;\n questionClassName?: string;\n answerClassName?: string;\n};\n\nexport type TAutoScrollOptions = {\n edgeThreshold?: number;\n maxSpeed?: number;\n};\n\nexport type MatchingProps = {\n questions: { id: number; text: string }[];\n answers: { id: number; text: string }[];\n className?: string;\n questionClassName?: string;\n answerClassName?: string;\n lineColor?: string;\n circleColor?: string;\n circleRadius?: number;\n offset?: number;\n disabled?: boolean;\n allowAnswerReuse?: boolean;\n autoScroll?: boolean | TAutoScrollOptions;\n getMatchStyles?: (match: TMatch) => TMatchStyles | undefined;\n onChange?: (matches: TMatch[]) => void;\n};\n\ntype Point = { x: number; y: number };\n\ntype Line = TMatch & {\n start: Point;\n end: Point;\n};\n\nconst DEFAULT_EDGE_THRESHOLD = 64;\nconst DEFAULT_MAX_SCROLL_SPEED = 16;\n\nfunction toMatches(matches: Record<number, number>): TMatch[] {\n return Object.entries(matches).map(([questionId, answerId]) => ({\n questionId: Number(questionId),\n answerId,\n }));\n}\n\nfunction findScrollableAncestor(element: HTMLElement): HTMLElement {\n let current = element.parentElement;\n\n while (current) {\n const { overflowY } = window.getComputedStyle(current);\n if (/(auto|scroll|overlay)/.test(overflowY) && current.scrollHeight > current.clientHeight) {\n return current;\n }\n current = current.parentElement;\n }\n\n return (document.scrollingElement as HTMLElement | null) ?? document.documentElement;\n}\n\nexport function Matching({\n questions,\n answers,\n className,\n questionClassName,\n answerClassName,\n lineColor = \"black\",\n circleColor = \"white\",\n circleRadius = 8,\n offset = 10,\n disabled,\n allowAnswerReuse = false,\n autoScroll = true,\n getMatchStyles,\n onChange,\n}: MatchingProps) {\n const [matches, setMatches] = useState<Record<number, number>>({});\n const [lines, setLines] = useState<Line[]>([]);\n const [dragging, setDragging] = useState<number | null>(null);\n const [dragLine, setDragLine] = useState<{ start: Point; end: Point } | null>(null);\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const questionRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const answerRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const pointerRef = useRef<{ id: number; clientX: number; clientY: number } | null>(null);\n const scrollElementRef = useRef<HTMLElement | null>(null);\n const scrollFrameRef = useRef<number | null>(null);\n\n const getElementCenter = useCallback(\n (element: HTMLElement | null, isAnswer = false) => {\n if (!element || !containerRef.current) return null;\n const rect = element.getBoundingClientRect();\n const containerRect = containerRef.current.getBoundingClientRect();\n return {\n x: isAnswer\n ? rect.left - containerRect.left + circleRadius + offset\n : rect.right - containerRect.left - circleRadius - offset,\n y: rect.top + rect.height / 2 - containerRect.top,\n };\n },\n [circleRadius, offset]\n );\n\n const refreshLines = useCallback(() => {\n const nextLines = toMatches(matches)\n .map(({ questionId, answerId }) => {\n const start = getElementCenter(questionRefs.current[questionId]);\n const end = getElementCenter(answerRefs.current[answerId], true);\n return start && end ? { questionId, answerId, start, end } : null;\n })\n .filter((line): line is Line => line !== null);\n\n setLines(nextLines);\n }, [getElementCenter, matches]);\n\n const refreshDragLine = useCallback(() => {\n if (dragging == null || !containerRef.current || !pointerRef.current) return;\n const start = getElementCenter(questionRefs.current[dragging]);\n if (!start) return;\n const rect = containerRef.current.getBoundingClientRect();\n setDragLine({\n start,\n end: {\n x: pointerRef.current.clientX - rect.left,\n y: pointerRef.current.clientY - rect.top,\n },\n });\n }, [dragging, getElementCenter]);\n\n const stopAutoScroll = useCallback(() => {\n if (scrollFrameRef.current !== null) cancelAnimationFrame(scrollFrameRef.current);\n scrollFrameRef.current = null;\n scrollElementRef.current = null;\n }, []);\n\n const runAutoScroll = useCallback(() => {\n scrollFrameRef.current = null;\n if (autoScroll === false || dragging == null || !pointerRef.current) return;\n\n const scrollElement = scrollElementRef.current;\n if (!scrollElement) return;\n\n const isDocument = scrollElement === document.scrollingElement;\n const rect = isDocument\n ? { top: 0, bottom: window.innerHeight }\n : scrollElement.getBoundingClientRect();\n const edgeThreshold =\n typeof autoScroll === \"object\"\n ? (autoScroll.edgeThreshold ?? DEFAULT_EDGE_THRESHOLD)\n : DEFAULT_EDGE_THRESHOLD;\n const maxSpeed =\n typeof autoScroll === \"object\"\n ? (autoScroll.maxSpeed ?? DEFAULT_MAX_SCROLL_SPEED)\n : DEFAULT_MAX_SCROLL_SPEED;\n const { clientY } = pointerRef.current;\n let speed = 0;\n\n if (clientY < rect.top + edgeThreshold) {\n speed = -maxSpeed * (1 - Math.max(0, clientY - rect.top) / edgeThreshold);\n } else if (clientY > rect.bottom - edgeThreshold) {\n speed = maxSpeed * (1 - Math.max(0, rect.bottom - clientY) / edgeThreshold);\n }\n\n if (speed !== 0) {\n const previousScrollTop = scrollElement.scrollTop;\n scrollElement.scrollTop += speed;\n if (scrollElement.scrollTop !== previousScrollTop) {\n refreshLines();\n refreshDragLine();\n }\n }\n\n scrollFrameRef.current = requestAnimationFrame(runAutoScroll);\n }, [autoScroll, dragging, refreshDragLine, refreshLines]);\n\n const cancelDragging = useCallback(() => {\n setDragging(null);\n setDragLine(null);\n pointerRef.current = null;\n stopAutoScroll();\n }, [stopAutoScroll]);\n\n const handlePointerDown = (event: React.PointerEvent, questionId: number) => {\n if (disabled || !containerRef.current) return;\n event.preventDefault();\n pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };\n scrollElementRef.current = findScrollableAncestor(containerRef.current);\n setDragging(questionId);\n };\n\n const handlePointerMove = useCallback(\n (event: PointerEvent) => {\n if (dragging == null || pointerRef.current?.id !== event.pointerId) return;\n pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };\n refreshDragLine();\n },\n [dragging, refreshDragLine]\n );\n\n const handlePointerUp = (event: React.PointerEvent, answerId: number) => {\n if (dragging != null && pointerRef.current?.id === event.pointerId) {\n setMatches((current) => {\n const next = { ...current };\n if (!allowAnswerReuse) {\n for (const [questionId, matchedAnswerId] of Object.entries(next)) {\n if (matchedAnswerId === answerId) delete next[Number(questionId)];\n }\n }\n next[dragging] = answerId;\n queueMicrotask(() => onChange?.(toMatches(next)));\n return next;\n });\n }\n cancelDragging();\n };\n\n const removeMatch = (questionId: number) => {\n setMatches((current) => {\n const next = { ...current };\n delete next[questionId];\n queueMicrotask(() => onChange?.(toMatches(next)));\n return next;\n });\n };\n\n useEffect(() => {\n if (dragging == null) return;\n refreshDragLine();\n if (autoScroll !== false && scrollFrameRef.current === null) {\n scrollFrameRef.current = requestAnimationFrame(runAutoScroll);\n }\n\n const handleUp = (event: PointerEvent) => {\n if (pointerRef.current?.id === event.pointerId) cancelDragging();\n };\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handleUp);\n document.addEventListener(\"pointercancel\", handleUp);\n return () => {\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handleUp);\n document.removeEventListener(\"pointercancel\", handleUp);\n stopAutoScroll();\n };\n }, [\n autoScroll,\n cancelDragging,\n dragging,\n handlePointerMove,\n refreshDragLine,\n runAutoScroll,\n stopAutoScroll,\n ]);\n\n useEffect(() => {\n refreshLines();\n }, [refreshLines]);\n\n useEffect(() => {\n window.addEventListener(\"resize\", refreshLines);\n return () => window.removeEventListener(\"resize\", refreshLines);\n }, [refreshLines]);\n\n return (\n <div\n className={cn(\"grid relative grid-cols-2 gap-10 select-none\", className)}\n ref={containerRef}\n >\n <svg className=\"absolute z-20 w-full h-full pointer-events-none\">\n {lines.map((line) => {\n const styles = getMatchStyles?.(line);\n return (\n <g key={`${line.questionId}-${line.answerId}`}>\n <line\n x1={line.start.x}\n y1={line.start.y}\n x2={line.end.x}\n y2={line.end.y}\n stroke={styles?.lineColor ?? lineColor}\n strokeWidth={3}\n strokeLinecap=\"round\"\n />\n <circle\n cx={line.start.x}\n cy={line.start.y}\n r={circleRadius}\n fill={styles?.circleColor ?? circleColor}\n />\n <circle\n cx={line.end.x}\n cy={line.end.y}\n r={circleRadius}\n fill={styles?.circleColor ?? circleColor}\n />\n </g>\n );\n })}\n {dragLine && (\n <g>\n <line\n x1={dragLine.start.x}\n y1={dragLine.start.y}\n x2={dragLine.end.x}\n y2={dragLine.end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeDasharray=\"5,5\"\n strokeLinecap=\"round\"\n />\n <circle cx={dragLine.start.x} cy={dragLine.start.y} r={circleRadius} fill={circleColor} />\n <circle cx={dragLine.end.x} cy={dragLine.end.y} r={circleRadius} fill={circleColor} />\n </g>\n )}\n </svg>\n\n <div className=\"relative z-10 space-y-3\">\n {questions.map((question) => {\n const answerId = matches[question.id];\n const styles =\n answerId === undefined\n ? undefined\n : getMatchStyles?.({ questionId: question.id, answerId });\n return (\n <button\n key={question.id}\n ref={(element) => void (questionRefs.current[question.id] = element)}\n type=\"button\"\n disabled={disabled}\n onPointerDown={(event) => handlePointerDown(event, question.id)}\n onClick={() => answerId !== undefined && removeMatch(question.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n answerId !== undefined && \"bg-gray-700\",\n questionClassName,\n styles?.questionClassName\n )}\n >\n {question.text}\n </button>\n );\n })}\n </div>\n\n <div className=\"relative z-10 space-y-3\">\n {answers.map((answer) => {\n const answerMatches = toMatches(matches).filter((match) => match.answerId === answer.id);\n return (\n <button\n key={answer.id}\n ref={(element) => void (answerRefs.current[answer.id] = element)}\n type=\"button\"\n disabled={disabled}\n onPointerUp={(event) => handlePointerUp(event, answer.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n answerMatches.length > 0 && \"bg-gray-700\",\n answerClassName,\n answerMatches.map((match) => getMatchStyles?.(match)?.answerClassName)\n )}\n >\n {answer.text}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;;;ACAzD,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ADmRY,SACE,KADF;AA5OZ,IAAM,yBAAyB;AAC/B,IAAM,2BAA2B;AAEjC,SAAS,UAAU,SAA2C;AAC5D,SAAO,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,YAAY,QAAQ,OAAO;AAAA,IAC9D,YAAY,OAAO,UAAU;AAAA,IAC7B;AAAA,EACF,EAAE;AACJ;AAEA,SAAS,uBAAuB,SAAmC;AACjE,MAAI,UAAU,QAAQ;AAEtB,SAAO,SAAS;AACd,UAAM,EAAE,UAAU,IAAI,OAAO,iBAAiB,OAAO;AACrD,QAAI,wBAAwB,KAAK,SAAS,KAAK,QAAQ,eAAe,QAAQ,cAAc;AAC1F,aAAO;AAAA,IACT;AACA,cAAU,QAAQ;AA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T;AAAA,gBACA,cAAc,SAAS,KAAK;AAAA,gBAC5B;AAAA,gBACA,cAAc,IAAI,CAAC,UAAU,iBAAiB,KAAK,GAAG,eAAe;AAAA,cACvE;AAAA,cAEC,iBAAO;AAAA;AAAA,YAZH,OAAO;AAAA,UAad;AAAA,QAEJ,CAAC,GACH;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-matchings",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "A React component for matching questions and answers",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",