
    @h                     >    S SK r S SKJrJr  S SKJr   " S S\5      rg)    N)AnyOptional)RecursiveCharacterTextSplitterc                   x   ^  \ rS rSrSr   SS\\\      S\S\S\	SS4
U 4S	 jjjr
S
\S\\   4U 4S jjrSrU =r$ )JSFrameworkTextSplitter   a@  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                 J   > [         TU ]  " SX#S.UD6  U=(       d    / U l        g)a  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        T/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_text_splitters/jsx.pyr    JSFrameworkTextSplitter.__init__   s'     	VJVvV%+    textc                 
  > [         R                  " SU5      n/ nU H  nXC;  d  M
  UR                  U5        M     U Vs/ sH  nSU 3PM
     nn/ SQnU R                  U-   U-   / SQ-   nXpl        [        TU ]  U5      $ s  snf )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   "JSFrameworkTextSplitter.split_text*   s      zz"=tDC(%%c*   6DD^c!C5	^D
2 "# -- 	 &w!$''C  Es    B )r   )Ni  r   )__name__
__module____qualname____firstlineno____doc__r   liststrintr   r   r   __static_attributes____classcell__)r   s   @r   r   r      sr    $ +/	,T#Y', , 	,
 , 
, ,$7(s 7(tCy 7( 7(r   r   )r   typingr   r   langchain_text_splittersr   r   r   r   r   <module>r1      s    	   CZ(< Z(r   