
    3fi                     >    d Z ddlZddlmZ ddlmZ  G d de      Zy)z#JavaScript framework text splitter.    N)Any)RecursiveCharacterTextSplitterc                   f     e Zd ZdZ	 	 	 ddee   dz  dedededdf
 fdZd	edee   f fd
Z	 xZ
S )JSFrameworkTextSplitteran  Text splitter that handles React (JSX), Vue, and Svelte code.

    This splitter extends RecursiveCharacterTextSplitter to handle
    React (JSX), Vue, and Svelte code by:

    1. Detecting and extracting custom component tags from the text
    2. Using those tags as additional separators along with standard JS syntax

    The splitter combines:

    * Custom component tags as separators (e.g. <Component, <div)
    * JavaScript syntax elements (function, const, if, etc)
    * Standard text splitting on newlines

    This allows chunks to break at natural boundaries in
    React, Vue, and Svelte component code.
    N
separators
chunk_sizechunk_overlapkwargsreturnc                 @    t        |   d||d| |xs g | _        y)aG  Initialize the JS Framework text splitter.

        Args:
            separators: Optional list of custom separator strings to use
            chunk_size: Maximum size of chunks to return
            chunk_overlap: Overlap in characters between chunks
            **kwargs: Additional arguments to pass to parent class
        )r   r	   N )super__init___separators)selfr   r   r	   r
   	__class__s        Z/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_text_splitters/jsx.pyr   z JSFrameworkTextSplitter.__init__   s)     	VJmVvV%+    textc                     t        j                  d|      }g }|D ]  }||vs|j                  |        |D cg c]  }d| 	 }}g d}| j                  |z   |z   g dz   }|| _        t        |   |      S c c}w )a  Split text into chunks.

        This method splits the text into chunks by:

        * Extracting unique opening component tags using regex
        * Creating separators list with extracted tags and JS separators
        * Splitting the text using the separators by calling the parent class method

        Args:
            text: String containing code to split

        Returns:
            List of text chunks split on component and JS boundaries
        z<\s*([a-zA-Z0-9]+)[^>]*><)z
export z export z

function z
async function z async function z
const z
let z
var z
class z class z
if z if z
for z for z
while z while z
switch z switch z
case z case z	
default z	 default )z<>z

z&&
z||
)refindallappendr   r   
split_text)	r   r   opening_tagscomponent_tagstagcomponent_separatorsjs_separatorsr   r   s	           r   r   z"JSFrameworkTextSplitter.split_text.   s    " zz"=tD 	+C.(%%c*	+ 6DDc!C5	DD
2 "# -- 	 &w!$''C  Es   A:)Ni  r   )__name__
__module____qualname____doc__liststrintr   r   r   __classcell__)r   s   @r   r   r   	   sm    ( (,	,I$, , 	,
 , 
,$8(s 8(tCy 8( 8(r   r   )r$   r   typingr   langchain_text_splittersr   r   r   r   r   <module>r+      s     ) 	  C](< ](r   