react-matchings 0.0.7 → 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/dist/index.css CHANGED
@@ -1,2 +1,2 @@
1
- /*! tailwindcss v4.1.18 | 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-gradient-position:initial;--tw-gradient-from:#0000;--tw-gradient-via:#0000;--tw-gradient-to:#0000;--tw-gradient-stops:initial;--tw-gradient-via-stops:initial;--tw-gradient-from-position:0%;--tw-gradient-via-position:50%;--tw-gradient-to-position:100%;--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;--tw-duration:initial}}}@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-blue-50:oklch(97% .014 254.604);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-purple-50:oklch(97.7% .014 308.299);--color-purple-500:oklch(62.7% .265 303.9);--color-purple-600:oklch(55.8% .288 302.321);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-300:oklch(87.2% .01 258.338);--color-gray-400:oklch(70.7% .022 261.325);--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-4xl:56rem;--text-lg:1.125rem;--text-lg--line-height:calc(1.75/1.125);--text-2xl:1.5rem;--text-2xl--line-height:calc(2/1.5);--font-weight-medium:500;--font-weight-semibold:600;--font-weight-bold:700;--radius-lg:.5rem;--radius-xl:.75rem;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--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}}.mx-auto{margin-inline:auto}.my-8{margin-block:calc(var(--spacing)*8)}.mt-4{margin-top:calc(var(--spacing)*4)}.mt-6{margin-top:calc(var(--spacing)*6)}.mb-6{margin-bottom:calc(var(--spacing)*6)}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-4xl{max-width:var(--container-4xl)}.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-lg{border-radius:var(--radius-lg)}.rounded-xl{border-radius:var(--radius-xl)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-300{border-color:var(--color-gray-300)}.bg-black{background-color:var(--color-black)}.bg-blue-500{background-color:var(--color-blue-500)}.bg-gray-100{background-color:var(--color-gray-100)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-purple-500{background-color:var(--color-purple-500)}.bg-linear-to-br{--tw-gradient-position:to bottom right}@supports (background-image:linear-gradient(in lab, red, red)){.bg-linear-to-br{--tw-gradient-position:to bottom right in oklab}}.bg-linear-to-br{background-image:linear-gradient(var(--tw-gradient-stops))}.from-blue-50{--tw-gradient-from:var(--color-blue-50);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-purple-50{--tw-gradient-to:var(--color-purple-50);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.p-4{padding:calc(var(--spacing)*4)}.p-6{padding:calc(var(--spacing)*6)}.p-8{padding:calc(var(--spacing)*8)}.px-6{padding-inline:calc(var(--spacing)*6)}.py-2{padding-block:calc(var(--spacing)*2)}.text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.text-white{color:var(--color-white)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-200{--tw-duration:.2s;transition-duration:.2s}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\:bg-blue-600:hover{background-color:var(--color-blue-600)}.hover\:bg-purple-600:hover{background-color:var(--color-purple-600)}}.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}.disabled\:bg-gray-400:disabled{background-color:var(--color-gray-400)}}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-gradient-position{syntax:"*";inherits:false}@property --tw-gradient-from{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-via{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-to{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-stops{syntax:"*";inherits:false}@property --tw-gradient-via-stops{syntax:"*";inherits:false}@property --tw-gradient-from-position{syntax:"<length-percentage>";inherits:false;initial-value:0%}@property --tw-gradient-via-position{syntax:"<length-percentage>";inherits:false;initial-value:50%}@property --tw-gradient-to-position{syntax:"<length-percentage>";inherits:false;initial-value:100%}@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}@property --tw-duration{syntax:"*";inherits:false}
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-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,3 +1,12 @@
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
+ function __injectReactMatchingsCss() {
3
+ if (typeof document === "undefined" || document.getElementById("__REACT_MATCHINGS_AUTO_CSS__")) return;
4
+ const style = document.createElement("style");
5
+ style.id = "__REACT_MATCHINGS_AUTO_CSS__";
6
+ style.textContent = __REACT_MATCHINGS_AUTO_CSS__;
7
+ document.head.appendChild(style);
8
+ }
9
+ __injectReactMatchingsCss();
1
10
  "use strict";
2
11
  var __defProp = Object.defineProperty;
3
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -36,6 +45,25 @@ function cn(...inputs) {
36
45
 
37
46
  // src/matching.tsx
38
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
+ }
39
67
  function Matching({
40
68
  questions,
41
69
  answers,
@@ -47,6 +75,9 @@ function Matching({
47
75
  circleRadius = 8,
48
76
  offset = 10,
49
77
  disabled,
78
+ allowAnswerReuse = false,
79
+ autoScroll = true,
80
+ getMatchStyles,
50
81
  onChange
51
82
  }) {
52
83
  const [matches, setMatches] = (0, import_react.useState)({});
@@ -56,10 +87,13 @@ function Matching({
56
87
  const containerRef = (0, import_react.useRef)(null);
57
88
  const questionRefs = (0, import_react.useRef)({});
58
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);
59
93
  const getElementCenter = (0, import_react.useCallback)(
60
- (el, isAnswer = false) => {
61
- if (!el || !containerRef.current) return null;
62
- const rect = el.getBoundingClientRect();
94
+ (element, isAnswer = false) => {
95
+ if (!element || !containerRef.current) return null;
96
+ const rect = element.getBoundingClientRect();
63
97
  const containerRect = containerRef.current.getBoundingClientRect();
64
98
  return {
65
99
  x: isAnswer ? rect.left - containerRect.left + circleRadius + offset : rect.right - containerRect.left - circleRadius - offset,
@@ -68,90 +102,137 @@ function Matching({
68
102
  },
69
103
  [circleRadius, offset]
70
104
  );
71
- const handleMouseDown = (qId) => {
72
- if (disabled) return;
73
- setDragging(qId);
74
- requestAnimationFrame(() => {
75
- const start = getElementCenter(questionRefs.current[qId]);
76
- 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
+ }
77
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);
78
169
  };
79
- const handleMouseMove = (0, import_react.useCallback)(
80
- (e) => {
81
- if (!dragging || !containerRef.current) return;
82
- const rect = containerRef.current.getBoundingClientRect();
83
- setDragLine(
84
- (prev) => prev ? {
85
- ...prev,
86
- end: { x: e.clientX - rect.left, y: e.clientY - rect.top }
87
- } : null
88
- );
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();
89
175
  },
90
- [dragging]
176
+ [dragging, refreshDragLine]
91
177
  );
92
- const handleMouseUp = (aId) => {
93
- if (dragging != null) {
94
- setMatches((prev) => {
95
- const newMatches = { ...prev, [dragging]: aId };
96
- if (onChange) {
97
- queueMicrotask(
98
- () => onChange(
99
- Object.entries(newMatches).map(([qId, aId2]) => ({
100
- questionId: Number(qId),
101
- answerId: aId2
102
- }))
103
- )
104
- );
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
+ }
105
186
  }
106
- return newMatches;
187
+ next[dragging] = answerId;
188
+ queueMicrotask(() => onChange?.(toMatches(next)));
189
+ return next;
107
190
  });
108
191
  }
109
- setDragging(null);
110
- setDragLine(null);
192
+ cancelDragging();
111
193
  };
112
- const removeMatch = (qId) => {
113
- setMatches((prev) => {
114
- const newMatches = { ...prev };
115
- delete newMatches[qId];
116
- if (onChange) {
117
- queueMicrotask(
118
- () => onChange(
119
- Object.entries(newMatches).map(([qId2, aId]) => ({
120
- questionId: Number(qId2),
121
- answerId: aId
122
- }))
123
- )
124
- );
125
- }
126
- 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;
127
200
  });
128
201
  };
129
202
  (0, import_react.useEffect)(() => {
130
- if (!dragging) return;
131
- const handleUp = () => {
132
- setDragging(null);
133
- setDragLine(null);
203
+ if (dragging == null) return;
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();
134
210
  };
135
- document.addEventListener("mousemove", handleMouseMove);
136
- document.addEventListener("mouseup", handleUp);
211
+ document.addEventListener("pointermove", handlePointerMove);
212
+ document.addEventListener("pointerup", handleUp);
213
+ document.addEventListener("pointercancel", handleUp);
137
214
  return () => {
138
- document.removeEventListener("mousemove", handleMouseMove);
139
- document.removeEventListener("mouseup", handleUp);
215
+ document.removeEventListener("pointermove", handlePointerMove);
216
+ document.removeEventListener("pointerup", handleUp);
217
+ document.removeEventListener("pointercancel", handleUp);
218
+ stopAutoScroll();
140
219
  };
141
- }, [dragging, handleMouseMove]);
220
+ }, [
221
+ autoScroll,
222
+ cancelDragging,
223
+ dragging,
224
+ handlePointerMove,
225
+ refreshDragLine,
226
+ runAutoScroll,
227
+ stopAutoScroll
228
+ ]);
229
+ (0, import_react.useEffect)(() => {
230
+ refreshLines();
231
+ }, [refreshLines]);
142
232
  (0, import_react.useEffect)(() => {
143
- if (!containerRef.current) return;
144
- const newLines = Object.entries(matches).map(([qId, aId]) => {
145
- const startEl = questionRefs.current[Number(qId)];
146
- const endEl = answerRefs.current[Number(aId)];
147
- if (!startEl || !endEl) return null;
148
- const start = getElementCenter(startEl, false);
149
- const end = getElementCenter(endEl, true);
150
- if (!start || !end) return null;
151
- return { qId, aId: aId.toString(), start, end };
152
- }).filter(Boolean);
153
- setLines(newLines);
154
- }, [matches, getElementCenter]);
233
+ window.addEventListener("resize", refreshLines);
234
+ return () => window.removeEventListener("resize", refreshLines);
235
+ }, [refreshLines]);
155
236
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
156
237
  "div",
157
238
  {
@@ -159,30 +240,41 @@ function Matching({
159
240
  ref: containerRef,
160
241
  children: [
161
242
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { className: "absolute z-20 w-full h-full pointer-events-none", children: [
162
- lines.map(({ qId, aId, start, end }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
163
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
164
- "line",
165
- {
166
- x1: start.x,
167
- y1: start.y,
168
- x2: end.x,
169
- y2: end.y,
170
- stroke: lineColor,
171
- strokeWidth: 3,
172
- strokeLinecap: "round"
173
- }
174
- ),
175
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
176
- "circle",
177
- {
178
- cx: start.x,
179
- cy: start.y,
180
- r: circleRadius,
181
- fill: circleColor
182
- }
183
- ),
184
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: end.x, cy: end.y, r: circleRadius, fill: circleColor })
185
- ] }, `${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
+ }),
186
278
  dragLine && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
187
279
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
188
280
  "line",
@@ -197,61 +289,50 @@ function Matching({
197
289
  strokeLinecap: "round"
198
290
  }
199
291
  ),
200
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
201
- "circle",
202
- {
203
- cx: dragLine.start.x,
204
- cy: dragLine.start.y,
205
- r: circleRadius,
206
- fill: circleColor
207
- }
208
- ),
209
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
210
- "circle",
211
- {
212
- cx: dragLine.end.x,
213
- cy: dragLine.end.y,
214
- r: circleRadius,
215
- fill: circleColor
216
- }
217
- )
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 })
218
294
  ] })
219
295
  ] }),
220
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "relative z-10 space-y-3", children: questions.map((q) => {
221
- 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 });
222
299
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
223
300
  "button",
224
301
  {
225
- ref: (el) => void (questionRefs.current[q.id] = el),
302
+ ref: (element) => void (questionRefs.current[question.id] = element),
226
303
  type: "button",
227
- onMouseDown: () => handleMouseDown(q.id),
228
- onClick: () => isMatched && removeMatch(q.id),
304
+ disabled,
305
+ onPointerDown: (event) => handlePointerDown(event, question.id),
306
+ onClick: () => answerId !== void 0 && removeMatch(question.id),
229
307
  className: cn(
230
- "p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
231
- isMatched && "bg-gray-700",
232
- 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
233
312
  ),
234
- children: q.text
313
+ children: question.text
235
314
  },
236
- q.id
315
+ question.id
237
316
  );
238
317
  }) }),
239
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "relative z-10 space-y-3", children: answers.map((a) => {
240
- 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);
241
320
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
242
321
  "button",
243
322
  {
244
- ref: (el) => void (answerRefs.current[a.id] = el),
323
+ ref: (element) => void (answerRefs.current[answer.id] = element),
245
324
  type: "button",
246
- onMouseUp: () => handleMouseUp(a.id),
325
+ disabled,
326
+ onPointerUp: (event) => handlePointerUp(event, answer.id),
247
327
  className: cn(
248
- "p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
249
- isMatched && "bg-gray-700",
250
- 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)
251
332
  ),
252
- children: a.text
333
+ children: answer.text
253
334
  },
254
- a.id
335
+ answer.id
255
336
  );
256
337
  }) })
257
338
  ]
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/matching.tsx","../src/lib/utils.ts"],"sourcesContent":["import \"./index.css\";\r\nexport { Matching } from \"./matching\";\r\nexport type { TMatch } from \"./matching\";\r\n","import { useCallback, useEffect, useRef, useState } from \"react\";\r\nimport { cn } from \"./lib/utils\";\r\n\r\nexport type TMatch = {\r\n questionId: number;\r\n answerId: number;\r\n};\r\n\r\ntype Props = {\r\n questions: { id: number; text: string }[];\r\n answers: { id: number; text: string }[];\r\n className?: string;\r\n questionClassName?: string;\r\n answerClassName?: string;\r\n lineColor?: string;\r\n circleColor?: string;\r\n circleRadius?: number;\r\n offset?: number;\r\n disabled?: boolean;\r\n onChange?: (matches: TMatch[]) => void;\r\n};\r\n\r\ntype Line = {\r\n qId: string;\r\n aId: string;\r\n start: { x: number; y: number };\r\n end: { x: number; y: number };\r\n};\r\n\r\nexport function Matching({\r\n questions,\r\n answers,\r\n className,\r\n questionClassName,\r\n answerClassName,\r\n lineColor = \"black\",\r\n circleColor = \"white\",\r\n circleRadius = 8,\r\n offset = 10,\r\n disabled,\r\n onChange,\r\n}: Props) {\r\n const [matches, setMatches] = useState<Record<number, number>>({});\r\n const [lines, setLines] = useState<Line[]>([]);\r\n const [dragging, setDragging] = useState<number | null>(null);\r\n const [dragLine, setDragLine] = useState<{\r\n start: { x: number; y: number };\r\n end: { x: number; y: number };\r\n questionId: number;\r\n } | null>(null);\r\n\r\n const containerRef = useRef<HTMLDivElement | null>(null);\r\n const questionRefs = useRef<Record<number, HTMLButtonElement | null>>({});\r\n const answerRefs = useRef<Record<number, HTMLButtonElement | null>>({});\r\n\r\n const getElementCenter = useCallback(\r\n (el: HTMLElement | null, isAnswer = false) => {\r\n if (!el || !containerRef.current) return null;\r\n const rect = el.getBoundingClientRect();\r\n const containerRect = containerRef.current.getBoundingClientRect();\r\n return {\r\n x: isAnswer\r\n ? rect.left - containerRect.left + circleRadius + offset\r\n : rect.right - containerRect.left - circleRadius - offset,\r\n y: rect.top + rect.height / 2 - containerRect.top,\r\n };\r\n },\r\n [circleRadius, offset]\r\n );\r\n\r\n const handleMouseDown = (qId: number) => {\r\n if (disabled) return;\r\n setDragging(qId);\r\n requestAnimationFrame(() => {\r\n const start = getElementCenter(questionRefs.current[qId]);\r\n if (start) setDragLine({ start, end: start, questionId: qId });\r\n });\r\n };\r\n\r\n const handleMouseMove = useCallback(\r\n (e: MouseEvent) => {\r\n if (!dragging || !containerRef.current) return;\r\n const rect = containerRef.current.getBoundingClientRect();\r\n setDragLine((prev) =>\r\n prev\r\n ? {\r\n ...prev,\r\n end: { x: e.clientX - rect.left, y: e.clientY - rect.top },\r\n }\r\n : null\r\n );\r\n },\r\n [dragging]\r\n );\r\n\r\n const handleMouseUp = (aId: number) => {\r\n if (dragging != null) {\r\n setMatches((prev) => {\r\n const newMatches = { ...prev, [dragging]: aId };\r\n if (onChange) {\r\n // notify parent immediately on every change\r\n queueMicrotask(() =>\r\n onChange(\r\n Object.entries(newMatches).map(([qId, aId]) => ({\r\n questionId: Number(qId),\r\n answerId: aId,\r\n }))\r\n )\r\n );\r\n }\r\n return newMatches;\r\n });\r\n }\r\n setDragging(null);\r\n setDragLine(null);\r\n };\r\n\r\n const removeMatch = (qId: number) => {\r\n setMatches((prev) => {\r\n const newMatches = { ...prev };\r\n delete newMatches[qId];\r\n if (onChange) {\r\n queueMicrotask(() =>\r\n onChange(\r\n Object.entries(newMatches).map(([qId, aId]) => ({\r\n questionId: Number(qId),\r\n answerId: aId,\r\n }))\r\n )\r\n );\r\n }\r\n return newMatches;\r\n });\r\n };\r\n\r\n useEffect(() => {\r\n if (!dragging) return;\r\n const handleUp = () => {\r\n setDragging(null);\r\n setDragLine(null);\r\n };\r\n document.addEventListener(\"mousemove\", handleMouseMove);\r\n document.addEventListener(\"mouseup\", handleUp);\r\n return () => {\r\n document.removeEventListener(\"mousemove\", handleMouseMove);\r\n document.removeEventListener(\"mouseup\", handleUp);\r\n };\r\n }, [dragging, handleMouseMove]);\r\n\r\n useEffect(() => {\r\n if (!containerRef.current) return;\r\n\r\n const newLines: Line[] = Object.entries(matches)\r\n .map(([qId, aId]) => {\r\n const startEl = questionRefs.current[Number(qId)];\r\n const endEl = answerRefs.current[Number(aId)];\r\n if (!startEl || !endEl) return null;\r\n const start = getElementCenter(startEl, false);\r\n const end = getElementCenter(endEl, true);\r\n if (!start || !end) return null;\r\n return { qId, aId: aId.toString(), start, end };\r\n })\r\n .filter(Boolean) as Line[];\r\n\r\n setLines(newLines);\r\n }, [matches, getElementCenter]);\r\n\r\n return (\r\n <div\r\n className={cn(\"grid relative grid-cols-2 gap-10 select-none\", className)}\r\n ref={containerRef}\r\n >\r\n <svg className=\"absolute z-20 w-full h-full pointer-events-none\">\r\n {lines.map(({ qId, aId, start, end }) => (\r\n <g key={`${qId}-${aId}`}>\r\n <line\r\n x1={start.x}\r\n y1={start.y}\r\n x2={end.x}\r\n y2={end.y}\r\n stroke={lineColor}\r\n strokeWidth={3}\r\n strokeLinecap=\"round\"\r\n />\r\n <circle\r\n cx={start.x}\r\n cy={start.y}\r\n r={circleRadius}\r\n fill={circleColor}\r\n />\r\n <circle cx={end.x} cy={end.y} r={circleRadius} fill={circleColor} />\r\n </g>\r\n ))}\r\n {dragLine && (\r\n <g>\r\n <line\r\n x1={dragLine.start.x}\r\n y1={dragLine.start.y}\r\n x2={dragLine.end.x}\r\n y2={dragLine.end.y}\r\n stroke={lineColor}\r\n strokeWidth={3}\r\n strokeDasharray=\"5,5\"\r\n strokeLinecap=\"round\"\r\n />\r\n <circle\r\n cx={dragLine.start.x}\r\n cy={dragLine.start.y}\r\n r={circleRadius}\r\n fill={circleColor}\r\n />\r\n <circle\r\n cx={dragLine.end.x}\r\n cy={dragLine.end.y}\r\n r={circleRadius}\r\n fill={circleColor}\r\n />\r\n </g>\r\n )}\r\n </svg>\r\n\r\n <div className=\"relative z-10 space-y-3\">\r\n {questions.map((q) => {\r\n const isMatched = matches[q.id] !== undefined;\r\n return (\r\n <button\r\n key={q.id}\r\n ref={(el) => void (questionRefs.current[q.id] = el)}\r\n type=\"button\"\r\n onMouseDown={() => handleMouseDown(q.id)}\r\n onClick={() => isMatched && removeMatch(q.id)}\r\n className={cn(\r\n \"p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\r\n isMatched && \"bg-gray-700\",\r\n questionClassName\r\n )}\r\n >\r\n {q.text}\r\n </button>\r\n );\r\n })}\r\n </div>\r\n\r\n <div className=\"relative z-10 space-y-3\">\r\n {answers.map((a) => {\r\n const isMatched = Object.values(matches).includes(a.id);\r\n return (\r\n <button\r\n key={a.id}\r\n ref={(el) => void (answerRefs.current[a.id] = el)}\r\n type=\"button\"\r\n onMouseUp={() => handleMouseUp(a.id)}\r\n className={cn(\r\n \"p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\r\n isMatched && \"bg-gray-700\",\r\n answerClassName\r\n )}\r\n >\r\n {a.text}\r\n </button>\r\n );\r\n })}\r\n </div>\r\n </div>\r\n );\r\n}\r\n","import { clsx, type ClassValue } from \"clsx\";\r\nimport { twMerge } from \"tailwind-merge\";\r\n\r\nexport function cn(...inputs: ClassValue[]) {\r\n return twMerge(clsx(inputs));\r\n}\r\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,CA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A,gBACA,aAAa;AAAA,gBACb;AAAA,cACF;AAAA,cAEC,YAAE;AAAA;AAAA,YAVE,EAAE;AAAA,UAWT;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;;;ACAzD,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AAC1C,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC7B;;;ADmRY;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;AAAA,EACpB;AAEA,SAAQ,SAAS,oBAA2C,SAAS;AACvE;AAEO,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,mBAAmB;AAAA,EACnB,aAAa;AAAA,EACb;AAAA,EACA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