freddyaboulton HF Staff commited on
Commit
697b048
·
verified ·
1 Parent(s): ce98d80

Delete src

Browse files
src/.DS_Store DELETED
Binary file (6.15 kB)
 
src/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- .eggs/
2
- dist/
3
- *.pyc
4
- __pycache__/
5
- *.py[cod]
6
- *$py.class
7
- __tmp/*
8
- *.pyi
9
- node_modules
10
- templates/
 
 
 
 
 
 
 
 
 
 
 
src/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Freddy Boulton
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/README.md DELETED
@@ -1,286 +0,0 @@
1
-
2
- # `gradio_pdf`
3
- <a href="https://pypi.org/project/gradio_pdf/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_pdf"></a> <a href="https://github.com/freddyaboulton/gradio-pdf/issues" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Issues-white?logo=github&logoColor=black"></a> <a href="https://huggingface.co/spaces/freddyaboulton/gradio_pdf/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
4
-
5
- Easily display PDFs in Gradio
6
-
7
- ## Installation
8
-
9
- ```bash
10
- pip install gradio_pdf
11
- ```
12
-
13
- ## Usage
14
-
15
- ```python
16
-
17
- import gradio as gr
18
- from gradio_pdf import PDF
19
- from pdf2image import convert_from_path
20
- from transformers import pipeline
21
- from pathlib import Path
22
-
23
- dir_ = Path(__file__).parent
24
-
25
- p = pipeline(
26
- "document-question-answering",
27
- model="impira/layoutlm-document-qa",
28
- )
29
-
30
- def qa(question: str, doc: str) -> str:
31
- img = convert_from_path(doc)[0]
32
- output = p(img, question)
33
- return sorted(output, key=lambda x: x["score"], reverse=True)[0]['answer']
34
-
35
-
36
- demo = gr.Interface(
37
- qa,
38
- [gr.Textbox(label="Question"), PDF(label="Document")],
39
- gr.Textbox(),
40
- examples=[["What is the total gross worth?", str(dir_ / "invoice_2.pdf")],
41
- ["Whos is being invoiced?", str(dir_ / "sample_invoice.pdf")]]
42
- )
43
-
44
- if __name__ == "__main__":
45
- demo.launch()
46
-
47
- ```
48
-
49
- ## `PDF`
50
-
51
- ### Initialization
52
-
53
- <table>
54
- <thead>
55
- <tr>
56
- <th align="left">name</th>
57
- <th align="left" style="width: 25%;">type</th>
58
- <th align="left">default</th>
59
- <th align="left">description</th>
60
- </tr>
61
- </thead>
62
- <tbody>
63
- <tr>
64
- <td align="left"><code>value</code></td>
65
- <td align="left" style="width: 25%;">
66
-
67
- ```python
68
- Any
69
- ```
70
-
71
- </td>
72
- <td align="left"><code>None</code></td>
73
- <td align="left">None</td>
74
- </tr>
75
-
76
- <tr>
77
- <td align="left"><code>height</code></td>
78
- <td align="left" style="width: 25%;">
79
-
80
- ```python
81
- int | None
82
- ```
83
-
84
- </td>
85
- <td align="left"><code>None</code></td>
86
- <td align="left">None</td>
87
- </tr>
88
-
89
- <tr>
90
- <td align="left"><code>label</code></td>
91
- <td align="left" style="width: 25%;">
92
-
93
- ```python
94
- str | None
95
- ```
96
-
97
- </td>
98
- <td align="left"><code>None</code></td>
99
- <td align="left">None</td>
100
- </tr>
101
-
102
- <tr>
103
- <td align="left"><code>info</code></td>
104
- <td align="left" style="width: 25%;">
105
-
106
- ```python
107
- str | None
108
- ```
109
-
110
- </td>
111
- <td align="left"><code>None</code></td>
112
- <td align="left">None</td>
113
- </tr>
114
-
115
- <tr>
116
- <td align="left"><code>show_label</code></td>
117
- <td align="left" style="width: 25%;">
118
-
119
- ```python
120
- bool | None
121
- ```
122
-
123
- </td>
124
- <td align="left"><code>None</code></td>
125
- <td align="left">None</td>
126
- </tr>
127
-
128
- <tr>
129
- <td align="left"><code>container</code></td>
130
- <td align="left" style="width: 25%;">
131
-
132
- ```python
133
- bool
134
- ```
135
-
136
- </td>
137
- <td align="left"><code>True</code></td>
138
- <td align="left">None</td>
139
- </tr>
140
-
141
- <tr>
142
- <td align="left"><code>scale</code></td>
143
- <td align="left" style="width: 25%;">
144
-
145
- ```python
146
- int | None
147
- ```
148
-
149
- </td>
150
- <td align="left"><code>None</code></td>
151
- <td align="left">None</td>
152
- </tr>
153
-
154
- <tr>
155
- <td align="left"><code>min_width</code></td>
156
- <td align="left" style="width: 25%;">
157
-
158
- ```python
159
- int | None
160
- ```
161
-
162
- </td>
163
- <td align="left"><code>None</code></td>
164
- <td align="left">None</td>
165
- </tr>
166
-
167
- <tr>
168
- <td align="left"><code>interactive</code></td>
169
- <td align="left" style="width: 25%;">
170
-
171
- ```python
172
- bool | None
173
- ```
174
-
175
- </td>
176
- <td align="left"><code>None</code></td>
177
- <td align="left">None</td>
178
- </tr>
179
-
180
- <tr>
181
- <td align="left"><code>visible</code></td>
182
- <td align="left" style="width: 25%;">
183
-
184
- ```python
185
- bool
186
- ```
187
-
188
- </td>
189
- <td align="left"><code>True</code></td>
190
- <td align="left">None</td>
191
- </tr>
192
-
193
- <tr>
194
- <td align="left"><code>elem_id</code></td>
195
- <td align="left" style="width: 25%;">
196
-
197
- ```python
198
- str | None
199
- ```
200
-
201
- </td>
202
- <td align="left"><code>None</code></td>
203
- <td align="left">None</td>
204
- </tr>
205
-
206
- <tr>
207
- <td align="left"><code>elem_classes</code></td>
208
- <td align="left" style="width: 25%;">
209
-
210
- ```python
211
- list[str] | str | None
212
- ```
213
-
214
- </td>
215
- <td align="left"><code>None</code></td>
216
- <td align="left">None</td>
217
- </tr>
218
-
219
- <tr>
220
- <td align="left"><code>render</code></td>
221
- <td align="left" style="width: 25%;">
222
-
223
- ```python
224
- bool
225
- ```
226
-
227
- </td>
228
- <td align="left"><code>True</code></td>
229
- <td align="left">None</td>
230
- </tr>
231
-
232
- <tr>
233
- <td align="left"><code>load_fn</code></td>
234
- <td align="left" style="width: 25%;">
235
-
236
- ```python
237
- Callable[..., Any] | None
238
- ```
239
-
240
- </td>
241
- <td align="left"><code>None</code></td>
242
- <td align="left">None</td>
243
- </tr>
244
-
245
- <tr>
246
- <td align="left"><code>every</code></td>
247
- <td align="left" style="width: 25%;">
248
-
249
- ```python
250
- float | None
251
- ```
252
-
253
- </td>
254
- <td align="left"><code>None</code></td>
255
- <td align="left">None</td>
256
- </tr>
257
- </tbody></table>
258
-
259
-
260
- ### Events
261
-
262
- | name | description |
263
- |:-----|:------------|
264
- | `change` | |
265
- | `upload` | |
266
-
267
-
268
-
269
- ### User function
270
-
271
- The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
272
-
273
- - When used as an Input, the component only impacts the input signature of the user function.
274
- - When used as an output, the component only impacts the return signature of the user function.
275
-
276
- The code snippet below is accurate in cases where the component is used as both an input and an output.
277
-
278
-
279
-
280
- ```python
281
- def predict(
282
- value: str
283
- ) -> str | None:
284
- return value
285
- ```
286
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/backend/gradio_pdf/__init__.py DELETED
@@ -1,4 +0,0 @@
1
-
2
- from .pdf import PDF
3
-
4
- __all__ = ['PDF']
 
 
 
 
 
src/backend/gradio_pdf/pdf.py DELETED
@@ -1,50 +0,0 @@
1
- from __future__ import annotations
2
- from typing import Any, Callable
3
-
4
- from gradio.components.base import Component
5
- from gradio.data_classes import FileData
6
- from gradio import processing_utils
7
-
8
- class PDF(Component):
9
-
10
- EVENTS = ["change", "upload"]
11
-
12
- data_model = FileData
13
-
14
- def __init__(self, value: Any = None, *,
15
- height: int | None = None,
16
- label: str | None = None, info: str | None = None,
17
- show_label: bool | None = None,
18
- container: bool = True,
19
- scale: int | None = None,
20
- min_width: int | None = None,
21
- interactive: bool | None = None,
22
- visible: bool = True,
23
- elem_id: str | None = None,
24
- elem_classes: list[str] | str | None = None,
25
- render: bool = True,
26
- load_fn: Callable[..., Any] | None = None,
27
- every: float | None = None):
28
- super().__init__(value, label=label, info=info,
29
- show_label=show_label, container=container,
30
- scale=scale, min_width=min_width,
31
- interactive=interactive, visible=visible,
32
- elem_id=elem_id, elem_classes=elem_classes,
33
- render=render, load_fn=load_fn, every=every)
34
- self.height = height
35
-
36
- def preprocess(self, payload: FileData) -> str:
37
- return payload.path
38
-
39
- def postprocess(self, value: str | None) -> FileData:
40
- if not value:
41
- return None
42
- return FileData(path=value)
43
-
44
- def example_inputs(self):
45
- return "https://gradio-builds.s3.amazonaws.com/assets/pdf-guide/fw9.pdf"
46
-
47
- def as_example(self, input_data: str | None) -> str | None:
48
- if input_data is None:
49
- return None
50
- return processing_utils.move_resource_to_block_cache(input_data, self)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/backend/gradio_pdf/pdf.pyi DELETED
@@ -1,132 +0,0 @@
1
- from gradio.components.base import Component
2
-
3
- from gradio.events import Dependency
4
-
5
- class PDF(Component):
6
-
7
- EVENTS = ["change", "upload"]
8
-
9
- data_model = FileData
10
-
11
- def __init__(self, value: Any = None, *,
12
- height: int | None = None,
13
- label: str | None = None, info: str | None = None,
14
- show_label: bool | None = None,
15
- container: bool = True,
16
- scale: int | None = None,
17
- min_width: int | None = None,
18
- interactive: bool | None = None,
19
- visible: bool = True,
20
- elem_id: str | None = None,
21
- elem_classes: list[str] | str | None = None,
22
- render: bool = True,
23
- load_fn: Callable[..., Any] | None = None,
24
- every: float | None = None):
25
- super().__init__(value, label=label, info=info,
26
- show_label=show_label, container=container,
27
- scale=scale, min_width=min_width,
28
- interactive=interactive, visible=visible,
29
- elem_id=elem_id, elem_classes=elem_classes,
30
- render=render, load_fn=load_fn, every=every)
31
- self.height = height
32
-
33
- def preprocess(self, payload: FileData) -> str:
34
- return payload.path
35
-
36
- def postprocess(self, value: str | None) -> FileData:
37
- if not value:
38
- return None
39
- return FileData(path=value)
40
-
41
- def example_inputs(self):
42
- return "https://gradio-builds.s3.amazonaws.com/assets/pdf-guide/fw9.pdf"
43
-
44
- def as_example(self, input_data: str | None) -> str | None:
45
- if input_data is None:
46
- return None
47
- return processing_utils.move_resource_to_block_cache(input_data, self)
48
-
49
-
50
- def change(self,
51
- fn: Callable | None,
52
- inputs: Component | Sequence[Component] | set[Component] | None = None,
53
- outputs: Component | Sequence[Component] | None = None,
54
- api_name: str | None | Literal[False] = None,
55
- scroll_to_output: bool = False,
56
- show_progress: Literal["full", "minimal", "hidden"] = "full",
57
- queue: bool | None = None,
58
- batch: bool = False,
59
- max_batch_size: int = 4,
60
- preprocess: bool = True,
61
- postprocess: bool = True,
62
- cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
63
- every: float | None = None,
64
- trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
65
- js: str | None = None,
66
- concurrency_limit: int | None | Literal["default"] = "default",
67
- concurrency_id: str | None = None,
68
- show_api: bool = True) -> Dependency:
69
- """
70
- Parameters:
71
- fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
72
- inputs: List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
73
- outputs: List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
74
- api_name: Defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, the endpoint will be exposed in the api docs as an unnamed endpoint, although this behavior will be changed in Gradio 4.0. If set to a string, the endpoint will be exposed in the api docs with the given name.
75
- scroll_to_output: If True, will scroll to output component on completion
76
- show_progress: If True, will show progress animation while pending
77
- queue: If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app.
78
- batch: If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component.
79
- max_batch_size: Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
80
- preprocess: If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component).
81
- postprocess: If False, will not run postprocessing of component data before returning 'fn' output to the browser.
82
- cancels: A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish.
83
- every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
84
- trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
85
- js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
86
- concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
87
- concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
88
- show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
89
- """
90
- ...
91
-
92
- def upload(self,
93
- fn: Callable | None,
94
- inputs: Component | Sequence[Component] | set[Component] | None = None,
95
- outputs: Component | Sequence[Component] | None = None,
96
- api_name: str | None | Literal[False] = None,
97
- scroll_to_output: bool = False,
98
- show_progress: Literal["full", "minimal", "hidden"] = "full",
99
- queue: bool | None = None,
100
- batch: bool = False,
101
- max_batch_size: int = 4,
102
- preprocess: bool = True,
103
- postprocess: bool = True,
104
- cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
105
- every: float | None = None,
106
- trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
107
- js: str | None = None,
108
- concurrency_limit: int | None | Literal["default"] = "default",
109
- concurrency_id: str | None = None,
110
- show_api: bool = True) -> Dependency:
111
- """
112
- Parameters:
113
- fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
114
- inputs: List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
115
- outputs: List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
116
- api_name: Defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, the endpoint will be exposed in the api docs as an unnamed endpoint, although this behavior will be changed in Gradio 4.0. If set to a string, the endpoint will be exposed in the api docs with the given name.
117
- scroll_to_output: If True, will scroll to output component on completion
118
- show_progress: If True, will show progress animation while pending
119
- queue: If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app.
120
- batch: If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component.
121
- max_batch_size: Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
122
- preprocess: If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component).
123
- postprocess: If False, will not run postprocessing of component data before returning 'fn' output to the browser.
124
- cancels: A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish.
125
- every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
126
- trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
127
- js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
128
- concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
129
- concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
130
- show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
131
- """
132
- ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/backend/gradio_pdf/templates/component/Index-9e3f581a.js DELETED
The diff for this file is too large to render. See raw diff
 
src/backend/gradio_pdf/templates/component/Index-f36f7747.js DELETED
The diff for this file is too large to render. See raw diff
 
src/backend/gradio_pdf/templates/component/Index-f4230f0b.js DELETED
The diff for this file is too large to render. See raw diff
 
src/backend/gradio_pdf/templates/component/index.js DELETED
@@ -1,4 +0,0 @@
1
- import { I as f } from "./Index-9e3f581a.js";
2
- export {
3
- f as default
4
- };
 
 
 
 
 
src/backend/gradio_pdf/templates/component/style.css DELETED
@@ -1 +0,0 @@
1
- .dropdown-arrow.svelte-145leq6{fill:currentColor}.block.svelte-1t38q2d{position:relative;margin:0;box-shadow:var(--block-shadow);border-width:var(--block-border-width);border-color:var(--block-border-color);border-radius:var(--block-radius);background:var(--block-background-fill);width:100%;line-height:var(--line-sm)}.block.border_focus.svelte-1t38q2d{border-color:var(--color-accent)}.padded.svelte-1t38q2d{padding:var(--block-padding)}.hidden.svelte-1t38q2d{display:none}.hide-container.svelte-1t38q2d{margin:0;box-shadow:none;--block-border-width:0;background:transparent;padding:0;overflow:visible}div.svelte-1hnfib2{margin-bottom:var(--spacing-lg);color:var(--block-info-text-color);font-weight:var(--block-info-text-weight);font-size:var(--block-info-text-size);line-height:var(--line-sm)}span.has-info.svelte-22c38v{margin-bottom:var(--spacing-xs)}span.svelte-22c38v:not(.has-info){margin-bottom:var(--spacing-lg)}span.svelte-22c38v{display:inline-block;position:relative;z-index:var(--layer-4);border:solid var(--block-title-border-width) var(--block-title-border-color);border-radius:var(--block-title-radius);background:var(--block-title-background-fill);padding:var(--block-title-padding);color:var(--block-title-text-color);font-weight:var(--block-title-text-weight);font-size:var(--block-title-text-size);line-height:var(--line-sm)}.hide.svelte-22c38v{margin:0;height:0}label.svelte-9gxdi0{display:inline-flex;align-items:center;z-index:var(--layer-2);box-shadow:var(--block-label-shadow);border:var(--block-label-border-width) solid var(--border-color-primary);border-top:none;border-left:none;border-radius:var(--block-label-radius);background:var(--block-label-background-fill);padding:var(--block-label-padding);pointer-events:none;color:var(--block-label-text-color);font-weight:var(--block-label-text-weight);font-size:var(--block-label-text-size);line-height:var(--line-sm)}.gr-group label.svelte-9gxdi0{border-top-left-radius:0}label.float.svelte-9gxdi0{position:absolute;top:var(--block-label-margin);left:var(--block-label-margin)}label.svelte-9gxdi0:not(.float){position:static;margin-top:var(--block-label-margin);margin-left:var(--block-label-margin)}.hide.svelte-9gxdi0{height:0}span.svelte-9gxdi0{opacity:.8;margin-right:var(--size-2);width:calc(var(--block-label-text-size) - 1px);height:calc(var(--block-label-text-size) - 1px)}.hide-label.svelte-9gxdi0{box-shadow:none;border-width:0;background:transparent;overflow:visible}button.svelte-xtz2g8{display:flex;justify-content:center;align-items:center;gap:1px;z-index:var(--layer-2);border-radius:var(--radius-sm);color:var(--block-label-text-color);border:1px solid transparent}.padded.svelte-xtz2g8{padding:2px;background:var(--background-fill-primary);box-shadow:var(--shadow-drop);border:1px solid var(--button-secondary-border-color)}button.svelte-xtz2g8:hover{cursor:pointer;color:var(--color-accent)}.padded.svelte-xtz2g8:hover{border:2px solid var(--button-secondary-border-color-hover);padding:1px;color:var(--block-label-text-color)}span.svelte-xtz2g8{padding:0 1px;font-size:10px}div.svelte-xtz2g8{padding:2px;display:flex;align-items:flex-end}.small.svelte-xtz2g8{width:14px;height:14px}.large.svelte-xtz2g8{width:22px;height:22px}.pending.svelte-xtz2g8{animation:svelte-xtz2g8-flash .5s infinite}@keyframes svelte-xtz2g8-flash{0%{opacity:.5}50%{opacity:1}to{opacity:.5}}.empty.svelte-3w3rth{display:flex;justify-content:center;align-items:center;margin-top:calc(0px - var(--size-6));height:var(--size-full)}.icon.svelte-3w3rth{opacity:.5;height:var(--size-5);color:var(--body-text-color)}.small.svelte-3w3rth{min-height:calc(var(--size-32) - 20px)}.large.svelte-3w3rth{min-height:calc(var(--size-64) - 20px)}.unpadded_box.svelte-3w3rth{margin-top:0}.small_parent.svelte-3w3rth{min-height:100%!important}.wrap.svelte-kzcjhc{display:flex;flex-direction:column;justify-content:center;align-items:center;min-height:var(--size-60);color:var(--block-label-text-color);line-height:var(--line-md);height:100%;padding-top:var(--size-3)}.or.svelte-kzcjhc{color:var(--body-text-color-subdued);display:flex}.icon-wrap.svelte-kzcjhc{width:30px;margin-bottom:var(--spacing-lg)}@media (--screen-md){.wrap.svelte-kzcjhc{font-size:var(--text-lg)}}.hovered.svelte-kzcjhc{color:var(--color-accent)}div.svelte-1nba87b{border-top:1px solid transparent;display:flex;max-height:100%;justify-content:center;gap:var(--spacing-sm);height:auto;align-items:flex-end;box-shadow:var(--shadow-drop);padding:var(--spacing-xl) 0;color:var(--block-label-text-color);flex-shrink:0;width:95%}.show_border.svelte-1nba87b{border-top:1px solid var(--block-border-color);margin-top:var(--spacing-xxl)}button.svelte-8huxfn,a.svelte-8huxfn{display:inline-flex;justify-content:center;align-items:center;transition:var(--button-transition);box-shadow:var(--button-shadow);padding:var(--size-0-5) var(--size-2);text-align:center}button.svelte-8huxfn:hover,button[disabled].svelte-8huxfn,a.svelte-8huxfn:hover,a.disabled.svelte-8huxfn{box-shadow:var(--button-shadow-hover)}button.svelte-8huxfn:active,a.svelte-8huxfn:active{box-shadow:var(--button-shadow-active)}button[disabled].svelte-8huxfn,a.disabled.svelte-8huxfn{opacity:.5;filter:grayscale(30%);cursor:not-allowed}.hidden.svelte-8huxfn{display:none}.primary.svelte-8huxfn{border:var(--button-border-width) solid var(--button-primary-border-color);background:var(--button-primary-background-fill);color:var(--button-primary-text-color)}.primary.svelte-8huxfn:hover,.primary[disabled].svelte-8huxfn{border-color:var(--button-primary-border-color-hover);background:var(--button-primary-background-fill-hover);color:var(--button-primary-text-color-hover)}.secondary.svelte-8huxfn{border:var(--button-border-width) solid var(--button-secondary-border-color);background:var(--button-secondary-background-fill);color:var(--button-secondary-text-color)}.secondary.svelte-8huxfn:hover,.secondary[disabled].svelte-8huxfn{border-color:var(--button-secondary-border-color-hover);background:var(--button-secondary-background-fill-hover);color:var(--button-secondary-text-color-hover)}.stop.svelte-8huxfn{border:var(--button-border-width) solid var(--button-cancel-border-color);background:var(--button-cancel-background-fill);color:var(--button-cancel-text-color)}.stop.svelte-8huxfn:hover,.stop[disabled].svelte-8huxfn{border-color:var(--button-cancel-border-color-hover);background:var(--button-cancel-background-fill-hover);color:var(--button-cancel-text-color-hover)}.sm.svelte-8huxfn{border-radius:var(--button-small-radius);padding:var(--button-small-padding);font-weight:var(--button-small-text-weight);font-size:var(--button-small-text-size)}.lg.svelte-8huxfn{border-radius:var(--button-large-radius);padding:var(--button-large-padding);font-weight:var(--button-large-text-weight);font-size:var(--button-large-text-size)}.button-icon.svelte-8huxfn{width:var(--text-xl);height:var(--text-xl);margin-right:var(--spacing-xl)}svg.svelte-43sxxs.svelte-43sxxs{width:var(--size-20);height:var(--size-20)}svg.svelte-43sxxs path.svelte-43sxxs{fill:var(--loader-color)}div.svelte-43sxxs.svelte-43sxxs{z-index:var(--layer-2)}.margin.svelte-43sxxs.svelte-43sxxs{margin:var(--size-4)}.wrap.svelte-14miwb5.svelte-14miwb5{display:flex;flex-direction:column;justify-content:center;align-items:center;z-index:var(--layer-5);transition:opacity .1s ease-in-out;border-radius:var(--block-radius);background:var(--block-background-fill);padding:0 var(--size-6);max-height:var(--size-screen-h);overflow:hidden;pointer-events:none}.wrap.center.svelte-14miwb5.svelte-14miwb5{top:0;right:0;left:0}.wrap.default.svelte-14miwb5.svelte-14miwb5{top:0;right:0;bottom:0;left:0}.hide.svelte-14miwb5.svelte-14miwb5{opacity:0;pointer-events:none}.generating.svelte-14miwb5.svelte-14miwb5{animation:svelte-14miwb5-pulse 2s cubic-bezier(.4,0,.6,1) infinite;border:2px solid var(--color-accent);background:transparent}.translucent.svelte-14miwb5.svelte-14miwb5{background:none}@keyframes svelte-14miwb5-pulse{0%,to{opacity:1}50%{opacity:.5}}.loading.svelte-14miwb5.svelte-14miwb5{z-index:var(--layer-2);color:var(--body-text-color)}.eta-bar.svelte-14miwb5.svelte-14miwb5{position:absolute;top:0;right:0;bottom:0;left:0;transform-origin:left;opacity:.8;z-index:var(--layer-1);transition:10ms;background:var(--background-fill-secondary)}.progress-bar-wrap.svelte-14miwb5.svelte-14miwb5{border:1px solid var(--border-color-primary);background:var(--background-fill-primary);width:55.5%;height:var(--size-4)}.progress-bar.svelte-14miwb5.svelte-14miwb5{transform-origin:left;background-color:var(--loader-color);width:var(--size-full);height:var(--size-full)}.progress-level.svelte-14miwb5.svelte-14miwb5{display:flex;flex-direction:column;align-items:center;gap:1;z-index:var(--layer-2);width:var(--size-full)}.progress-level-inner.svelte-14miwb5.svelte-14miwb5{margin:var(--size-2) auto;color:var(--body-text-color);font-size:var(--text-sm);font-family:var(--font-mono)}.meta-text.svelte-14miwb5.svelte-14miwb5{position:absolute;top:0;right:0;z-index:var(--layer-2);padding:var(--size-1) var(--size-2);font-size:var(--text-sm);font-family:var(--font-mono)}.meta-text-center.svelte-14miwb5.svelte-14miwb5{display:flex;position:absolute;top:0;right:0;justify-content:center;align-items:center;transform:translateY(var(--size-6));z-index:var(--layer-2);padding:var(--size-1) var(--size-2);font-size:var(--text-sm);font-family:var(--font-mono);text-align:center}.error.svelte-14miwb5.svelte-14miwb5{box-shadow:var(--shadow-drop);border:solid 1px var(--error-border-color);border-radius:var(--radius-full);background:var(--error-background-fill);padding-right:var(--size-4);padding-left:var(--size-4);color:var(--error-text-color);font-weight:var(--weight-semibold);font-size:var(--text-lg);line-height:var(--line-lg);font-family:var(--font)}.minimal.svelte-14miwb5 .progress-text.svelte-14miwb5{background:var(--block-background-fill)}.border.svelte-14miwb5.svelte-14miwb5{border:1px solid var(--border-color-primary)}.toast-body.svelte-solcu7{display:flex;position:relative;right:0;left:0;align-items:center;margin:var(--size-6) var(--size-4);margin:auto;border-radius:var(--container-radius);overflow:hidden;pointer-events:auto}.toast-body.error.svelte-solcu7{border:1px solid var(--color-red-700);background:var(--color-red-50)}.dark .toast-body.error.svelte-solcu7{border:1px solid var(--color-red-500);background-color:var(--color-grey-950)}.toast-body.warning.svelte-solcu7{border:1px solid var(--color-yellow-700);background:var(--color-yellow-50)}.dark .toast-body.warning.svelte-solcu7{border:1px solid var(--color-yellow-500);background-color:var(--color-grey-950)}.toast-body.info.svelte-solcu7{border:1px solid var(--color-grey-700);background:var(--color-grey-50)}.dark .toast-body.info.svelte-solcu7{border:1px solid var(--color-grey-500);background-color:var(--color-grey-950)}.toast-title.svelte-solcu7{display:flex;align-items:center;font-weight:var(--weight-bold);font-size:var(--text-lg);line-height:var(--line-sm);text-transform:capitalize}.toast-title.error.svelte-solcu7{color:var(--color-red-700)}.dark .toast-title.error.svelte-solcu7{color:var(--color-red-50)}.toast-title.warning.svelte-solcu7{color:var(--color-yellow-700)}.dark .toast-title.warning.svelte-solcu7{color:var(--color-yellow-50)}.toast-title.info.svelte-solcu7{color:var(--color-grey-700)}.dark .toast-title.info.svelte-solcu7{color:var(--color-grey-50)}.toast-close.svelte-solcu7{margin:0 var(--size-3);border-radius:var(--size-3);padding:0px var(--size-1-5);font-size:var(--size-5);line-height:var(--size-5)}.toast-close.error.svelte-solcu7{color:var(--color-red-700)}.dark .toast-close.error.svelte-solcu7{color:var(--color-red-500)}.toast-close.warning.svelte-solcu7{color:var(--color-yellow-700)}.dark .toast-close.warning.svelte-solcu7{color:var(--color-yellow-500)}.toast-close.info.svelte-solcu7{color:var(--color-grey-700)}.dark .toast-close.info.svelte-solcu7{color:var(--color-grey-500)}.toast-text.svelte-solcu7{font-size:var(--text-lg)}.toast-text.error.svelte-solcu7{color:var(--color-red-700)}.dark .toast-text.error.svelte-solcu7{color:var(--color-red-50)}.toast-text.warning.svelte-solcu7{color:var(--color-yellow-700)}.dark .toast-text.warning.svelte-solcu7{color:var(--color-yellow-50)}.toast-text.info.svelte-solcu7{color:var(--color-grey-700)}.dark .toast-text.info.svelte-solcu7{color:var(--color-grey-50)}.toast-details.svelte-solcu7{margin:var(--size-3) var(--size-3) var(--size-3) 0;width:100%}.toast-icon.svelte-solcu7{display:flex;position:absolute;position:relative;flex-shrink:0;justify-content:center;align-items:center;margin:var(--size-2);border-radius:var(--radius-full);padding:var(--size-1);padding-left:calc(var(--size-1) - 1px);width:35px;height:35px}.toast-icon.error.svelte-solcu7{color:var(--color-red-700)}.dark .toast-icon.error.svelte-solcu7{color:var(--color-red-500)}.toast-icon.warning.svelte-solcu7{color:var(--color-yellow-700)}.dark .toast-icon.warning.svelte-solcu7{color:var(--color-yellow-500)}.toast-icon.info.svelte-solcu7{color:var(--color-grey-700)}.dark .toast-icon.info.svelte-solcu7{color:var(--color-grey-500)}@keyframes svelte-solcu7-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}.timer.svelte-solcu7{position:absolute;bottom:0;left:0;transform-origin:0 0;animation:svelte-solcu7-countdown 10s linear forwards;width:100%;height:var(--size-1)}.timer.error.svelte-solcu7{background:var(--color-red-700)}.dark .timer.error.svelte-solcu7{background:var(--color-red-500)}.timer.warning.svelte-solcu7{background:var(--color-yellow-700)}.dark .timer.warning.svelte-solcu7{background:var(--color-yellow-500)}.timer.info.svelte-solcu7{background:var(--color-grey-700)}.dark .timer.info.svelte-solcu7{background:var(--color-grey-500)}.toast-wrap.svelte-gatr8h{display:flex;position:fixed;top:var(--size-4);right:var(--size-4);flex-direction:column;align-items:end;gap:var(--size-2);z-index:var(--layer-top);width:calc(100% - var(--size-8))}@media (--screen-sm){.toast-wrap.svelte-gatr8h{width:calc(var(--size-96) + var(--size-10))}}button.svelte-18dlsnh{cursor:pointer;width:var(--size-full);height:var(--size-full)}.hidden.svelte-18dlsnh{display:none;height:0;position:absolute}.center.svelte-18dlsnh{display:flex;justify-content:center}.flex.svelte-18dlsnh{display:flex;justify-content:center;align-items:center}input.svelte-18dlsnh{display:none}div.svelte-1wj0ocy{display:flex;top:var(--size-2);right:var(--size-2);justify-content:flex-end;gap:var(--spacing-sm);z-index:var(--layer-1)}.not-absolute.svelte-1wj0ocy{margin:var(--size-1)}.pdf-canvas.svelte-qxsbof{display:flex;justify-content:center;align-items:center;overflow-y:auto}.button-row.svelte-qxsbof{display:flex;flex-direction:row;width:100%;justify-content:center;align-items:center}.page-count.svelte-qxsbof{margin:0 10px;font-family:var(--font-mono)}
 
 
src/backend/gradio_pdf/templates/component/wrapper-98f94c21-15fa1cb3.js DELETED
@@ -1,2449 +0,0 @@
1
- import { r as S } from "./Index-9e3f581a.js";
2
- function z(s) {
3
- return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
4
- }
5
- function gt(s) {
6
- if (s.__esModule)
7
- return s;
8
- var e = s.default;
9
- if (typeof e == "function") {
10
- var t = function r() {
11
- return this instanceof r ? Reflect.construct(e, arguments, this.constructor) : e.apply(this, arguments);
12
- };
13
- t.prototype = e.prototype;
14
- } else
15
- t = {};
16
- return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(s).forEach(function(r) {
17
- var i = Object.getOwnPropertyDescriptor(s, r);
18
- Object.defineProperty(t, r, i.get ? i : {
19
- enumerable: !0,
20
- get: function() {
21
- return s[r];
22
- }
23
- });
24
- }), t;
25
- }
26
- const { Duplex: yt } = S;
27
- function Oe(s) {
28
- s.emit("close");
29
- }
30
- function vt() {
31
- !this.destroyed && this._writableState.finished && this.destroy();
32
- }
33
- function Qe(s) {
34
- this.removeListener("error", Qe), this.destroy(), this.listenerCount("error") === 0 && this.emit("error", s);
35
- }
36
- function St(s, e) {
37
- let t = !0;
38
- const r = new yt({
39
- ...e,
40
- autoDestroy: !1,
41
- emitClose: !1,
42
- objectMode: !1,
43
- writableObjectMode: !1
44
- });
45
- return s.on("message", function(n, o) {
46
- const l = !o && r._readableState.objectMode ? n.toString() : n;
47
- r.push(l) || s.pause();
48
- }), s.once("error", function(n) {
49
- r.destroyed || (t = !1, r.destroy(n));
50
- }), s.once("close", function() {
51
- r.destroyed || r.push(null);
52
- }), r._destroy = function(i, n) {
53
- if (s.readyState === s.CLOSED) {
54
- n(i), process.nextTick(Oe, r);
55
- return;
56
- }
57
- let o = !1;
58
- s.once("error", function(f) {
59
- o = !0, n(f);
60
- }), s.once("close", function() {
61
- o || n(i), process.nextTick(Oe, r);
62
- }), t && s.terminate();
63
- }, r._final = function(i) {
64
- if (s.readyState === s.CONNECTING) {
65
- s.once("open", function() {
66
- r._final(i);
67
- });
68
- return;
69
- }
70
- s._socket !== null && (s._socket._writableState.finished ? (i(), r._readableState.endEmitted && r.destroy()) : (s._socket.once("finish", function() {
71
- i();
72
- }), s.close()));
73
- }, r._read = function() {
74
- s.isPaused && s.resume();
75
- }, r._write = function(i, n, o) {
76
- if (s.readyState === s.CONNECTING) {
77
- s.once("open", function() {
78
- r._write(i, n, o);
79
- });
80
- return;
81
- }
82
- s.send(i, o);
83
- }, r.on("end", vt), r.on("error", Qe), r;
84
- }
85
- var Et = St;
86
- const Vs = /* @__PURE__ */ z(Et);
87
- var te = { exports: {} }, U = {
88
- BINARY_TYPES: ["nodebuffer", "arraybuffer", "fragments"],
89
- EMPTY_BUFFER: Buffer.alloc(0),
90
- GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
91
- kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
92
- kListener: Symbol("kListener"),
93
- kStatusCode: Symbol("status-code"),
94
- kWebSocket: Symbol("websocket"),
95
- NOOP: () => {
96
- }
97
- }, bt, xt;
98
- const { EMPTY_BUFFER: kt } = U, Se = Buffer[Symbol.species];
99
- function wt(s, e) {
100
- if (s.length === 0)
101
- return kt;
102
- if (s.length === 1)
103
- return s[0];
104
- const t = Buffer.allocUnsafe(e);
105
- let r = 0;
106
- for (let i = 0; i < s.length; i++) {
107
- const n = s[i];
108
- t.set(n, r), r += n.length;
109
- }
110
- return r < e ? new Se(t.buffer, t.byteOffset, r) : t;
111
- }
112
- function Je(s, e, t, r, i) {
113
- for (let n = 0; n < i; n++)
114
- t[r + n] = s[n] ^ e[n & 3];
115
- }
116
- function et(s, e) {
117
- for (let t = 0; t < s.length; t++)
118
- s[t] ^= e[t & 3];
119
- }
120
- function Ot(s) {
121
- return s.length === s.buffer.byteLength ? s.buffer : s.buffer.slice(s.byteOffset, s.byteOffset + s.length);
122
- }
123
- function Ee(s) {
124
- if (Ee.readOnly = !0, Buffer.isBuffer(s))
125
- return s;
126
- let e;
127
- return s instanceof ArrayBuffer ? e = new Se(s) : ArrayBuffer.isView(s) ? e = new Se(s.buffer, s.byteOffset, s.byteLength) : (e = Buffer.from(s), Ee.readOnly = !1), e;
128
- }
129
- te.exports = {
130
- concat: wt,
131
- mask: Je,
132
- toArrayBuffer: Ot,
133
- toBuffer: Ee,
134
- unmask: et
135
- };
136
- if (!process.env.WS_NO_BUFFER_UTIL)
137
- try {
138
- const s = require("bufferutil");
139
- xt = te.exports.mask = function(e, t, r, i, n) {
140
- n < 48 ? Je(e, t, r, i, n) : s.mask(e, t, r, i, n);
141
- }, bt = te.exports.unmask = function(e, t) {
142
- e.length < 32 ? et(e, t) : s.unmask(e, t);
143
- };
144
- } catch {
145
- }
146
- var ne = te.exports;
147
- const Ce = Symbol("kDone"), ue = Symbol("kRun");
148
- let Ct = class {
149
- /**
150
- * Creates a new `Limiter`.
151
- *
152
- * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
153
- * to run concurrently
154
- */
155
- constructor(e) {
156
- this[Ce] = () => {
157
- this.pending--, this[ue]();
158
- }, this.concurrency = e || 1 / 0, this.jobs = [], this.pending = 0;
159
- }
160
- /**
161
- * Adds a job to the queue.
162
- *
163
- * @param {Function} job The job to run
164
- * @public
165
- */
166
- add(e) {
167
- this.jobs.push(e), this[ue]();
168
- }
169
- /**
170
- * Removes a job from the queue and runs it if possible.
171
- *
172
- * @private
173
- */
174
- [ue]() {
175
- if (this.pending !== this.concurrency && this.jobs.length) {
176
- const e = this.jobs.shift();
177
- this.pending++, e(this[Ce]);
178
- }
179
- }
180
- };
181
- var Tt = Ct;
182
- const W = S, Te = ne, Lt = Tt, { kStatusCode: tt } = U, Nt = Buffer[Symbol.species], Pt = Buffer.from([0, 0, 255, 255]), se = Symbol("permessage-deflate"), w = Symbol("total-length"), V = Symbol("callback"), C = Symbol("buffers"), J = Symbol("error");
183
- let K, Rt = class {
184
- /**
185
- * Creates a PerMessageDeflate instance.
186
- *
187
- * @param {Object} [options] Configuration options
188
- * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
189
- * for, or request, a custom client window size
190
- * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
191
- * acknowledge disabling of client context takeover
192
- * @param {Number} [options.concurrencyLimit=10] The number of concurrent
193
- * calls to zlib
194
- * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
195
- * use of a custom server window size
196
- * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
197
- * disabling of server context takeover
198
- * @param {Number} [options.threshold=1024] Size (in bytes) below which
199
- * messages should not be compressed if context takeover is disabled
200
- * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
201
- * deflate
202
- * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
203
- * inflate
204
- * @param {Boolean} [isServer=false] Create the instance in either server or
205
- * client mode
206
- * @param {Number} [maxPayload=0] The maximum allowed message length
207
- */
208
- constructor(e, t, r) {
209
- if (this._maxPayload = r | 0, this._options = e || {}, this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024, this._isServer = !!t, this._deflate = null, this._inflate = null, this.params = null, !K) {
210
- const i = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
211
- K = new Lt(i);
212
- }
213
- }
214
- /**
215
- * @type {String}
216
- */
217
- static get extensionName() {
218
- return "permessage-deflate";
219
- }
220
- /**
221
- * Create an extension negotiation offer.
222
- *
223
- * @return {Object} Extension parameters
224
- * @public
225
- */
226
- offer() {
227
- const e = {};
228
- return this._options.serverNoContextTakeover && (e.server_no_context_takeover = !0), this._options.clientNoContextTakeover && (e.client_no_context_takeover = !0), this._options.serverMaxWindowBits && (e.server_max_window_bits = this._options.serverMaxWindowBits), this._options.clientMaxWindowBits ? e.client_max_window_bits = this._options.clientMaxWindowBits : this._options.clientMaxWindowBits == null && (e.client_max_window_bits = !0), e;
229
- }
230
- /**
231
- * Accept an extension negotiation offer/response.
232
- *
233
- * @param {Array} configurations The extension negotiation offers/reponse
234
- * @return {Object} Accepted configuration
235
- * @public
236
- */
237
- accept(e) {
238
- return e = this.normalizeParams(e), this.params = this._isServer ? this.acceptAsServer(e) : this.acceptAsClient(e), this.params;
239
- }
240
- /**
241
- * Releases all resources used by the extension.
242
- *
243
- * @public
244
- */
245
- cleanup() {
246
- if (this._inflate && (this._inflate.close(), this._inflate = null), this._deflate) {
247
- const e = this._deflate[V];
248
- this._deflate.close(), this._deflate = null, e && e(
249
- new Error(
250
- "The deflate stream was closed while data was being processed"
251
- )
252
- );
253
- }
254
- }
255
- /**
256
- * Accept an extension negotiation offer.
257
- *
258
- * @param {Array} offers The extension negotiation offers
259
- * @return {Object} Accepted configuration
260
- * @private
261
- */
262
- acceptAsServer(e) {
263
- const t = this._options, r = e.find((i) => !(t.serverNoContextTakeover === !1 && i.server_no_context_takeover || i.server_max_window_bits && (t.serverMaxWindowBits === !1 || typeof t.serverMaxWindowBits == "number" && t.serverMaxWindowBits > i.server_max_window_bits) || typeof t.clientMaxWindowBits == "number" && !i.client_max_window_bits));
264
- if (!r)
265
- throw new Error("None of the extension offers can be accepted");
266
- return t.serverNoContextTakeover && (r.server_no_context_takeover = !0), t.clientNoContextTakeover && (r.client_no_context_takeover = !0), typeof t.serverMaxWindowBits == "number" && (r.server_max_window_bits = t.serverMaxWindowBits), typeof t.clientMaxWindowBits == "number" ? r.client_max_window_bits = t.clientMaxWindowBits : (r.client_max_window_bits === !0 || t.clientMaxWindowBits === !1) && delete r.client_max_window_bits, r;
267
- }
268
- /**
269
- * Accept the extension negotiation response.
270
- *
271
- * @param {Array} response The extension negotiation response
272
- * @return {Object} Accepted configuration
273
- * @private
274
- */
275
- acceptAsClient(e) {
276
- const t = e[0];
277
- if (this._options.clientNoContextTakeover === !1 && t.client_no_context_takeover)
278
- throw new Error('Unexpected parameter "client_no_context_takeover"');
279
- if (!t.client_max_window_bits)
280
- typeof this._options.clientMaxWindowBits == "number" && (t.client_max_window_bits = this._options.clientMaxWindowBits);
281
- else if (this._options.clientMaxWindowBits === !1 || typeof this._options.clientMaxWindowBits == "number" && t.client_max_window_bits > this._options.clientMaxWindowBits)
282
- throw new Error(
283
- 'Unexpected or invalid parameter "client_max_window_bits"'
284
- );
285
- return t;
286
- }
287
- /**
288
- * Normalize parameters.
289
- *
290
- * @param {Array} configurations The extension negotiation offers/reponse
291
- * @return {Array} The offers/response with normalized parameters
292
- * @private
293
- */
294
- normalizeParams(e) {
295
- return e.forEach((t) => {
296
- Object.keys(t).forEach((r) => {
297
- let i = t[r];
298
- if (i.length > 1)
299
- throw new Error(`Parameter "${r}" must have only a single value`);
300
- if (i = i[0], r === "client_max_window_bits") {
301
- if (i !== !0) {
302
- const n = +i;
303
- if (!Number.isInteger(n) || n < 8 || n > 15)
304
- throw new TypeError(
305
- `Invalid value for parameter "${r}": ${i}`
306
- );
307
- i = n;
308
- } else if (!this._isServer)
309
- throw new TypeError(
310
- `Invalid value for parameter "${r}": ${i}`
311
- );
312
- } else if (r === "server_max_window_bits") {
313
- const n = +i;
314
- if (!Number.isInteger(n) || n < 8 || n > 15)
315
- throw new TypeError(
316
- `Invalid value for parameter "${r}": ${i}`
317
- );
318
- i = n;
319
- } else if (r === "client_no_context_takeover" || r === "server_no_context_takeover") {
320
- if (i !== !0)
321
- throw new TypeError(
322
- `Invalid value for parameter "${r}": ${i}`
323
- );
324
- } else
325
- throw new Error(`Unknown parameter "${r}"`);
326
- t[r] = i;
327
- });
328
- }), e;
329
- }
330
- /**
331
- * Decompress data. Concurrency limited.
332
- *
333
- * @param {Buffer} data Compressed data
334
- * @param {Boolean} fin Specifies whether or not this is the last fragment
335
- * @param {Function} callback Callback
336
- * @public
337
- */
338
- decompress(e, t, r) {
339
- K.add((i) => {
340
- this._decompress(e, t, (n, o) => {
341
- i(), r(n, o);
342
- });
343
- });
344
- }
345
- /**
346
- * Compress data. Concurrency limited.
347
- *
348
- * @param {(Buffer|String)} data Data to compress
349
- * @param {Boolean} fin Specifies whether or not this is the last fragment
350
- * @param {Function} callback Callback
351
- * @public
352
- */
353
- compress(e, t, r) {
354
- K.add((i) => {
355
- this._compress(e, t, (n, o) => {
356
- i(), r(n, o);
357
- });
358
- });
359
- }
360
- /**
361
- * Decompress data.
362
- *
363
- * @param {Buffer} data Compressed data
364
- * @param {Boolean} fin Specifies whether or not this is the last fragment
365
- * @param {Function} callback Callback
366
- * @private
367
- */
368
- _decompress(e, t, r) {
369
- const i = this._isServer ? "client" : "server";
370
- if (!this._inflate) {
371
- const n = `${i}_max_window_bits`, o = typeof this.params[n] != "number" ? W.Z_DEFAULT_WINDOWBITS : this.params[n];
372
- this._inflate = W.createInflateRaw({
373
- ...this._options.zlibInflateOptions,
374
- windowBits: o
375
- }), this._inflate[se] = this, this._inflate[w] = 0, this._inflate[C] = [], this._inflate.on("error", Bt), this._inflate.on("data", st);
376
- }
377
- this._inflate[V] = r, this._inflate.write(e), t && this._inflate.write(Pt), this._inflate.flush(() => {
378
- const n = this._inflate[J];
379
- if (n) {
380
- this._inflate.close(), this._inflate = null, r(n);
381
- return;
382
- }
383
- const o = Te.concat(
384
- this._inflate[C],
385
- this._inflate[w]
386
- );
387
- this._inflate._readableState.endEmitted ? (this._inflate.close(), this._inflate = null) : (this._inflate[w] = 0, this._inflate[C] = [], t && this.params[`${i}_no_context_takeover`] && this._inflate.reset()), r(null, o);
388
- });
389
- }
390
- /**
391
- * Compress data.
392
- *
393
- * @param {(Buffer|String)} data Data to compress
394
- * @param {Boolean} fin Specifies whether or not this is the last fragment
395
- * @param {Function} callback Callback
396
- * @private
397
- */
398
- _compress(e, t, r) {
399
- const i = this._isServer ? "server" : "client";
400
- if (!this._deflate) {
401
- const n = `${i}_max_window_bits`, o = typeof this.params[n] != "number" ? W.Z_DEFAULT_WINDOWBITS : this.params[n];
402
- this._deflate = W.createDeflateRaw({
403
- ...this._options.zlibDeflateOptions,
404
- windowBits: o
405
- }), this._deflate[w] = 0, this._deflate[C] = [], this._deflate.on("data", Ut);
406
- }
407
- this._deflate[V] = r, this._deflate.write(e), this._deflate.flush(W.Z_SYNC_FLUSH, () => {
408
- if (!this._deflate)
409
- return;
410
- let n = Te.concat(
411
- this._deflate[C],
412
- this._deflate[w]
413
- );
414
- t && (n = new Nt(n.buffer, n.byteOffset, n.length - 4)), this._deflate[V] = null, this._deflate[w] = 0, this._deflate[C] = [], t && this.params[`${i}_no_context_takeover`] && this._deflate.reset(), r(null, n);
415
- });
416
- }
417
- };
418
- var oe = Rt;
419
- function Ut(s) {
420
- this[C].push(s), this[w] += s.length;
421
- }
422
- function st(s) {
423
- if (this[w] += s.length, this[se]._maxPayload < 1 || this[w] <= this[se]._maxPayload) {
424
- this[C].push(s);
425
- return;
426
- }
427
- this[J] = new RangeError("Max payload size exceeded"), this[J].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH", this[J][tt] = 1009, this.removeListener("data", st), this.reset();
428
- }
429
- function Bt(s) {
430
- this[se]._inflate = null, s[tt] = 1007, this[V](s);
431
- }
432
- var re = { exports: {} };
433
- const $t = {}, Mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
434
- __proto__: null,
435
- default: $t
436
- }, Symbol.toStringTag, { value: "Module" })), It = /* @__PURE__ */ gt(Mt);
437
- var Le;
438
- const { isUtf8: Ne } = S, Dt = [
439
- 0,
440
- 0,
441
- 0,
442
- 0,
443
- 0,
444
- 0,
445
- 0,
446
- 0,
447
- 0,
448
- 0,
449
- 0,
450
- 0,
451
- 0,
452
- 0,
453
- 0,
454
- 0,
455
- // 0 - 15
456
- 0,
457
- 0,
458
- 0,
459
- 0,
460
- 0,
461
- 0,
462
- 0,
463
- 0,
464
- 0,
465
- 0,
466
- 0,
467
- 0,
468
- 0,
469
- 0,
470
- 0,
471
- 0,
472
- // 16 - 31
473
- 0,
474
- 1,
475
- 0,
476
- 1,
477
- 1,
478
- 1,
479
- 1,
480
- 1,
481
- 0,
482
- 0,
483
- 1,
484
- 1,
485
- 0,
486
- 1,
487
- 1,
488
- 0,
489
- // 32 - 47
490
- 1,
491
- 1,
492
- 1,
493
- 1,
494
- 1,
495
- 1,
496
- 1,
497
- 1,
498
- 1,
499
- 1,
500
- 0,
501
- 0,
502
- 0,
503
- 0,
504
- 0,
505
- 0,
506
- // 48 - 63
507
- 0,
508
- 1,
509
- 1,
510
- 1,
511
- 1,
512
- 1,
513
- 1,
514
- 1,
515
- 1,
516
- 1,
517
- 1,
518
- 1,
519
- 1,
520
- 1,
521
- 1,
522
- 1,
523
- // 64 - 79
524
- 1,
525
- 1,
526
- 1,
527
- 1,
528
- 1,
529
- 1,
530
- 1,
531
- 1,
532
- 1,
533
- 1,
534
- 1,
535
- 0,
536
- 0,
537
- 0,
538
- 1,
539
- 1,
540
- // 80 - 95
541
- 1,
542
- 1,
543
- 1,
544
- 1,
545
- 1,
546
- 1,
547
- 1,
548
- 1,
549
- 1,
550
- 1,
551
- 1,
552
- 1,
553
- 1,
554
- 1,
555
- 1,
556
- 1,
557
- // 96 - 111
558
- 1,
559
- 1,
560
- 1,
561
- 1,
562
- 1,
563
- 1,
564
- 1,
565
- 1,
566
- 1,
567
- 1,
568
- 1,
569
- 0,
570
- 1,
571
- 0,
572
- 1,
573
- 0
574
- // 112 - 127
575
- ];
576
- function Wt(s) {
577
- return s >= 1e3 && s <= 1014 && s !== 1004 && s !== 1005 && s !== 1006 || s >= 3e3 && s <= 4999;
578
- }
579
- function be(s) {
580
- const e = s.length;
581
- let t = 0;
582
- for (; t < e; )
583
- if (!(s[t] & 128))
584
- t++;
585
- else if ((s[t] & 224) === 192) {
586
- if (t + 1 === e || (s[t + 1] & 192) !== 128 || (s[t] & 254) === 192)
587
- return !1;
588
- t += 2;
589
- } else if ((s[t] & 240) === 224) {
590
- if (t + 2 >= e || (s[t + 1] & 192) !== 128 || (s[t + 2] & 192) !== 128 || s[t] === 224 && (s[t + 1] & 224) === 128 || // Overlong
591
- s[t] === 237 && (s[t + 1] & 224) === 160)
592
- return !1;
593
- t += 3;
594
- } else if ((s[t] & 248) === 240) {
595
- if (t + 3 >= e || (s[t + 1] & 192) !== 128 || (s[t + 2] & 192) !== 128 || (s[t + 3] & 192) !== 128 || s[t] === 240 && (s[t + 1] & 240) === 128 || // Overlong
596
- s[t] === 244 && s[t + 1] > 143 || s[t] > 244)
597
- return !1;
598
- t += 4;
599
- } else
600
- return !1;
601
- return !0;
602
- }
603
- re.exports = {
604
- isValidStatusCode: Wt,
605
- isValidUTF8: be,
606
- tokenChars: Dt
607
- };
608
- if (Ne)
609
- Le = re.exports.isValidUTF8 = function(s) {
610
- return s.length < 24 ? be(s) : Ne(s);
611
- };
612
- else if (!process.env.WS_NO_UTF_8_VALIDATE)
613
- try {
614
- const s = It;
615
- Le = re.exports.isValidUTF8 = function(e) {
616
- return e.length < 32 ? be(e) : s(e);
617
- };
618
- } catch {
619
- }
620
- var ae = re.exports;
621
- const { Writable: At } = S, Pe = oe, {
622
- BINARY_TYPES: Ft,
623
- EMPTY_BUFFER: Re,
624
- kStatusCode: jt,
625
- kWebSocket: Gt
626
- } = U, { concat: de, toArrayBuffer: Vt, unmask: Ht } = ne, { isValidStatusCode: zt, isValidUTF8: Ue } = ae, X = Buffer[Symbol.species], A = 0, Be = 1, $e = 2, Me = 3, _e = 4, Yt = 5;
627
- let qt = class extends At {
628
- /**
629
- * Creates a Receiver instance.
630
- *
631
- * @param {Object} [options] Options object
632
- * @param {String} [options.binaryType=nodebuffer] The type for binary data
633
- * @param {Object} [options.extensions] An object containing the negotiated
634
- * extensions
635
- * @param {Boolean} [options.isServer=false] Specifies whether to operate in
636
- * client or server mode
637
- * @param {Number} [options.maxPayload=0] The maximum allowed message length
638
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
639
- * not to skip UTF-8 validation for text and close messages
640
- */
641
- constructor(e = {}) {
642
- super(), this._binaryType = e.binaryType || Ft[0], this._extensions = e.extensions || {}, this._isServer = !!e.isServer, this._maxPayload = e.maxPayload | 0, this._skipUTF8Validation = !!e.skipUTF8Validation, this[Gt] = void 0, this._bufferedBytes = 0, this._buffers = [], this._compressed = !1, this._payloadLength = 0, this._mask = void 0, this._fragmented = 0, this._masked = !1, this._fin = !1, this._opcode = 0, this._totalPayloadLength = 0, this._messageLength = 0, this._fragments = [], this._state = A, this._loop = !1;
643
- }
644
- /**
645
- * Implements `Writable.prototype._write()`.
646
- *
647
- * @param {Buffer} chunk The chunk of data to write
648
- * @param {String} encoding The character encoding of `chunk`
649
- * @param {Function} cb Callback
650
- * @private
651
- */
652
- _write(e, t, r) {
653
- if (this._opcode === 8 && this._state == A)
654
- return r();
655
- this._bufferedBytes += e.length, this._buffers.push(e), this.startLoop(r);
656
- }
657
- /**
658
- * Consumes `n` bytes from the buffered data.
659
- *
660
- * @param {Number} n The number of bytes to consume
661
- * @return {Buffer} The consumed bytes
662
- * @private
663
- */
664
- consume(e) {
665
- if (this._bufferedBytes -= e, e === this._buffers[0].length)
666
- return this._buffers.shift();
667
- if (e < this._buffers[0].length) {
668
- const r = this._buffers[0];
669
- return this._buffers[0] = new X(
670
- r.buffer,
671
- r.byteOffset + e,
672
- r.length - e
673
- ), new X(r.buffer, r.byteOffset, e);
674
- }
675
- const t = Buffer.allocUnsafe(e);
676
- do {
677
- const r = this._buffers[0], i = t.length - e;
678
- e >= r.length ? t.set(this._buffers.shift(), i) : (t.set(new Uint8Array(r.buffer, r.byteOffset, e), i), this._buffers[0] = new X(
679
- r.buffer,
680
- r.byteOffset + e,
681
- r.length - e
682
- )), e -= r.length;
683
- } while (e > 0);
684
- return t;
685
- }
686
- /**
687
- * Starts the parsing loop.
688
- *
689
- * @param {Function} cb Callback
690
- * @private
691
- */
692
- startLoop(e) {
693
- let t;
694
- this._loop = !0;
695
- do
696
- switch (this._state) {
697
- case A:
698
- t = this.getInfo();
699
- break;
700
- case Be:
701
- t = this.getPayloadLength16();
702
- break;
703
- case $e:
704
- t = this.getPayloadLength64();
705
- break;
706
- case Me:
707
- this.getMask();
708
- break;
709
- case _e:
710
- t = this.getData(e);
711
- break;
712
- default:
713
- this._loop = !1;
714
- return;
715
- }
716
- while (this._loop);
717
- e(t);
718
- }
719
- /**
720
- * Reads the first two bytes of a frame.
721
- *
722
- * @return {(RangeError|undefined)} A possible error
723
- * @private
724
- */
725
- getInfo() {
726
- if (this._bufferedBytes < 2) {
727
- this._loop = !1;
728
- return;
729
- }
730
- const e = this.consume(2);
731
- if (e[0] & 48)
732
- return this._loop = !1, g(
733
- RangeError,
734
- "RSV2 and RSV3 must be clear",
735
- !0,
736
- 1002,
737
- "WS_ERR_UNEXPECTED_RSV_2_3"
738
- );
739
- const t = (e[0] & 64) === 64;
740
- if (t && !this._extensions[Pe.extensionName])
741
- return this._loop = !1, g(
742
- RangeError,
743
- "RSV1 must be clear",
744
- !0,
745
- 1002,
746
- "WS_ERR_UNEXPECTED_RSV_1"
747
- );
748
- if (this._fin = (e[0] & 128) === 128, this._opcode = e[0] & 15, this._payloadLength = e[1] & 127, this._opcode === 0) {
749
- if (t)
750
- return this._loop = !1, g(
751
- RangeError,
752
- "RSV1 must be clear",
753
- !0,
754
- 1002,
755
- "WS_ERR_UNEXPECTED_RSV_1"
756
- );
757
- if (!this._fragmented)
758
- return this._loop = !1, g(
759
- RangeError,
760
- "invalid opcode 0",
761
- !0,
762
- 1002,
763
- "WS_ERR_INVALID_OPCODE"
764
- );
765
- this._opcode = this._fragmented;
766
- } else if (this._opcode === 1 || this._opcode === 2) {
767
- if (this._fragmented)
768
- return this._loop = !1, g(
769
- RangeError,
770
- `invalid opcode ${this._opcode}`,
771
- !0,
772
- 1002,
773
- "WS_ERR_INVALID_OPCODE"
774
- );
775
- this._compressed = t;
776
- } else if (this._opcode > 7 && this._opcode < 11) {
777
- if (!this._fin)
778
- return this._loop = !1, g(
779
- RangeError,
780
- "FIN must be set",
781
- !0,
782
- 1002,
783
- "WS_ERR_EXPECTED_FIN"
784
- );
785
- if (t)
786
- return this._loop = !1, g(
787
- RangeError,
788
- "RSV1 must be clear",
789
- !0,
790
- 1002,
791
- "WS_ERR_UNEXPECTED_RSV_1"
792
- );
793
- if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1)
794
- return this._loop = !1, g(
795
- RangeError,
796
- `invalid payload length ${this._payloadLength}`,
797
- !0,
798
- 1002,
799
- "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
800
- );
801
- } else
802
- return this._loop = !1, g(
803
- RangeError,
804
- `invalid opcode ${this._opcode}`,
805
- !0,
806
- 1002,
807
- "WS_ERR_INVALID_OPCODE"
808
- );
809
- if (!this._fin && !this._fragmented && (this._fragmented = this._opcode), this._masked = (e[1] & 128) === 128, this._isServer) {
810
- if (!this._masked)
811
- return this._loop = !1, g(
812
- RangeError,
813
- "MASK must be set",
814
- !0,
815
- 1002,
816
- "WS_ERR_EXPECTED_MASK"
817
- );
818
- } else if (this._masked)
819
- return this._loop = !1, g(
820
- RangeError,
821
- "MASK must be clear",
822
- !0,
823
- 1002,
824
- "WS_ERR_UNEXPECTED_MASK"
825
- );
826
- if (this._payloadLength === 126)
827
- this._state = Be;
828
- else if (this._payloadLength === 127)
829
- this._state = $e;
830
- else
831
- return this.haveLength();
832
- }
833
- /**
834
- * Gets extended payload length (7+16).
835
- *
836
- * @return {(RangeError|undefined)} A possible error
837
- * @private
838
- */
839
- getPayloadLength16() {
840
- if (this._bufferedBytes < 2) {
841
- this._loop = !1;
842
- return;
843
- }
844
- return this._payloadLength = this.consume(2).readUInt16BE(0), this.haveLength();
845
- }
846
- /**
847
- * Gets extended payload length (7+64).
848
- *
849
- * @return {(RangeError|undefined)} A possible error
850
- * @private
851
- */
852
- getPayloadLength64() {
853
- if (this._bufferedBytes < 8) {
854
- this._loop = !1;
855
- return;
856
- }
857
- const e = this.consume(8), t = e.readUInt32BE(0);
858
- return t > Math.pow(2, 53 - 32) - 1 ? (this._loop = !1, g(
859
- RangeError,
860
- "Unsupported WebSocket frame: payload length > 2^53 - 1",
861
- !1,
862
- 1009,
863
- "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
864
- )) : (this._payloadLength = t * Math.pow(2, 32) + e.readUInt32BE(4), this.haveLength());
865
- }
866
- /**
867
- * Payload length has been read.
868
- *
869
- * @return {(RangeError|undefined)} A possible error
870
- * @private
871
- */
872
- haveLength() {
873
- if (this._payloadLength && this._opcode < 8 && (this._totalPayloadLength += this._payloadLength, this._totalPayloadLength > this._maxPayload && this._maxPayload > 0))
874
- return this._loop = !1, g(
875
- RangeError,
876
- "Max payload size exceeded",
877
- !1,
878
- 1009,
879
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
880
- );
881
- this._masked ? this._state = Me : this._state = _e;
882
- }
883
- /**
884
- * Reads mask bytes.
885
- *
886
- * @private
887
- */
888
- getMask() {
889
- if (this._bufferedBytes < 4) {
890
- this._loop = !1;
891
- return;
892
- }
893
- this._mask = this.consume(4), this._state = _e;
894
- }
895
- /**
896
- * Reads data bytes.
897
- *
898
- * @param {Function} cb Callback
899
- * @return {(Error|RangeError|undefined)} A possible error
900
- * @private
901
- */
902
- getData(e) {
903
- let t = Re;
904
- if (this._payloadLength) {
905
- if (this._bufferedBytes < this._payloadLength) {
906
- this._loop = !1;
907
- return;
908
- }
909
- t = this.consume(this._payloadLength), this._masked && this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3] && Ht(t, this._mask);
910
- }
911
- if (this._opcode > 7)
912
- return this.controlMessage(t);
913
- if (this._compressed) {
914
- this._state = Yt, this.decompress(t, e);
915
- return;
916
- }
917
- return t.length && (this._messageLength = this._totalPayloadLength, this._fragments.push(t)), this.dataMessage();
918
- }
919
- /**
920
- * Decompresses data.
921
- *
922
- * @param {Buffer} data Compressed data
923
- * @param {Function} cb Callback
924
- * @private
925
- */
926
- decompress(e, t) {
927
- this._extensions[Pe.extensionName].decompress(e, this._fin, (i, n) => {
928
- if (i)
929
- return t(i);
930
- if (n.length) {
931
- if (this._messageLength += n.length, this._messageLength > this._maxPayload && this._maxPayload > 0)
932
- return t(
933
- g(
934
- RangeError,
935
- "Max payload size exceeded",
936
- !1,
937
- 1009,
938
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
939
- )
940
- );
941
- this._fragments.push(n);
942
- }
943
- const o = this.dataMessage();
944
- if (o)
945
- return t(o);
946
- this.startLoop(t);
947
- });
948
- }
949
- /**
950
- * Handles a data message.
951
- *
952
- * @return {(Error|undefined)} A possible error
953
- * @private
954
- */
955
- dataMessage() {
956
- if (this._fin) {
957
- const e = this._messageLength, t = this._fragments;
958
- if (this._totalPayloadLength = 0, this._messageLength = 0, this._fragmented = 0, this._fragments = [], this._opcode === 2) {
959
- let r;
960
- this._binaryType === "nodebuffer" ? r = de(t, e) : this._binaryType === "arraybuffer" ? r = Vt(de(t, e)) : r = t, this.emit("message", r, !0);
961
- } else {
962
- const r = de(t, e);
963
- if (!this._skipUTF8Validation && !Ue(r))
964
- return this._loop = !1, g(
965
- Error,
966
- "invalid UTF-8 sequence",
967
- !0,
968
- 1007,
969
- "WS_ERR_INVALID_UTF8"
970
- );
971
- this.emit("message", r, !1);
972
- }
973
- }
974
- this._state = A;
975
- }
976
- /**
977
- * Handles a control message.
978
- *
979
- * @param {Buffer} data Data to handle
980
- * @return {(Error|RangeError|undefined)} A possible error
981
- * @private
982
- */
983
- controlMessage(e) {
984
- if (this._opcode === 8)
985
- if (this._loop = !1, e.length === 0)
986
- this.emit("conclude", 1005, Re), this.end();
987
- else {
988
- const t = e.readUInt16BE(0);
989
- if (!zt(t))
990
- return g(
991
- RangeError,
992
- `invalid status code ${t}`,
993
- !0,
994
- 1002,
995
- "WS_ERR_INVALID_CLOSE_CODE"
996
- );
997
- const r = new X(
998
- e.buffer,
999
- e.byteOffset + 2,
1000
- e.length - 2
1001
- );
1002
- if (!this._skipUTF8Validation && !Ue(r))
1003
- return g(
1004
- Error,
1005
- "invalid UTF-8 sequence",
1006
- !0,
1007
- 1007,
1008
- "WS_ERR_INVALID_UTF8"
1009
- );
1010
- this.emit("conclude", t, r), this.end();
1011
- }
1012
- else
1013
- this._opcode === 9 ? this.emit("ping", e) : this.emit("pong", e);
1014
- this._state = A;
1015
- }
1016
- };
1017
- var rt = qt;
1018
- function g(s, e, t, r, i) {
1019
- const n = new s(
1020
- t ? `Invalid WebSocket frame: ${e}` : e
1021
- );
1022
- return Error.captureStackTrace(n, g), n.code = i, n[jt] = r, n;
1023
- }
1024
- const qs = /* @__PURE__ */ z(rt), { randomFillSync: Kt } = S, Ie = oe, { EMPTY_BUFFER: Xt } = U, { isValidStatusCode: Zt } = ae, { mask: De, toBuffer: M } = ne, x = Symbol("kByteLength"), Qt = Buffer.alloc(4);
1025
- let Jt = class P {
1026
- /**
1027
- * Creates a Sender instance.
1028
- *
1029
- * @param {(net.Socket|tls.Socket)} socket The connection socket
1030
- * @param {Object} [extensions] An object containing the negotiated extensions
1031
- * @param {Function} [generateMask] The function used to generate the masking
1032
- * key
1033
- */
1034
- constructor(e, t, r) {
1035
- this._extensions = t || {}, r && (this._generateMask = r, this._maskBuffer = Buffer.alloc(4)), this._socket = e, this._firstFragment = !0, this._compress = !1, this._bufferedBytes = 0, this._deflating = !1, this._queue = [];
1036
- }
1037
- /**
1038
- * Frames a piece of data according to the HyBi WebSocket protocol.
1039
- *
1040
- * @param {(Buffer|String)} data The data to frame
1041
- * @param {Object} options Options object
1042
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1043
- * FIN bit
1044
- * @param {Function} [options.generateMask] The function used to generate the
1045
- * masking key
1046
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1047
- * `data`
1048
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1049
- * key
1050
- * @param {Number} options.opcode The opcode
1051
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1052
- * modified
1053
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1054
- * RSV1 bit
1055
- * @return {(Buffer|String)[]} The framed data
1056
- * @public
1057
- */
1058
- static frame(e, t) {
1059
- let r, i = !1, n = 2, o = !1;
1060
- t.mask && (r = t.maskBuffer || Qt, t.generateMask ? t.generateMask(r) : Kt(r, 0, 4), o = (r[0] | r[1] | r[2] | r[3]) === 0, n = 6);
1061
- let l;
1062
- typeof e == "string" ? (!t.mask || o) && t[x] !== void 0 ? l = t[x] : (e = Buffer.from(e), l = e.length) : (l = e.length, i = t.mask && t.readOnly && !o);
1063
- let f = l;
1064
- l >= 65536 ? (n += 8, f = 127) : l > 125 && (n += 2, f = 126);
1065
- const a = Buffer.allocUnsafe(i ? l + n : n);
1066
- return a[0] = t.fin ? t.opcode | 128 : t.opcode, t.rsv1 && (a[0] |= 64), a[1] = f, f === 126 ? a.writeUInt16BE(l, 2) : f === 127 && (a[2] = a[3] = 0, a.writeUIntBE(l, 4, 6)), t.mask ? (a[1] |= 128, a[n - 4] = r[0], a[n - 3] = r[1], a[n - 2] = r[2], a[n - 1] = r[3], o ? [a, e] : i ? (De(e, r, a, n, l), [a]) : (De(e, r, e, 0, l), [a, e])) : [a, e];
1067
- }
1068
- /**
1069
- * Sends a close message to the other peer.
1070
- *
1071
- * @param {Number} [code] The status code component of the body
1072
- * @param {(String|Buffer)} [data] The message component of the body
1073
- * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1074
- * @param {Function} [cb] Callback
1075
- * @public
1076
- */
1077
- close(e, t, r, i) {
1078
- let n;
1079
- if (e === void 0)
1080
- n = Xt;
1081
- else {
1082
- if (typeof e != "number" || !Zt(e))
1083
- throw new TypeError("First argument must be a valid error code number");
1084
- if (t === void 0 || !t.length)
1085
- n = Buffer.allocUnsafe(2), n.writeUInt16BE(e, 0);
1086
- else {
1087
- const l = Buffer.byteLength(t);
1088
- if (l > 123)
1089
- throw new RangeError("The message must not be greater than 123 bytes");
1090
- n = Buffer.allocUnsafe(2 + l), n.writeUInt16BE(e, 0), typeof t == "string" ? n.write(t, 2) : n.set(t, 2);
1091
- }
1092
- }
1093
- const o = {
1094
- [x]: n.length,
1095
- fin: !0,
1096
- generateMask: this._generateMask,
1097
- mask: r,
1098
- maskBuffer: this._maskBuffer,
1099
- opcode: 8,
1100
- readOnly: !1,
1101
- rsv1: !1
1102
- };
1103
- this._deflating ? this.enqueue([this.dispatch, n, !1, o, i]) : this.sendFrame(P.frame(n, o), i);
1104
- }
1105
- /**
1106
- * Sends a ping message to the other peer.
1107
- *
1108
- * @param {*} data The message to send
1109
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1110
- * @param {Function} [cb] Callback
1111
- * @public
1112
- */
1113
- ping(e, t, r) {
1114
- let i, n;
1115
- if (typeof e == "string" ? (i = Buffer.byteLength(e), n = !1) : (e = M(e), i = e.length, n = M.readOnly), i > 125)
1116
- throw new RangeError("The data size must not be greater than 125 bytes");
1117
- const o = {
1118
- [x]: i,
1119
- fin: !0,
1120
- generateMask: this._generateMask,
1121
- mask: t,
1122
- maskBuffer: this._maskBuffer,
1123
- opcode: 9,
1124
- readOnly: n,
1125
- rsv1: !1
1126
- };
1127
- this._deflating ? this.enqueue([this.dispatch, e, !1, o, r]) : this.sendFrame(P.frame(e, o), r);
1128
- }
1129
- /**
1130
- * Sends a pong message to the other peer.
1131
- *
1132
- * @param {*} data The message to send
1133
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1134
- * @param {Function} [cb] Callback
1135
- * @public
1136
- */
1137
- pong(e, t, r) {
1138
- let i, n;
1139
- if (typeof e == "string" ? (i = Buffer.byteLength(e), n = !1) : (e = M(e), i = e.length, n = M.readOnly), i > 125)
1140
- throw new RangeError("The data size must not be greater than 125 bytes");
1141
- const o = {
1142
- [x]: i,
1143
- fin: !0,
1144
- generateMask: this._generateMask,
1145
- mask: t,
1146
- maskBuffer: this._maskBuffer,
1147
- opcode: 10,
1148
- readOnly: n,
1149
- rsv1: !1
1150
- };
1151
- this._deflating ? this.enqueue([this.dispatch, e, !1, o, r]) : this.sendFrame(P.frame(e, o), r);
1152
- }
1153
- /**
1154
- * Sends a data message to the other peer.
1155
- *
1156
- * @param {*} data The message to send
1157
- * @param {Object} options Options object
1158
- * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1159
- * or text
1160
- * @param {Boolean} [options.compress=false] Specifies whether or not to
1161
- * compress `data`
1162
- * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1163
- * last one
1164
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1165
- * `data`
1166
- * @param {Function} [cb] Callback
1167
- * @public
1168
- */
1169
- send(e, t, r) {
1170
- const i = this._extensions[Ie.extensionName];
1171
- let n = t.binary ? 2 : 1, o = t.compress, l, f;
1172
- if (typeof e == "string" ? (l = Buffer.byteLength(e), f = !1) : (e = M(e), l = e.length, f = M.readOnly), this._firstFragment ? (this._firstFragment = !1, o && i && i.params[i._isServer ? "server_no_context_takeover" : "client_no_context_takeover"] && (o = l >= i._threshold), this._compress = o) : (o = !1, n = 0), t.fin && (this._firstFragment = !0), i) {
1173
- const a = {
1174
- [x]: l,
1175
- fin: t.fin,
1176
- generateMask: this._generateMask,
1177
- mask: t.mask,
1178
- maskBuffer: this._maskBuffer,
1179
- opcode: n,
1180
- readOnly: f,
1181
- rsv1: o
1182
- };
1183
- this._deflating ? this.enqueue([this.dispatch, e, this._compress, a, r]) : this.dispatch(e, this._compress, a, r);
1184
- } else
1185
- this.sendFrame(
1186
- P.frame(e, {
1187
- [x]: l,
1188
- fin: t.fin,
1189
- generateMask: this._generateMask,
1190
- mask: t.mask,
1191
- maskBuffer: this._maskBuffer,
1192
- opcode: n,
1193
- readOnly: f,
1194
- rsv1: !1
1195
- }),
1196
- r
1197
- );
1198
- }
1199
- /**
1200
- * Dispatches a message.
1201
- *
1202
- * @param {(Buffer|String)} data The message to send
1203
- * @param {Boolean} [compress=false] Specifies whether or not to compress
1204
- * `data`
1205
- * @param {Object} options Options object
1206
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1207
- * FIN bit
1208
- * @param {Function} [options.generateMask] The function used to generate the
1209
- * masking key
1210
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1211
- * `data`
1212
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1213
- * key
1214
- * @param {Number} options.opcode The opcode
1215
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1216
- * modified
1217
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1218
- * RSV1 bit
1219
- * @param {Function} [cb] Callback
1220
- * @private
1221
- */
1222
- dispatch(e, t, r, i) {
1223
- if (!t) {
1224
- this.sendFrame(P.frame(e, r), i);
1225
- return;
1226
- }
1227
- const n = this._extensions[Ie.extensionName];
1228
- this._bufferedBytes += r[x], this._deflating = !0, n.compress(e, r.fin, (o, l) => {
1229
- if (this._socket.destroyed) {
1230
- const f = new Error(
1231
- "The socket was closed while data was being compressed"
1232
- );
1233
- typeof i == "function" && i(f);
1234
- for (let a = 0; a < this._queue.length; a++) {
1235
- const c = this._queue[a], h = c[c.length - 1];
1236
- typeof h == "function" && h(f);
1237
- }
1238
- return;
1239
- }
1240
- this._bufferedBytes -= r[x], this._deflating = !1, r.readOnly = !1, this.sendFrame(P.frame(l, r), i), this.dequeue();
1241
- });
1242
- }
1243
- /**
1244
- * Executes queued send operations.
1245
- *
1246
- * @private
1247
- */
1248
- dequeue() {
1249
- for (; !this._deflating && this._queue.length; ) {
1250
- const e = this._queue.shift();
1251
- this._bufferedBytes -= e[3][x], Reflect.apply(e[0], this, e.slice(1));
1252
- }
1253
- }
1254
- /**
1255
- * Enqueues a send operation.
1256
- *
1257
- * @param {Array} params Send operation parameters.
1258
- * @private
1259
- */
1260
- enqueue(e) {
1261
- this._bufferedBytes += e[3][x], this._queue.push(e);
1262
- }
1263
- /**
1264
- * Sends a frame.
1265
- *
1266
- * @param {Buffer[]} list The frame to send
1267
- * @param {Function} [cb] Callback
1268
- * @private
1269
- */
1270
- sendFrame(e, t) {
1271
- e.length === 2 ? (this._socket.cork(), this._socket.write(e[0]), this._socket.write(e[1], t), this._socket.uncork()) : this._socket.write(e[0], t);
1272
- }
1273
- };
1274
- var it = Jt;
1275
- const Ks = /* @__PURE__ */ z(it), { kForOnEventAttribute: F, kListener: pe } = U, We = Symbol("kCode"), Ae = Symbol("kData"), Fe = Symbol("kError"), je = Symbol("kMessage"), Ge = Symbol("kReason"), I = Symbol("kTarget"), Ve = Symbol("kType"), He = Symbol("kWasClean");
1276
- class B {
1277
- /**
1278
- * Create a new `Event`.
1279
- *
1280
- * @param {String} type The name of the event
1281
- * @throws {TypeError} If the `type` argument is not specified
1282
- */
1283
- constructor(e) {
1284
- this[I] = null, this[Ve] = e;
1285
- }
1286
- /**
1287
- * @type {*}
1288
- */
1289
- get target() {
1290
- return this[I];
1291
- }
1292
- /**
1293
- * @type {String}
1294
- */
1295
- get type() {
1296
- return this[Ve];
1297
- }
1298
- }
1299
- Object.defineProperty(B.prototype, "target", { enumerable: !0 });
1300
- Object.defineProperty(B.prototype, "type", { enumerable: !0 });
1301
- class Y extends B {
1302
- /**
1303
- * Create a new `CloseEvent`.
1304
- *
1305
- * @param {String} type The name of the event
1306
- * @param {Object} [options] A dictionary object that allows for setting
1307
- * attributes via object members of the same name
1308
- * @param {Number} [options.code=0] The status code explaining why the
1309
- * connection was closed
1310
- * @param {String} [options.reason=''] A human-readable string explaining why
1311
- * the connection was closed
1312
- * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1313
- * connection was cleanly closed
1314
- */
1315
- constructor(e, t = {}) {
1316
- super(e), this[We] = t.code === void 0 ? 0 : t.code, this[Ge] = t.reason === void 0 ? "" : t.reason, this[He] = t.wasClean === void 0 ? !1 : t.wasClean;
1317
- }
1318
- /**
1319
- * @type {Number}
1320
- */
1321
- get code() {
1322
- return this[We];
1323
- }
1324
- /**
1325
- * @type {String}
1326
- */
1327
- get reason() {
1328
- return this[Ge];
1329
- }
1330
- /**
1331
- * @type {Boolean}
1332
- */
1333
- get wasClean() {
1334
- return this[He];
1335
- }
1336
- }
1337
- Object.defineProperty(Y.prototype, "code", { enumerable: !0 });
1338
- Object.defineProperty(Y.prototype, "reason", { enumerable: !0 });
1339
- Object.defineProperty(Y.prototype, "wasClean", { enumerable: !0 });
1340
- class le extends B {
1341
- /**
1342
- * Create a new `ErrorEvent`.
1343
- *
1344
- * @param {String} type The name of the event
1345
- * @param {Object} [options] A dictionary object that allows for setting
1346
- * attributes via object members of the same name
1347
- * @param {*} [options.error=null] The error that generated this event
1348
- * @param {String} [options.message=''] The error message
1349
- */
1350
- constructor(e, t = {}) {
1351
- super(e), this[Fe] = t.error === void 0 ? null : t.error, this[je] = t.message === void 0 ? "" : t.message;
1352
- }
1353
- /**
1354
- * @type {*}
1355
- */
1356
- get error() {
1357
- return this[Fe];
1358
- }
1359
- /**
1360
- * @type {String}
1361
- */
1362
- get message() {
1363
- return this[je];
1364
- }
1365
- }
1366
- Object.defineProperty(le.prototype, "error", { enumerable: !0 });
1367
- Object.defineProperty(le.prototype, "message", { enumerable: !0 });
1368
- class xe extends B {
1369
- /**
1370
- * Create a new `MessageEvent`.
1371
- *
1372
- * @param {String} type The name of the event
1373
- * @param {Object} [options] A dictionary object that allows for setting
1374
- * attributes via object members of the same name
1375
- * @param {*} [options.data=null] The message content
1376
- */
1377
- constructor(e, t = {}) {
1378
- super(e), this[Ae] = t.data === void 0 ? null : t.data;
1379
- }
1380
- /**
1381
- * @type {*}
1382
- */
1383
- get data() {
1384
- return this[Ae];
1385
- }
1386
- }
1387
- Object.defineProperty(xe.prototype, "data", { enumerable: !0 });
1388
- const es = {
1389
- /**
1390
- * Register an event listener.
1391
- *
1392
- * @param {String} type A string representing the event type to listen for
1393
- * @param {(Function|Object)} handler The listener to add
1394
- * @param {Object} [options] An options object specifies characteristics about
1395
- * the event listener
1396
- * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1397
- * listener should be invoked at most once after being added. If `true`,
1398
- * the listener would be automatically removed when invoked.
1399
- * @public
1400
- */
1401
- addEventListener(s, e, t = {}) {
1402
- for (const i of this.listeners(s))
1403
- if (!t[F] && i[pe] === e && !i[F])
1404
- return;
1405
- let r;
1406
- if (s === "message")
1407
- r = function(n, o) {
1408
- const l = new xe("message", {
1409
- data: o ? n : n.toString()
1410
- });
1411
- l[I] = this, Z(e, this, l);
1412
- };
1413
- else if (s === "close")
1414
- r = function(n, o) {
1415
- const l = new Y("close", {
1416
- code: n,
1417
- reason: o.toString(),
1418
- wasClean: this._closeFrameReceived && this._closeFrameSent
1419
- });
1420
- l[I] = this, Z(e, this, l);
1421
- };
1422
- else if (s === "error")
1423
- r = function(n) {
1424
- const o = new le("error", {
1425
- error: n,
1426
- message: n.message
1427
- });
1428
- o[I] = this, Z(e, this, o);
1429
- };
1430
- else if (s === "open")
1431
- r = function() {
1432
- const n = new B("open");
1433
- n[I] = this, Z(e, this, n);
1434
- };
1435
- else
1436
- return;
1437
- r[F] = !!t[F], r[pe] = e, t.once ? this.once(s, r) : this.on(s, r);
1438
- },
1439
- /**
1440
- * Remove an event listener.
1441
- *
1442
- * @param {String} type A string representing the event type to remove
1443
- * @param {(Function|Object)} handler The listener to remove
1444
- * @public
1445
- */
1446
- removeEventListener(s, e) {
1447
- for (const t of this.listeners(s))
1448
- if (t[pe] === e && !t[F]) {
1449
- this.removeListener(s, t);
1450
- break;
1451
- }
1452
- }
1453
- };
1454
- var ts = {
1455
- CloseEvent: Y,
1456
- ErrorEvent: le,
1457
- Event: B,
1458
- EventTarget: es,
1459
- MessageEvent: xe
1460
- };
1461
- function Z(s, e, t) {
1462
- typeof s == "object" && s.handleEvent ? s.handleEvent.call(s, t) : s.call(e, t);
1463
- }
1464
- const { tokenChars: j } = ae;
1465
- function k(s, e, t) {
1466
- s[e] === void 0 ? s[e] = [t] : s[e].push(t);
1467
- }
1468
- function ss(s) {
1469
- const e = /* @__PURE__ */ Object.create(null);
1470
- let t = /* @__PURE__ */ Object.create(null), r = !1, i = !1, n = !1, o, l, f = -1, a = -1, c = -1, h = 0;
1471
- for (; h < s.length; h++)
1472
- if (a = s.charCodeAt(h), o === void 0)
1473
- if (c === -1 && j[a] === 1)
1474
- f === -1 && (f = h);
1475
- else if (h !== 0 && (a === 32 || a === 9))
1476
- c === -1 && f !== -1 && (c = h);
1477
- else if (a === 59 || a === 44) {
1478
- if (f === -1)
1479
- throw new SyntaxError(`Unexpected character at index ${h}`);
1480
- c === -1 && (c = h);
1481
- const v = s.slice(f, c);
1482
- a === 44 ? (k(e, v, t), t = /* @__PURE__ */ Object.create(null)) : o = v, f = c = -1;
1483
- } else
1484
- throw new SyntaxError(`Unexpected character at index ${h}`);
1485
- else if (l === void 0)
1486
- if (c === -1 && j[a] === 1)
1487
- f === -1 && (f = h);
1488
- else if (a === 32 || a === 9)
1489
- c === -1 && f !== -1 && (c = h);
1490
- else if (a === 59 || a === 44) {
1491
- if (f === -1)
1492
- throw new SyntaxError(`Unexpected character at index ${h}`);
1493
- c === -1 && (c = h), k(t, s.slice(f, c), !0), a === 44 && (k(e, o, t), t = /* @__PURE__ */ Object.create(null), o = void 0), f = c = -1;
1494
- } else if (a === 61 && f !== -1 && c === -1)
1495
- l = s.slice(f, h), f = c = -1;
1496
- else
1497
- throw new SyntaxError(`Unexpected character at index ${h}`);
1498
- else if (i) {
1499
- if (j[a] !== 1)
1500
- throw new SyntaxError(`Unexpected character at index ${h}`);
1501
- f === -1 ? f = h : r || (r = !0), i = !1;
1502
- } else if (n)
1503
- if (j[a] === 1)
1504
- f === -1 && (f = h);
1505
- else if (a === 34 && f !== -1)
1506
- n = !1, c = h;
1507
- else if (a === 92)
1508
- i = !0;
1509
- else
1510
- throw new SyntaxError(`Unexpected character at index ${h}`);
1511
- else if (a === 34 && s.charCodeAt(h - 1) === 61)
1512
- n = !0;
1513
- else if (c === -1 && j[a] === 1)
1514
- f === -1 && (f = h);
1515
- else if (f !== -1 && (a === 32 || a === 9))
1516
- c === -1 && (c = h);
1517
- else if (a === 59 || a === 44) {
1518
- if (f === -1)
1519
- throw new SyntaxError(`Unexpected character at index ${h}`);
1520
- c === -1 && (c = h);
1521
- let v = s.slice(f, c);
1522
- r && (v = v.replace(/\\/g, ""), r = !1), k(t, l, v), a === 44 && (k(e, o, t), t = /* @__PURE__ */ Object.create(null), o = void 0), l = void 0, f = c = -1;
1523
- } else
1524
- throw new SyntaxError(`Unexpected character at index ${h}`);
1525
- if (f === -1 || n || a === 32 || a === 9)
1526
- throw new SyntaxError("Unexpected end of input");
1527
- c === -1 && (c = h);
1528
- const p = s.slice(f, c);
1529
- return o === void 0 ? k(e, p, t) : (l === void 0 ? k(t, p, !0) : r ? k(t, l, p.replace(/\\/g, "")) : k(t, l, p), k(e, o, t)), e;
1530
- }
1531
- function rs(s) {
1532
- return Object.keys(s).map((e) => {
1533
- let t = s[e];
1534
- return Array.isArray(t) || (t = [t]), t.map((r) => [e].concat(
1535
- Object.keys(r).map((i) => {
1536
- let n = r[i];
1537
- return Array.isArray(n) || (n = [n]), n.map((o) => o === !0 ? i : `${i}=${o}`).join("; ");
1538
- })
1539
- ).join("; ")).join(", ");
1540
- }).join(", ");
1541
- }
1542
- var nt = { format: rs, parse: ss };
1543
- const is = S, ns = S, os = S, ot = S, as = S, { randomBytes: ls, createHash: fs } = S, { URL: me } = S, T = oe, hs = rt, cs = it, {
1544
- BINARY_TYPES: ze,
1545
- EMPTY_BUFFER: Q,
1546
- GUID: us,
1547
- kForOnEventAttribute: ge,
1548
- kListener: ds,
1549
- kStatusCode: _s,
1550
- kWebSocket: y,
1551
- NOOP: at
1552
- } = U, {
1553
- EventTarget: { addEventListener: ps, removeEventListener: ms }
1554
- } = ts, { format: gs, parse: ys } = nt, { toBuffer: vs } = ne, Ss = 30 * 1e3, lt = Symbol("kAborted"), ye = [8, 13], O = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"], Es = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
1555
- let m = class d extends is {
1556
- /**
1557
- * Create a new `WebSocket`.
1558
- *
1559
- * @param {(String|URL)} address The URL to which to connect
1560
- * @param {(String|String[])} [protocols] The subprotocols
1561
- * @param {Object} [options] Connection options
1562
- */
1563
- constructor(e, t, r) {
1564
- super(), this._binaryType = ze[0], this._closeCode = 1006, this._closeFrameReceived = !1, this._closeFrameSent = !1, this._closeMessage = Q, this._closeTimer = null, this._extensions = {}, this._paused = !1, this._protocol = "", this._readyState = d.CONNECTING, this._receiver = null, this._sender = null, this._socket = null, e !== null ? (this._bufferedAmount = 0, this._isServer = !1, this._redirects = 0, t === void 0 ? t = [] : Array.isArray(t) || (typeof t == "object" && t !== null ? (r = t, t = []) : t = [t]), ht(this, e, t, r)) : this._isServer = !0;
1565
- }
1566
- /**
1567
- * This deviates from the WHATWG interface since ws doesn't support the
1568
- * required default "blob" type (instead we define a custom "nodebuffer"
1569
- * type).
1570
- *
1571
- * @type {String}
1572
- */
1573
- get binaryType() {
1574
- return this._binaryType;
1575
- }
1576
- set binaryType(e) {
1577
- ze.includes(e) && (this._binaryType = e, this._receiver && (this._receiver._binaryType = e));
1578
- }
1579
- /**
1580
- * @type {Number}
1581
- */
1582
- get bufferedAmount() {
1583
- return this._socket ? this._socket._writableState.length + this._sender._bufferedBytes : this._bufferedAmount;
1584
- }
1585
- /**
1586
- * @type {String}
1587
- */
1588
- get extensions() {
1589
- return Object.keys(this._extensions).join();
1590
- }
1591
- /**
1592
- * @type {Boolean}
1593
- */
1594
- get isPaused() {
1595
- return this._paused;
1596
- }
1597
- /**
1598
- * @type {Function}
1599
- */
1600
- /* istanbul ignore next */
1601
- get onclose() {
1602
- return null;
1603
- }
1604
- /**
1605
- * @type {Function}
1606
- */
1607
- /* istanbul ignore next */
1608
- get onerror() {
1609
- return null;
1610
- }
1611
- /**
1612
- * @type {Function}
1613
- */
1614
- /* istanbul ignore next */
1615
- get onopen() {
1616
- return null;
1617
- }
1618
- /**
1619
- * @type {Function}
1620
- */
1621
- /* istanbul ignore next */
1622
- get onmessage() {
1623
- return null;
1624
- }
1625
- /**
1626
- * @type {String}
1627
- */
1628
- get protocol() {
1629
- return this._protocol;
1630
- }
1631
- /**
1632
- * @type {Number}
1633
- */
1634
- get readyState() {
1635
- return this._readyState;
1636
- }
1637
- /**
1638
- * @type {String}
1639
- */
1640
- get url() {
1641
- return this._url;
1642
- }
1643
- /**
1644
- * Set up the socket and the internal resources.
1645
- *
1646
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
1647
- * server and client
1648
- * @param {Buffer} head The first packet of the upgraded stream
1649
- * @param {Object} options Options object
1650
- * @param {Function} [options.generateMask] The function used to generate the
1651
- * masking key
1652
- * @param {Number} [options.maxPayload=0] The maximum allowed message size
1653
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
1654
- * not to skip UTF-8 validation for text and close messages
1655
- * @private
1656
- */
1657
- setSocket(e, t, r) {
1658
- const i = new hs({
1659
- binaryType: this.binaryType,
1660
- extensions: this._extensions,
1661
- isServer: this._isServer,
1662
- maxPayload: r.maxPayload,
1663
- skipUTF8Validation: r.skipUTF8Validation
1664
- });
1665
- this._sender = new cs(e, this._extensions, r.generateMask), this._receiver = i, this._socket = e, i[y] = this, e[y] = this, i.on("conclude", ks), i.on("drain", ws), i.on("error", Os), i.on("message", Cs), i.on("ping", Ts), i.on("pong", Ls), e.setTimeout(0), e.setNoDelay(), t.length > 0 && e.unshift(t), e.on("close", ut), e.on("data", fe), e.on("end", dt), e.on("error", _t), this._readyState = d.OPEN, this.emit("open");
1666
- }
1667
- /**
1668
- * Emit the `'close'` event.
1669
- *
1670
- * @private
1671
- */
1672
- emitClose() {
1673
- if (!this._socket) {
1674
- this._readyState = d.CLOSED, this.emit("close", this._closeCode, this._closeMessage);
1675
- return;
1676
- }
1677
- this._extensions[T.extensionName] && this._extensions[T.extensionName].cleanup(), this._receiver.removeAllListeners(), this._readyState = d.CLOSED, this.emit("close", this._closeCode, this._closeMessage);
1678
- }
1679
- /**
1680
- * Start a closing handshake.
1681
- *
1682
- * +----------+ +-----------+ +----------+
1683
- * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
1684
- * | +----------+ +-----------+ +----------+ |
1685
- * +----------+ +-----------+ |
1686
- * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
1687
- * +----------+ +-----------+ |
1688
- * | | | +---+ |
1689
- * +------------------------+-->|fin| - - - -
1690
- * | +---+ | +---+
1691
- * - - - - -|fin|<---------------------+
1692
- * +---+
1693
- *
1694
- * @param {Number} [code] Status code explaining why the connection is closing
1695
- * @param {(String|Buffer)} [data] The reason why the connection is
1696
- * closing
1697
- * @public
1698
- */
1699
- close(e, t) {
1700
- if (this.readyState !== d.CLOSED) {
1701
- if (this.readyState === d.CONNECTING) {
1702
- const r = "WebSocket was closed before the connection was established";
1703
- b(this, this._req, r);
1704
- return;
1705
- }
1706
- if (this.readyState === d.CLOSING) {
1707
- this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end();
1708
- return;
1709
- }
1710
- this._readyState = d.CLOSING, this._sender.close(e, t, !this._isServer, (r) => {
1711
- r || (this._closeFrameSent = !0, (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end());
1712
- }), this._closeTimer = setTimeout(
1713
- this._socket.destroy.bind(this._socket),
1714
- Ss
1715
- );
1716
- }
1717
- }
1718
- /**
1719
- * Pause the socket.
1720
- *
1721
- * @public
1722
- */
1723
- pause() {
1724
- this.readyState === d.CONNECTING || this.readyState === d.CLOSED || (this._paused = !0, this._socket.pause());
1725
- }
1726
- /**
1727
- * Send a ping.
1728
- *
1729
- * @param {*} [data] The data to send
1730
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
1731
- * @param {Function} [cb] Callback which is executed when the ping is sent
1732
- * @public
1733
- */
1734
- ping(e, t, r) {
1735
- if (this.readyState === d.CONNECTING)
1736
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1737
- if (typeof e == "function" ? (r = e, e = t = void 0) : typeof t == "function" && (r = t, t = void 0), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1738
- ve(this, e, r);
1739
- return;
1740
- }
1741
- t === void 0 && (t = !this._isServer), this._sender.ping(e || Q, t, r);
1742
- }
1743
- /**
1744
- * Send a pong.
1745
- *
1746
- * @param {*} [data] The data to send
1747
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
1748
- * @param {Function} [cb] Callback which is executed when the pong is sent
1749
- * @public
1750
- */
1751
- pong(e, t, r) {
1752
- if (this.readyState === d.CONNECTING)
1753
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1754
- if (typeof e == "function" ? (r = e, e = t = void 0) : typeof t == "function" && (r = t, t = void 0), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1755
- ve(this, e, r);
1756
- return;
1757
- }
1758
- t === void 0 && (t = !this._isServer), this._sender.pong(e || Q, t, r);
1759
- }
1760
- /**
1761
- * Resume the socket.
1762
- *
1763
- * @public
1764
- */
1765
- resume() {
1766
- this.readyState === d.CONNECTING || this.readyState === d.CLOSED || (this._paused = !1, this._receiver._writableState.needDrain || this._socket.resume());
1767
- }
1768
- /**
1769
- * Send a data message.
1770
- *
1771
- * @param {*} data The message to send
1772
- * @param {Object} [options] Options object
1773
- * @param {Boolean} [options.binary] Specifies whether `data` is binary or
1774
- * text
1775
- * @param {Boolean} [options.compress] Specifies whether or not to compress
1776
- * `data`
1777
- * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
1778
- * last one
1779
- * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
1780
- * @param {Function} [cb] Callback which is executed when data is written out
1781
- * @public
1782
- */
1783
- send(e, t, r) {
1784
- if (this.readyState === d.CONNECTING)
1785
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1786
- if (typeof t == "function" && (r = t, t = {}), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1787
- ve(this, e, r);
1788
- return;
1789
- }
1790
- const i = {
1791
- binary: typeof e != "string",
1792
- mask: !this._isServer,
1793
- compress: !0,
1794
- fin: !0,
1795
- ...t
1796
- };
1797
- this._extensions[T.extensionName] || (i.compress = !1), this._sender.send(e || Q, i, r);
1798
- }
1799
- /**
1800
- * Forcibly close the connection.
1801
- *
1802
- * @public
1803
- */
1804
- terminate() {
1805
- if (this.readyState !== d.CLOSED) {
1806
- if (this.readyState === d.CONNECTING) {
1807
- const e = "WebSocket was closed before the connection was established";
1808
- b(this, this._req, e);
1809
- return;
1810
- }
1811
- this._socket && (this._readyState = d.CLOSING, this._socket.destroy());
1812
- }
1813
- }
1814
- };
1815
- Object.defineProperty(m, "CONNECTING", {
1816
- enumerable: !0,
1817
- value: O.indexOf("CONNECTING")
1818
- });
1819
- Object.defineProperty(m.prototype, "CONNECTING", {
1820
- enumerable: !0,
1821
- value: O.indexOf("CONNECTING")
1822
- });
1823
- Object.defineProperty(m, "OPEN", {
1824
- enumerable: !0,
1825
- value: O.indexOf("OPEN")
1826
- });
1827
- Object.defineProperty(m.prototype, "OPEN", {
1828
- enumerable: !0,
1829
- value: O.indexOf("OPEN")
1830
- });
1831
- Object.defineProperty(m, "CLOSING", {
1832
- enumerable: !0,
1833
- value: O.indexOf("CLOSING")
1834
- });
1835
- Object.defineProperty(m.prototype, "CLOSING", {
1836
- enumerable: !0,
1837
- value: O.indexOf("CLOSING")
1838
- });
1839
- Object.defineProperty(m, "CLOSED", {
1840
- enumerable: !0,
1841
- value: O.indexOf("CLOSED")
1842
- });
1843
- Object.defineProperty(m.prototype, "CLOSED", {
1844
- enumerable: !0,
1845
- value: O.indexOf("CLOSED")
1846
- });
1847
- [
1848
- "binaryType",
1849
- "bufferedAmount",
1850
- "extensions",
1851
- "isPaused",
1852
- "protocol",
1853
- "readyState",
1854
- "url"
1855
- ].forEach((s) => {
1856
- Object.defineProperty(m.prototype, s, { enumerable: !0 });
1857
- });
1858
- ["open", "error", "close", "message"].forEach((s) => {
1859
- Object.defineProperty(m.prototype, `on${s}`, {
1860
- enumerable: !0,
1861
- get() {
1862
- for (const e of this.listeners(s))
1863
- if (e[ge])
1864
- return e[ds];
1865
- return null;
1866
- },
1867
- set(e) {
1868
- for (const t of this.listeners(s))
1869
- if (t[ge]) {
1870
- this.removeListener(s, t);
1871
- break;
1872
- }
1873
- typeof e == "function" && this.addEventListener(s, e, {
1874
- [ge]: !0
1875
- });
1876
- }
1877
- });
1878
- });
1879
- m.prototype.addEventListener = ps;
1880
- m.prototype.removeEventListener = ms;
1881
- var ft = m;
1882
- function ht(s, e, t, r) {
1883
- const i = {
1884
- protocolVersion: ye[1],
1885
- maxPayload: 104857600,
1886
- skipUTF8Validation: !1,
1887
- perMessageDeflate: !0,
1888
- followRedirects: !1,
1889
- maxRedirects: 10,
1890
- ...r,
1891
- createConnection: void 0,
1892
- socketPath: void 0,
1893
- hostname: void 0,
1894
- protocol: void 0,
1895
- timeout: void 0,
1896
- method: "GET",
1897
- host: void 0,
1898
- path: void 0,
1899
- port: void 0
1900
- };
1901
- if (!ye.includes(i.protocolVersion))
1902
- throw new RangeError(
1903
- `Unsupported protocol version: ${i.protocolVersion} (supported versions: ${ye.join(", ")})`
1904
- );
1905
- let n;
1906
- if (e instanceof me)
1907
- n = e, s._url = e.href;
1908
- else {
1909
- try {
1910
- n = new me(e);
1911
- } catch {
1912
- throw new SyntaxError(`Invalid URL: ${e}`);
1913
- }
1914
- s._url = e;
1915
- }
1916
- const o = n.protocol === "wss:", l = n.protocol === "ws+unix:";
1917
- let f;
1918
- if (n.protocol !== "ws:" && !o && !l ? f = `The URL's protocol must be one of "ws:", "wss:", or "ws+unix:"` : l && !n.pathname ? f = "The URL's pathname is empty" : n.hash && (f = "The URL contains a fragment identifier"), f) {
1919
- const u = new SyntaxError(f);
1920
- if (s._redirects === 0)
1921
- throw u;
1922
- ee(s, u);
1923
- return;
1924
- }
1925
- const a = o ? 443 : 80, c = ls(16).toString("base64"), h = o ? ns.request : os.request, p = /* @__PURE__ */ new Set();
1926
- let v;
1927
- if (i.createConnection = o ? xs : bs, i.defaultPort = i.defaultPort || a, i.port = n.port || a, i.host = n.hostname.startsWith("[") ? n.hostname.slice(1, -1) : n.hostname, i.headers = {
1928
- ...i.headers,
1929
- "Sec-WebSocket-Version": i.protocolVersion,
1930
- "Sec-WebSocket-Key": c,
1931
- Connection: "Upgrade",
1932
- Upgrade: "websocket"
1933
- }, i.path = n.pathname + n.search, i.timeout = i.handshakeTimeout, i.perMessageDeflate && (v = new T(
1934
- i.perMessageDeflate !== !0 ? i.perMessageDeflate : {},
1935
- !1,
1936
- i.maxPayload
1937
- ), i.headers["Sec-WebSocket-Extensions"] = gs({
1938
- [T.extensionName]: v.offer()
1939
- })), t.length) {
1940
- for (const u of t) {
1941
- if (typeof u != "string" || !Es.test(u) || p.has(u))
1942
- throw new SyntaxError(
1943
- "An invalid or duplicated subprotocol was specified"
1944
- );
1945
- p.add(u);
1946
- }
1947
- i.headers["Sec-WebSocket-Protocol"] = t.join(",");
1948
- }
1949
- if (i.origin && (i.protocolVersion < 13 ? i.headers["Sec-WebSocket-Origin"] = i.origin : i.headers.Origin = i.origin), (n.username || n.password) && (i.auth = `${n.username}:${n.password}`), l) {
1950
- const u = i.path.split(":");
1951
- i.socketPath = u[0], i.path = u[1];
1952
- }
1953
- let _;
1954
- if (i.followRedirects) {
1955
- if (s._redirects === 0) {
1956
- s._originalIpc = l, s._originalSecure = o, s._originalHostOrSocketPath = l ? i.socketPath : n.host;
1957
- const u = r && r.headers;
1958
- if (r = { ...r, headers: {} }, u)
1959
- for (const [E, $] of Object.entries(u))
1960
- r.headers[E.toLowerCase()] = $;
1961
- } else if (s.listenerCount("redirect") === 0) {
1962
- const u = l ? s._originalIpc ? i.socketPath === s._originalHostOrSocketPath : !1 : s._originalIpc ? !1 : n.host === s._originalHostOrSocketPath;
1963
- (!u || s._originalSecure && !o) && (delete i.headers.authorization, delete i.headers.cookie, u || delete i.headers.host, i.auth = void 0);
1964
- }
1965
- i.auth && !r.headers.authorization && (r.headers.authorization = "Basic " + Buffer.from(i.auth).toString("base64")), _ = s._req = h(i), s._redirects && s.emit("redirect", s.url, _);
1966
- } else
1967
- _ = s._req = h(i);
1968
- i.timeout && _.on("timeout", () => {
1969
- b(s, _, "Opening handshake has timed out");
1970
- }), _.on("error", (u) => {
1971
- _ === null || _[lt] || (_ = s._req = null, ee(s, u));
1972
- }), _.on("response", (u) => {
1973
- const E = u.headers.location, $ = u.statusCode;
1974
- if (E && i.followRedirects && $ >= 300 && $ < 400) {
1975
- if (++s._redirects > i.maxRedirects) {
1976
- b(s, _, "Maximum redirects exceeded");
1977
- return;
1978
- }
1979
- _.abort();
1980
- let q;
1981
- try {
1982
- q = new me(E, e);
1983
- } catch {
1984
- const L = new SyntaxError(`Invalid URL: ${E}`);
1985
- ee(s, L);
1986
- return;
1987
- }
1988
- ht(s, q, t, r);
1989
- } else
1990
- s.emit("unexpected-response", _, u) || b(
1991
- s,
1992
- _,
1993
- `Unexpected server response: ${u.statusCode}`
1994
- );
1995
- }), _.on("upgrade", (u, E, $) => {
1996
- if (s.emit("upgrade", u), s.readyState !== m.CONNECTING)
1997
- return;
1998
- if (_ = s._req = null, u.headers.upgrade.toLowerCase() !== "websocket") {
1999
- b(s, E, "Invalid Upgrade header");
2000
- return;
2001
- }
2002
- const q = fs("sha1").update(c + us).digest("base64");
2003
- if (u.headers["sec-websocket-accept"] !== q) {
2004
- b(s, E, "Invalid Sec-WebSocket-Accept header");
2005
- return;
2006
- }
2007
- const D = u.headers["sec-websocket-protocol"];
2008
- let L;
2009
- if (D !== void 0 ? p.size ? p.has(D) || (L = "Server sent an invalid subprotocol") : L = "Server sent a subprotocol but none was requested" : p.size && (L = "Server sent no subprotocol"), L) {
2010
- b(s, E, L);
2011
- return;
2012
- }
2013
- D && (s._protocol = D);
2014
- const ke = u.headers["sec-websocket-extensions"];
2015
- if (ke !== void 0) {
2016
- if (!v) {
2017
- b(s, E, "Server sent a Sec-WebSocket-Extensions header but no extension was requested");
2018
- return;
2019
- }
2020
- let he;
2021
- try {
2022
- he = ys(ke);
2023
- } catch {
2024
- b(s, E, "Invalid Sec-WebSocket-Extensions header");
2025
- return;
2026
- }
2027
- const we = Object.keys(he);
2028
- if (we.length !== 1 || we[0] !== T.extensionName) {
2029
- b(s, E, "Server indicated an extension that was not requested");
2030
- return;
2031
- }
2032
- try {
2033
- v.accept(he[T.extensionName]);
2034
- } catch {
2035
- b(s, E, "Invalid Sec-WebSocket-Extensions header");
2036
- return;
2037
- }
2038
- s._extensions[T.extensionName] = v;
2039
- }
2040
- s.setSocket(E, $, {
2041
- generateMask: i.generateMask,
2042
- maxPayload: i.maxPayload,
2043
- skipUTF8Validation: i.skipUTF8Validation
2044
- });
2045
- }), i.finishRequest ? i.finishRequest(_, s) : _.end();
2046
- }
2047
- function ee(s, e) {
2048
- s._readyState = m.CLOSING, s.emit("error", e), s.emitClose();
2049
- }
2050
- function bs(s) {
2051
- return s.path = s.socketPath, ot.connect(s);
2052
- }
2053
- function xs(s) {
2054
- return s.path = void 0, !s.servername && s.servername !== "" && (s.servername = ot.isIP(s.host) ? "" : s.host), as.connect(s);
2055
- }
2056
- function b(s, e, t) {
2057
- s._readyState = m.CLOSING;
2058
- const r = new Error(t);
2059
- Error.captureStackTrace(r, b), e.setHeader ? (e[lt] = !0, e.abort(), e.socket && !e.socket.destroyed && e.socket.destroy(), process.nextTick(ee, s, r)) : (e.destroy(r), e.once("error", s.emit.bind(s, "error")), e.once("close", s.emitClose.bind(s)));
2060
- }
2061
- function ve(s, e, t) {
2062
- if (e) {
2063
- const r = vs(e).length;
2064
- s._socket ? s._sender._bufferedBytes += r : s._bufferedAmount += r;
2065
- }
2066
- if (t) {
2067
- const r = new Error(
2068
- `WebSocket is not open: readyState ${s.readyState} (${O[s.readyState]})`
2069
- );
2070
- process.nextTick(t, r);
2071
- }
2072
- }
2073
- function ks(s, e) {
2074
- const t = this[y];
2075
- t._closeFrameReceived = !0, t._closeMessage = e, t._closeCode = s, t._socket[y] !== void 0 && (t._socket.removeListener("data", fe), process.nextTick(ct, t._socket), s === 1005 ? t.close() : t.close(s, e));
2076
- }
2077
- function ws() {
2078
- const s = this[y];
2079
- s.isPaused || s._socket.resume();
2080
- }
2081
- function Os(s) {
2082
- const e = this[y];
2083
- e._socket[y] !== void 0 && (e._socket.removeListener("data", fe), process.nextTick(ct, e._socket), e.close(s[_s])), e.emit("error", s);
2084
- }
2085
- function Ye() {
2086
- this[y].emitClose();
2087
- }
2088
- function Cs(s, e) {
2089
- this[y].emit("message", s, e);
2090
- }
2091
- function Ts(s) {
2092
- const e = this[y];
2093
- e.pong(s, !e._isServer, at), e.emit("ping", s);
2094
- }
2095
- function Ls(s) {
2096
- this[y].emit("pong", s);
2097
- }
2098
- function ct(s) {
2099
- s.resume();
2100
- }
2101
- function ut() {
2102
- const s = this[y];
2103
- this.removeListener("close", ut), this.removeListener("data", fe), this.removeListener("end", dt), s._readyState = m.CLOSING;
2104
- let e;
2105
- !this._readableState.endEmitted && !s._closeFrameReceived && !s._receiver._writableState.errorEmitted && (e = s._socket.read()) !== null && s._receiver.write(e), s._receiver.end(), this[y] = void 0, clearTimeout(s._closeTimer), s._receiver._writableState.finished || s._receiver._writableState.errorEmitted ? s.emitClose() : (s._receiver.on("error", Ye), s._receiver.on("finish", Ye));
2106
- }
2107
- function fe(s) {
2108
- this[y]._receiver.write(s) || this.pause();
2109
- }
2110
- function dt() {
2111
- const s = this[y];
2112
- s._readyState = m.CLOSING, s._receiver.end(), this.end();
2113
- }
2114
- function _t() {
2115
- const s = this[y];
2116
- this.removeListener("error", _t), this.on("error", at), s && (s._readyState = m.CLOSING, this.destroy());
2117
- }
2118
- const Xs = /* @__PURE__ */ z(ft), { tokenChars: Ns } = ae;
2119
- function Ps(s) {
2120
- const e = /* @__PURE__ */ new Set();
2121
- let t = -1, r = -1, i = 0;
2122
- for (i; i < s.length; i++) {
2123
- const o = s.charCodeAt(i);
2124
- if (r === -1 && Ns[o] === 1)
2125
- t === -1 && (t = i);
2126
- else if (i !== 0 && (o === 32 || o === 9))
2127
- r === -1 && t !== -1 && (r = i);
2128
- else if (o === 44) {
2129
- if (t === -1)
2130
- throw new SyntaxError(`Unexpected character at index ${i}`);
2131
- r === -1 && (r = i);
2132
- const l = s.slice(t, r);
2133
- if (e.has(l))
2134
- throw new SyntaxError(`The "${l}" subprotocol is duplicated`);
2135
- e.add(l), t = r = -1;
2136
- } else
2137
- throw new SyntaxError(`Unexpected character at index ${i}`);
2138
- }
2139
- if (t === -1 || r !== -1)
2140
- throw new SyntaxError("Unexpected end of input");
2141
- const n = s.slice(t, i);
2142
- if (e.has(n))
2143
- throw new SyntaxError(`The "${n}" subprotocol is duplicated`);
2144
- return e.add(n), e;
2145
- }
2146
- var Rs = { parse: Ps };
2147
- const Us = S, ie = S, { createHash: Bs } = S, qe = nt, N = oe, $s = Rs, Ms = ft, { GUID: Is, kWebSocket: Ds } = U, Ws = /^[+/0-9A-Za-z]{22}==$/, Ke = 0, Xe = 1, pt = 2;
2148
- class As extends Us {
2149
- /**
2150
- * Create a `WebSocketServer` instance.
2151
- *
2152
- * @param {Object} options Configuration options
2153
- * @param {Number} [options.backlog=511] The maximum length of the queue of
2154
- * pending connections
2155
- * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
2156
- * track clients
2157
- * @param {Function} [options.handleProtocols] A hook to handle protocols
2158
- * @param {String} [options.host] The hostname where to bind the server
2159
- * @param {Number} [options.maxPayload=104857600] The maximum allowed message
2160
- * size
2161
- * @param {Boolean} [options.noServer=false] Enable no server mode
2162
- * @param {String} [options.path] Accept only connections matching this path
2163
- * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
2164
- * permessage-deflate
2165
- * @param {Number} [options.port] The port where to bind the server
2166
- * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
2167
- * server to use
2168
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2169
- * not to skip UTF-8 validation for text and close messages
2170
- * @param {Function} [options.verifyClient] A hook to reject connections
2171
- * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
2172
- * class to use. It must be the `WebSocket` class or class that extends it
2173
- * @param {Function} [callback] A listener for the `listening` event
2174
- */
2175
- constructor(e, t) {
2176
- if (super(), e = {
2177
- maxPayload: 100 * 1024 * 1024,
2178
- skipUTF8Validation: !1,
2179
- perMessageDeflate: !1,
2180
- handleProtocols: null,
2181
- clientTracking: !0,
2182
- verifyClient: null,
2183
- noServer: !1,
2184
- backlog: null,
2185
- // use default (511 as implemented in net.js)
2186
- server: null,
2187
- host: null,
2188
- path: null,
2189
- port: null,
2190
- WebSocket: Ms,
2191
- ...e
2192
- }, e.port == null && !e.server && !e.noServer || e.port != null && (e.server || e.noServer) || e.server && e.noServer)
2193
- throw new TypeError(
2194
- 'One and only one of the "port", "server", or "noServer" options must be specified'
2195
- );
2196
- if (e.port != null ? (this._server = ie.createServer((r, i) => {
2197
- const n = ie.STATUS_CODES[426];
2198
- i.writeHead(426, {
2199
- "Content-Length": n.length,
2200
- "Content-Type": "text/plain"
2201
- }), i.end(n);
2202
- }), this._server.listen(
2203
- e.port,
2204
- e.host,
2205
- e.backlog,
2206
- t
2207
- )) : e.server && (this._server = e.server), this._server) {
2208
- const r = this.emit.bind(this, "connection");
2209
- this._removeListeners = js(this._server, {
2210
- listening: this.emit.bind(this, "listening"),
2211
- error: this.emit.bind(this, "error"),
2212
- upgrade: (i, n, o) => {
2213
- this.handleUpgrade(i, n, o, r);
2214
- }
2215
- });
2216
- }
2217
- e.perMessageDeflate === !0 && (e.perMessageDeflate = {}), e.clientTracking && (this.clients = /* @__PURE__ */ new Set(), this._shouldEmitClose = !1), this.options = e, this._state = Ke;
2218
- }
2219
- /**
2220
- * Returns the bound address, the address family name, and port of the server
2221
- * as reported by the operating system if listening on an IP socket.
2222
- * If the server is listening on a pipe or UNIX domain socket, the name is
2223
- * returned as a string.
2224
- *
2225
- * @return {(Object|String|null)} The address of the server
2226
- * @public
2227
- */
2228
- address() {
2229
- if (this.options.noServer)
2230
- throw new Error('The server is operating in "noServer" mode');
2231
- return this._server ? this._server.address() : null;
2232
- }
2233
- /**
2234
- * Stop the server from accepting new connections and emit the `'close'` event
2235
- * when all existing connections are closed.
2236
- *
2237
- * @param {Function} [cb] A one-time listener for the `'close'` event
2238
- * @public
2239
- */
2240
- close(e) {
2241
- if (this._state === pt) {
2242
- e && this.once("close", () => {
2243
- e(new Error("The server is not running"));
2244
- }), process.nextTick(G, this);
2245
- return;
2246
- }
2247
- if (e && this.once("close", e), this._state !== Xe)
2248
- if (this._state = Xe, this.options.noServer || this.options.server)
2249
- this._server && (this._removeListeners(), this._removeListeners = this._server = null), this.clients ? this.clients.size ? this._shouldEmitClose = !0 : process.nextTick(G, this) : process.nextTick(G, this);
2250
- else {
2251
- const t = this._server;
2252
- this._removeListeners(), this._removeListeners = this._server = null, t.close(() => {
2253
- G(this);
2254
- });
2255
- }
2256
- }
2257
- /**
2258
- * See if a given request should be handled by this server instance.
2259
- *
2260
- * @param {http.IncomingMessage} req Request object to inspect
2261
- * @return {Boolean} `true` if the request is valid, else `false`
2262
- * @public
2263
- */
2264
- shouldHandle(e) {
2265
- if (this.options.path) {
2266
- const t = e.url.indexOf("?");
2267
- if ((t !== -1 ? e.url.slice(0, t) : e.url) !== this.options.path)
2268
- return !1;
2269
- }
2270
- return !0;
2271
- }
2272
- /**
2273
- * Handle a HTTP Upgrade request.
2274
- *
2275
- * @param {http.IncomingMessage} req The request object
2276
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
2277
- * server and client
2278
- * @param {Buffer} head The first packet of the upgraded stream
2279
- * @param {Function} cb Callback
2280
- * @public
2281
- */
2282
- handleUpgrade(e, t, r, i) {
2283
- t.on("error", Ze);
2284
- const n = e.headers["sec-websocket-key"], o = +e.headers["sec-websocket-version"];
2285
- if (e.method !== "GET") {
2286
- R(this, e, t, 405, "Invalid HTTP method");
2287
- return;
2288
- }
2289
- if (e.headers.upgrade.toLowerCase() !== "websocket") {
2290
- R(this, e, t, 400, "Invalid Upgrade header");
2291
- return;
2292
- }
2293
- if (!n || !Ws.test(n)) {
2294
- R(this, e, t, 400, "Missing or invalid Sec-WebSocket-Key header");
2295
- return;
2296
- }
2297
- if (o !== 8 && o !== 13) {
2298
- R(this, e, t, 400, "Missing or invalid Sec-WebSocket-Version header");
2299
- return;
2300
- }
2301
- if (!this.shouldHandle(e)) {
2302
- H(t, 400);
2303
- return;
2304
- }
2305
- const l = e.headers["sec-websocket-protocol"];
2306
- let f = /* @__PURE__ */ new Set();
2307
- if (l !== void 0)
2308
- try {
2309
- f = $s.parse(l);
2310
- } catch {
2311
- R(this, e, t, 400, "Invalid Sec-WebSocket-Protocol header");
2312
- return;
2313
- }
2314
- const a = e.headers["sec-websocket-extensions"], c = {};
2315
- if (this.options.perMessageDeflate && a !== void 0) {
2316
- const h = new N(
2317
- this.options.perMessageDeflate,
2318
- !0,
2319
- this.options.maxPayload
2320
- );
2321
- try {
2322
- const p = qe.parse(a);
2323
- p[N.extensionName] && (h.accept(p[N.extensionName]), c[N.extensionName] = h);
2324
- } catch {
2325
- R(this, e, t, 400, "Invalid or unacceptable Sec-WebSocket-Extensions header");
2326
- return;
2327
- }
2328
- }
2329
- if (this.options.verifyClient) {
2330
- const h = {
2331
- origin: e.headers[`${o === 8 ? "sec-websocket-origin" : "origin"}`],
2332
- secure: !!(e.socket.authorized || e.socket.encrypted),
2333
- req: e
2334
- };
2335
- if (this.options.verifyClient.length === 2) {
2336
- this.options.verifyClient(h, (p, v, _, u) => {
2337
- if (!p)
2338
- return H(t, v || 401, _, u);
2339
- this.completeUpgrade(
2340
- c,
2341
- n,
2342
- f,
2343
- e,
2344
- t,
2345
- r,
2346
- i
2347
- );
2348
- });
2349
- return;
2350
- }
2351
- if (!this.options.verifyClient(h))
2352
- return H(t, 401);
2353
- }
2354
- this.completeUpgrade(c, n, f, e, t, r, i);
2355
- }
2356
- /**
2357
- * Upgrade the connection to WebSocket.
2358
- *
2359
- * @param {Object} extensions The accepted extensions
2360
- * @param {String} key The value of the `Sec-WebSocket-Key` header
2361
- * @param {Set} protocols The subprotocols
2362
- * @param {http.IncomingMessage} req The request object
2363
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
2364
- * server and client
2365
- * @param {Buffer} head The first packet of the upgraded stream
2366
- * @param {Function} cb Callback
2367
- * @throws {Error} If called more than once with the same socket
2368
- * @private
2369
- */
2370
- completeUpgrade(e, t, r, i, n, o, l) {
2371
- if (!n.readable || !n.writable)
2372
- return n.destroy();
2373
- if (n[Ds])
2374
- throw new Error(
2375
- "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
2376
- );
2377
- if (this._state > Ke)
2378
- return H(n, 503);
2379
- const a = [
2380
- "HTTP/1.1 101 Switching Protocols",
2381
- "Upgrade: websocket",
2382
- "Connection: Upgrade",
2383
- `Sec-WebSocket-Accept: ${Bs("sha1").update(t + Is).digest("base64")}`
2384
- ], c = new this.options.WebSocket(null);
2385
- if (r.size) {
2386
- const h = this.options.handleProtocols ? this.options.handleProtocols(r, i) : r.values().next().value;
2387
- h && (a.push(`Sec-WebSocket-Protocol: ${h}`), c._protocol = h);
2388
- }
2389
- if (e[N.extensionName]) {
2390
- const h = e[N.extensionName].params, p = qe.format({
2391
- [N.extensionName]: [h]
2392
- });
2393
- a.push(`Sec-WebSocket-Extensions: ${p}`), c._extensions = e;
2394
- }
2395
- this.emit("headers", a, i), n.write(a.concat(`\r
2396
- `).join(`\r
2397
- `)), n.removeListener("error", Ze), c.setSocket(n, o, {
2398
- maxPayload: this.options.maxPayload,
2399
- skipUTF8Validation: this.options.skipUTF8Validation
2400
- }), this.clients && (this.clients.add(c), c.on("close", () => {
2401
- this.clients.delete(c), this._shouldEmitClose && !this.clients.size && process.nextTick(G, this);
2402
- })), l(c, i);
2403
- }
2404
- }
2405
- var Fs = As;
2406
- function js(s, e) {
2407
- for (const t of Object.keys(e))
2408
- s.on(t, e[t]);
2409
- return function() {
2410
- for (const r of Object.keys(e))
2411
- s.removeListener(r, e[r]);
2412
- };
2413
- }
2414
- function G(s) {
2415
- s._state = pt, s.emit("close");
2416
- }
2417
- function Ze() {
2418
- this.destroy();
2419
- }
2420
- function H(s, e, t, r) {
2421
- t = t || ie.STATUS_CODES[e], r = {
2422
- Connection: "close",
2423
- "Content-Type": "text/html",
2424
- "Content-Length": Buffer.byteLength(t),
2425
- ...r
2426
- }, s.once("finish", s.destroy), s.end(
2427
- `HTTP/1.1 ${e} ${ie.STATUS_CODES[e]}\r
2428
- ` + Object.keys(r).map((i) => `${i}: ${r[i]}`).join(`\r
2429
- `) + `\r
2430
- \r
2431
- ` + t
2432
- );
2433
- }
2434
- function R(s, e, t, r, i) {
2435
- if (s.listenerCount("wsClientError")) {
2436
- const n = new Error(i);
2437
- Error.captureStackTrace(n, R), s.emit("wsClientError", n, t, e);
2438
- } else
2439
- H(t, r, i);
2440
- }
2441
- const Zs = /* @__PURE__ */ z(Fs);
2442
- export {
2443
- qs as Receiver,
2444
- Ks as Sender,
2445
- Xs as WebSocket,
2446
- Zs as WebSocketServer,
2447
- Vs as createWebSocketStream,
2448
- Xs as default
2449
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/backend/gradio_pdf/templates/component/wrapper-98f94c21-523a3923.js DELETED
@@ -1,2449 +0,0 @@
1
- import { r as S } from "./Index-f4230f0b.js";
2
- function z(s) {
3
- return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
4
- }
5
- function gt(s) {
6
- if (s.__esModule)
7
- return s;
8
- var e = s.default;
9
- if (typeof e == "function") {
10
- var t = function r() {
11
- return this instanceof r ? Reflect.construct(e, arguments, this.constructor) : e.apply(this, arguments);
12
- };
13
- t.prototype = e.prototype;
14
- } else
15
- t = {};
16
- return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(s).forEach(function(r) {
17
- var i = Object.getOwnPropertyDescriptor(s, r);
18
- Object.defineProperty(t, r, i.get ? i : {
19
- enumerable: !0,
20
- get: function() {
21
- return s[r];
22
- }
23
- });
24
- }), t;
25
- }
26
- const { Duplex: yt } = S;
27
- function Oe(s) {
28
- s.emit("close");
29
- }
30
- function vt() {
31
- !this.destroyed && this._writableState.finished && this.destroy();
32
- }
33
- function Qe(s) {
34
- this.removeListener("error", Qe), this.destroy(), this.listenerCount("error") === 0 && this.emit("error", s);
35
- }
36
- function St(s, e) {
37
- let t = !0;
38
- const r = new yt({
39
- ...e,
40
- autoDestroy: !1,
41
- emitClose: !1,
42
- objectMode: !1,
43
- writableObjectMode: !1
44
- });
45
- return s.on("message", function(n, o) {
46
- const l = !o && r._readableState.objectMode ? n.toString() : n;
47
- r.push(l) || s.pause();
48
- }), s.once("error", function(n) {
49
- r.destroyed || (t = !1, r.destroy(n));
50
- }), s.once("close", function() {
51
- r.destroyed || r.push(null);
52
- }), r._destroy = function(i, n) {
53
- if (s.readyState === s.CLOSED) {
54
- n(i), process.nextTick(Oe, r);
55
- return;
56
- }
57
- let o = !1;
58
- s.once("error", function(f) {
59
- o = !0, n(f);
60
- }), s.once("close", function() {
61
- o || n(i), process.nextTick(Oe, r);
62
- }), t && s.terminate();
63
- }, r._final = function(i) {
64
- if (s.readyState === s.CONNECTING) {
65
- s.once("open", function() {
66
- r._final(i);
67
- });
68
- return;
69
- }
70
- s._socket !== null && (s._socket._writableState.finished ? (i(), r._readableState.endEmitted && r.destroy()) : (s._socket.once("finish", function() {
71
- i();
72
- }), s.close()));
73
- }, r._read = function() {
74
- s.isPaused && s.resume();
75
- }, r._write = function(i, n, o) {
76
- if (s.readyState === s.CONNECTING) {
77
- s.once("open", function() {
78
- r._write(i, n, o);
79
- });
80
- return;
81
- }
82
- s.send(i, o);
83
- }, r.on("end", vt), r.on("error", Qe), r;
84
- }
85
- var Et = St;
86
- const Vs = /* @__PURE__ */ z(Et);
87
- var te = { exports: {} }, U = {
88
- BINARY_TYPES: ["nodebuffer", "arraybuffer", "fragments"],
89
- EMPTY_BUFFER: Buffer.alloc(0),
90
- GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
91
- kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
92
- kListener: Symbol("kListener"),
93
- kStatusCode: Symbol("status-code"),
94
- kWebSocket: Symbol("websocket"),
95
- NOOP: () => {
96
- }
97
- }, bt, xt;
98
- const { EMPTY_BUFFER: kt } = U, Se = Buffer[Symbol.species];
99
- function wt(s, e) {
100
- if (s.length === 0)
101
- return kt;
102
- if (s.length === 1)
103
- return s[0];
104
- const t = Buffer.allocUnsafe(e);
105
- let r = 0;
106
- for (let i = 0; i < s.length; i++) {
107
- const n = s[i];
108
- t.set(n, r), r += n.length;
109
- }
110
- return r < e ? new Se(t.buffer, t.byteOffset, r) : t;
111
- }
112
- function Je(s, e, t, r, i) {
113
- for (let n = 0; n < i; n++)
114
- t[r + n] = s[n] ^ e[n & 3];
115
- }
116
- function et(s, e) {
117
- for (let t = 0; t < s.length; t++)
118
- s[t] ^= e[t & 3];
119
- }
120
- function Ot(s) {
121
- return s.length === s.buffer.byteLength ? s.buffer : s.buffer.slice(s.byteOffset, s.byteOffset + s.length);
122
- }
123
- function Ee(s) {
124
- if (Ee.readOnly = !0, Buffer.isBuffer(s))
125
- return s;
126
- let e;
127
- return s instanceof ArrayBuffer ? e = new Se(s) : ArrayBuffer.isView(s) ? e = new Se(s.buffer, s.byteOffset, s.byteLength) : (e = Buffer.from(s), Ee.readOnly = !1), e;
128
- }
129
- te.exports = {
130
- concat: wt,
131
- mask: Je,
132
- toArrayBuffer: Ot,
133
- toBuffer: Ee,
134
- unmask: et
135
- };
136
- if (!process.env.WS_NO_BUFFER_UTIL)
137
- try {
138
- const s = require("bufferutil");
139
- xt = te.exports.mask = function(e, t, r, i, n) {
140
- n < 48 ? Je(e, t, r, i, n) : s.mask(e, t, r, i, n);
141
- }, bt = te.exports.unmask = function(e, t) {
142
- e.length < 32 ? et(e, t) : s.unmask(e, t);
143
- };
144
- } catch {
145
- }
146
- var ne = te.exports;
147
- const Ce = Symbol("kDone"), ue = Symbol("kRun");
148
- let Ct = class {
149
- /**
150
- * Creates a new `Limiter`.
151
- *
152
- * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
153
- * to run concurrently
154
- */
155
- constructor(e) {
156
- this[Ce] = () => {
157
- this.pending--, this[ue]();
158
- }, this.concurrency = e || 1 / 0, this.jobs = [], this.pending = 0;
159
- }
160
- /**
161
- * Adds a job to the queue.
162
- *
163
- * @param {Function} job The job to run
164
- * @public
165
- */
166
- add(e) {
167
- this.jobs.push(e), this[ue]();
168
- }
169
- /**
170
- * Removes a job from the queue and runs it if possible.
171
- *
172
- * @private
173
- */
174
- [ue]() {
175
- if (this.pending !== this.concurrency && this.jobs.length) {
176
- const e = this.jobs.shift();
177
- this.pending++, e(this[Ce]);
178
- }
179
- }
180
- };
181
- var Tt = Ct;
182
- const W = S, Te = ne, Lt = Tt, { kStatusCode: tt } = U, Nt = Buffer[Symbol.species], Pt = Buffer.from([0, 0, 255, 255]), se = Symbol("permessage-deflate"), w = Symbol("total-length"), V = Symbol("callback"), C = Symbol("buffers"), J = Symbol("error");
183
- let K, Rt = class {
184
- /**
185
- * Creates a PerMessageDeflate instance.
186
- *
187
- * @param {Object} [options] Configuration options
188
- * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
189
- * for, or request, a custom client window size
190
- * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
191
- * acknowledge disabling of client context takeover
192
- * @param {Number} [options.concurrencyLimit=10] The number of concurrent
193
- * calls to zlib
194
- * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
195
- * use of a custom server window size
196
- * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
197
- * disabling of server context takeover
198
- * @param {Number} [options.threshold=1024] Size (in bytes) below which
199
- * messages should not be compressed if context takeover is disabled
200
- * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
201
- * deflate
202
- * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
203
- * inflate
204
- * @param {Boolean} [isServer=false] Create the instance in either server or
205
- * client mode
206
- * @param {Number} [maxPayload=0] The maximum allowed message length
207
- */
208
- constructor(e, t, r) {
209
- if (this._maxPayload = r | 0, this._options = e || {}, this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024, this._isServer = !!t, this._deflate = null, this._inflate = null, this.params = null, !K) {
210
- const i = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
211
- K = new Lt(i);
212
- }
213
- }
214
- /**
215
- * @type {String}
216
- */
217
- static get extensionName() {
218
- return "permessage-deflate";
219
- }
220
- /**
221
- * Create an extension negotiation offer.
222
- *
223
- * @return {Object} Extension parameters
224
- * @public
225
- */
226
- offer() {
227
- const e = {};
228
- return this._options.serverNoContextTakeover && (e.server_no_context_takeover = !0), this._options.clientNoContextTakeover && (e.client_no_context_takeover = !0), this._options.serverMaxWindowBits && (e.server_max_window_bits = this._options.serverMaxWindowBits), this._options.clientMaxWindowBits ? e.client_max_window_bits = this._options.clientMaxWindowBits : this._options.clientMaxWindowBits == null && (e.client_max_window_bits = !0), e;
229
- }
230
- /**
231
- * Accept an extension negotiation offer/response.
232
- *
233
- * @param {Array} configurations The extension negotiation offers/reponse
234
- * @return {Object} Accepted configuration
235
- * @public
236
- */
237
- accept(e) {
238
- return e = this.normalizeParams(e), this.params = this._isServer ? this.acceptAsServer(e) : this.acceptAsClient(e), this.params;
239
- }
240
- /**
241
- * Releases all resources used by the extension.
242
- *
243
- * @public
244
- */
245
- cleanup() {
246
- if (this._inflate && (this._inflate.close(), this._inflate = null), this._deflate) {
247
- const e = this._deflate[V];
248
- this._deflate.close(), this._deflate = null, e && e(
249
- new Error(
250
- "The deflate stream was closed while data was being processed"
251
- )
252
- );
253
- }
254
- }
255
- /**
256
- * Accept an extension negotiation offer.
257
- *
258
- * @param {Array} offers The extension negotiation offers
259
- * @return {Object} Accepted configuration
260
- * @private
261
- */
262
- acceptAsServer(e) {
263
- const t = this._options, r = e.find((i) => !(t.serverNoContextTakeover === !1 && i.server_no_context_takeover || i.server_max_window_bits && (t.serverMaxWindowBits === !1 || typeof t.serverMaxWindowBits == "number" && t.serverMaxWindowBits > i.server_max_window_bits) || typeof t.clientMaxWindowBits == "number" && !i.client_max_window_bits));
264
- if (!r)
265
- throw new Error("None of the extension offers can be accepted");
266
- return t.serverNoContextTakeover && (r.server_no_context_takeover = !0), t.clientNoContextTakeover && (r.client_no_context_takeover = !0), typeof t.serverMaxWindowBits == "number" && (r.server_max_window_bits = t.serverMaxWindowBits), typeof t.clientMaxWindowBits == "number" ? r.client_max_window_bits = t.clientMaxWindowBits : (r.client_max_window_bits === !0 || t.clientMaxWindowBits === !1) && delete r.client_max_window_bits, r;
267
- }
268
- /**
269
- * Accept the extension negotiation response.
270
- *
271
- * @param {Array} response The extension negotiation response
272
- * @return {Object} Accepted configuration
273
- * @private
274
- */
275
- acceptAsClient(e) {
276
- const t = e[0];
277
- if (this._options.clientNoContextTakeover === !1 && t.client_no_context_takeover)
278
- throw new Error('Unexpected parameter "client_no_context_takeover"');
279
- if (!t.client_max_window_bits)
280
- typeof this._options.clientMaxWindowBits == "number" && (t.client_max_window_bits = this._options.clientMaxWindowBits);
281
- else if (this._options.clientMaxWindowBits === !1 || typeof this._options.clientMaxWindowBits == "number" && t.client_max_window_bits > this._options.clientMaxWindowBits)
282
- throw new Error(
283
- 'Unexpected or invalid parameter "client_max_window_bits"'
284
- );
285
- return t;
286
- }
287
- /**
288
- * Normalize parameters.
289
- *
290
- * @param {Array} configurations The extension negotiation offers/reponse
291
- * @return {Array} The offers/response with normalized parameters
292
- * @private
293
- */
294
- normalizeParams(e) {
295
- return e.forEach((t) => {
296
- Object.keys(t).forEach((r) => {
297
- let i = t[r];
298
- if (i.length > 1)
299
- throw new Error(`Parameter "${r}" must have only a single value`);
300
- if (i = i[0], r === "client_max_window_bits") {
301
- if (i !== !0) {
302
- const n = +i;
303
- if (!Number.isInteger(n) || n < 8 || n > 15)
304
- throw new TypeError(
305
- `Invalid value for parameter "${r}": ${i}`
306
- );
307
- i = n;
308
- } else if (!this._isServer)
309
- throw new TypeError(
310
- `Invalid value for parameter "${r}": ${i}`
311
- );
312
- } else if (r === "server_max_window_bits") {
313
- const n = +i;
314
- if (!Number.isInteger(n) || n < 8 || n > 15)
315
- throw new TypeError(
316
- `Invalid value for parameter "${r}": ${i}`
317
- );
318
- i = n;
319
- } else if (r === "client_no_context_takeover" || r === "server_no_context_takeover") {
320
- if (i !== !0)
321
- throw new TypeError(
322
- `Invalid value for parameter "${r}": ${i}`
323
- );
324
- } else
325
- throw new Error(`Unknown parameter "${r}"`);
326
- t[r] = i;
327
- });
328
- }), e;
329
- }
330
- /**
331
- * Decompress data. Concurrency limited.
332
- *
333
- * @param {Buffer} data Compressed data
334
- * @param {Boolean} fin Specifies whether or not this is the last fragment
335
- * @param {Function} callback Callback
336
- * @public
337
- */
338
- decompress(e, t, r) {
339
- K.add((i) => {
340
- this._decompress(e, t, (n, o) => {
341
- i(), r(n, o);
342
- });
343
- });
344
- }
345
- /**
346
- * Compress data. Concurrency limited.
347
- *
348
- * @param {(Buffer|String)} data Data to compress
349
- * @param {Boolean} fin Specifies whether or not this is the last fragment
350
- * @param {Function} callback Callback
351
- * @public
352
- */
353
- compress(e, t, r) {
354
- K.add((i) => {
355
- this._compress(e, t, (n, o) => {
356
- i(), r(n, o);
357
- });
358
- });
359
- }
360
- /**
361
- * Decompress data.
362
- *
363
- * @param {Buffer} data Compressed data
364
- * @param {Boolean} fin Specifies whether or not this is the last fragment
365
- * @param {Function} callback Callback
366
- * @private
367
- */
368
- _decompress(e, t, r) {
369
- const i = this._isServer ? "client" : "server";
370
- if (!this._inflate) {
371
- const n = `${i}_max_window_bits`, o = typeof this.params[n] != "number" ? W.Z_DEFAULT_WINDOWBITS : this.params[n];
372
- this._inflate = W.createInflateRaw({
373
- ...this._options.zlibInflateOptions,
374
- windowBits: o
375
- }), this._inflate[se] = this, this._inflate[w] = 0, this._inflate[C] = [], this._inflate.on("error", Bt), this._inflate.on("data", st);
376
- }
377
- this._inflate[V] = r, this._inflate.write(e), t && this._inflate.write(Pt), this._inflate.flush(() => {
378
- const n = this._inflate[J];
379
- if (n) {
380
- this._inflate.close(), this._inflate = null, r(n);
381
- return;
382
- }
383
- const o = Te.concat(
384
- this._inflate[C],
385
- this._inflate[w]
386
- );
387
- this._inflate._readableState.endEmitted ? (this._inflate.close(), this._inflate = null) : (this._inflate[w] = 0, this._inflate[C] = [], t && this.params[`${i}_no_context_takeover`] && this._inflate.reset()), r(null, o);
388
- });
389
- }
390
- /**
391
- * Compress data.
392
- *
393
- * @param {(Buffer|String)} data Data to compress
394
- * @param {Boolean} fin Specifies whether or not this is the last fragment
395
- * @param {Function} callback Callback
396
- * @private
397
- */
398
- _compress(e, t, r) {
399
- const i = this._isServer ? "server" : "client";
400
- if (!this._deflate) {
401
- const n = `${i}_max_window_bits`, o = typeof this.params[n] != "number" ? W.Z_DEFAULT_WINDOWBITS : this.params[n];
402
- this._deflate = W.createDeflateRaw({
403
- ...this._options.zlibDeflateOptions,
404
- windowBits: o
405
- }), this._deflate[w] = 0, this._deflate[C] = [], this._deflate.on("data", Ut);
406
- }
407
- this._deflate[V] = r, this._deflate.write(e), this._deflate.flush(W.Z_SYNC_FLUSH, () => {
408
- if (!this._deflate)
409
- return;
410
- let n = Te.concat(
411
- this._deflate[C],
412
- this._deflate[w]
413
- );
414
- t && (n = new Nt(n.buffer, n.byteOffset, n.length - 4)), this._deflate[V] = null, this._deflate[w] = 0, this._deflate[C] = [], t && this.params[`${i}_no_context_takeover`] && this._deflate.reset(), r(null, n);
415
- });
416
- }
417
- };
418
- var oe = Rt;
419
- function Ut(s) {
420
- this[C].push(s), this[w] += s.length;
421
- }
422
- function st(s) {
423
- if (this[w] += s.length, this[se]._maxPayload < 1 || this[w] <= this[se]._maxPayload) {
424
- this[C].push(s);
425
- return;
426
- }
427
- this[J] = new RangeError("Max payload size exceeded"), this[J].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH", this[J][tt] = 1009, this.removeListener("data", st), this.reset();
428
- }
429
- function Bt(s) {
430
- this[se]._inflate = null, s[tt] = 1007, this[V](s);
431
- }
432
- var re = { exports: {} };
433
- const $t = {}, Mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
434
- __proto__: null,
435
- default: $t
436
- }, Symbol.toStringTag, { value: "Module" })), It = /* @__PURE__ */ gt(Mt);
437
- var Le;
438
- const { isUtf8: Ne } = S, Dt = [
439
- 0,
440
- 0,
441
- 0,
442
- 0,
443
- 0,
444
- 0,
445
- 0,
446
- 0,
447
- 0,
448
- 0,
449
- 0,
450
- 0,
451
- 0,
452
- 0,
453
- 0,
454
- 0,
455
- // 0 - 15
456
- 0,
457
- 0,
458
- 0,
459
- 0,
460
- 0,
461
- 0,
462
- 0,
463
- 0,
464
- 0,
465
- 0,
466
- 0,
467
- 0,
468
- 0,
469
- 0,
470
- 0,
471
- 0,
472
- // 16 - 31
473
- 0,
474
- 1,
475
- 0,
476
- 1,
477
- 1,
478
- 1,
479
- 1,
480
- 1,
481
- 0,
482
- 0,
483
- 1,
484
- 1,
485
- 0,
486
- 1,
487
- 1,
488
- 0,
489
- // 32 - 47
490
- 1,
491
- 1,
492
- 1,
493
- 1,
494
- 1,
495
- 1,
496
- 1,
497
- 1,
498
- 1,
499
- 1,
500
- 0,
501
- 0,
502
- 0,
503
- 0,
504
- 0,
505
- 0,
506
- // 48 - 63
507
- 0,
508
- 1,
509
- 1,
510
- 1,
511
- 1,
512
- 1,
513
- 1,
514
- 1,
515
- 1,
516
- 1,
517
- 1,
518
- 1,
519
- 1,
520
- 1,
521
- 1,
522
- 1,
523
- // 64 - 79
524
- 1,
525
- 1,
526
- 1,
527
- 1,
528
- 1,
529
- 1,
530
- 1,
531
- 1,
532
- 1,
533
- 1,
534
- 1,
535
- 0,
536
- 0,
537
- 0,
538
- 1,
539
- 1,
540
- // 80 - 95
541
- 1,
542
- 1,
543
- 1,
544
- 1,
545
- 1,
546
- 1,
547
- 1,
548
- 1,
549
- 1,
550
- 1,
551
- 1,
552
- 1,
553
- 1,
554
- 1,
555
- 1,
556
- 1,
557
- // 96 - 111
558
- 1,
559
- 1,
560
- 1,
561
- 1,
562
- 1,
563
- 1,
564
- 1,
565
- 1,
566
- 1,
567
- 1,
568
- 1,
569
- 0,
570
- 1,
571
- 0,
572
- 1,
573
- 0
574
- // 112 - 127
575
- ];
576
- function Wt(s) {
577
- return s >= 1e3 && s <= 1014 && s !== 1004 && s !== 1005 && s !== 1006 || s >= 3e3 && s <= 4999;
578
- }
579
- function be(s) {
580
- const e = s.length;
581
- let t = 0;
582
- for (; t < e; )
583
- if (!(s[t] & 128))
584
- t++;
585
- else if ((s[t] & 224) === 192) {
586
- if (t + 1 === e || (s[t + 1] & 192) !== 128 || (s[t] & 254) === 192)
587
- return !1;
588
- t += 2;
589
- } else if ((s[t] & 240) === 224) {
590
- if (t + 2 >= e || (s[t + 1] & 192) !== 128 || (s[t + 2] & 192) !== 128 || s[t] === 224 && (s[t + 1] & 224) === 128 || // Overlong
591
- s[t] === 237 && (s[t + 1] & 224) === 160)
592
- return !1;
593
- t += 3;
594
- } else if ((s[t] & 248) === 240) {
595
- if (t + 3 >= e || (s[t + 1] & 192) !== 128 || (s[t + 2] & 192) !== 128 || (s[t + 3] & 192) !== 128 || s[t] === 240 && (s[t + 1] & 240) === 128 || // Overlong
596
- s[t] === 244 && s[t + 1] > 143 || s[t] > 244)
597
- return !1;
598
- t += 4;
599
- } else
600
- return !1;
601
- return !0;
602
- }
603
- re.exports = {
604
- isValidStatusCode: Wt,
605
- isValidUTF8: be,
606
- tokenChars: Dt
607
- };
608
- if (Ne)
609
- Le = re.exports.isValidUTF8 = function(s) {
610
- return s.length < 24 ? be(s) : Ne(s);
611
- };
612
- else if (!process.env.WS_NO_UTF_8_VALIDATE)
613
- try {
614
- const s = It;
615
- Le = re.exports.isValidUTF8 = function(e) {
616
- return e.length < 32 ? be(e) : s(e);
617
- };
618
- } catch {
619
- }
620
- var ae = re.exports;
621
- const { Writable: At } = S, Pe = oe, {
622
- BINARY_TYPES: Ft,
623
- EMPTY_BUFFER: Re,
624
- kStatusCode: jt,
625
- kWebSocket: Gt
626
- } = U, { concat: de, toArrayBuffer: Vt, unmask: Ht } = ne, { isValidStatusCode: zt, isValidUTF8: Ue } = ae, X = Buffer[Symbol.species], A = 0, Be = 1, $e = 2, Me = 3, _e = 4, Yt = 5;
627
- let qt = class extends At {
628
- /**
629
- * Creates a Receiver instance.
630
- *
631
- * @param {Object} [options] Options object
632
- * @param {String} [options.binaryType=nodebuffer] The type for binary data
633
- * @param {Object} [options.extensions] An object containing the negotiated
634
- * extensions
635
- * @param {Boolean} [options.isServer=false] Specifies whether to operate in
636
- * client or server mode
637
- * @param {Number} [options.maxPayload=0] The maximum allowed message length
638
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
639
- * not to skip UTF-8 validation for text and close messages
640
- */
641
- constructor(e = {}) {
642
- super(), this._binaryType = e.binaryType || Ft[0], this._extensions = e.extensions || {}, this._isServer = !!e.isServer, this._maxPayload = e.maxPayload | 0, this._skipUTF8Validation = !!e.skipUTF8Validation, this[Gt] = void 0, this._bufferedBytes = 0, this._buffers = [], this._compressed = !1, this._payloadLength = 0, this._mask = void 0, this._fragmented = 0, this._masked = !1, this._fin = !1, this._opcode = 0, this._totalPayloadLength = 0, this._messageLength = 0, this._fragments = [], this._state = A, this._loop = !1;
643
- }
644
- /**
645
- * Implements `Writable.prototype._write()`.
646
- *
647
- * @param {Buffer} chunk The chunk of data to write
648
- * @param {String} encoding The character encoding of `chunk`
649
- * @param {Function} cb Callback
650
- * @private
651
- */
652
- _write(e, t, r) {
653
- if (this._opcode === 8 && this._state == A)
654
- return r();
655
- this._bufferedBytes += e.length, this._buffers.push(e), this.startLoop(r);
656
- }
657
- /**
658
- * Consumes `n` bytes from the buffered data.
659
- *
660
- * @param {Number} n The number of bytes to consume
661
- * @return {Buffer} The consumed bytes
662
- * @private
663
- */
664
- consume(e) {
665
- if (this._bufferedBytes -= e, e === this._buffers[0].length)
666
- return this._buffers.shift();
667
- if (e < this._buffers[0].length) {
668
- const r = this._buffers[0];
669
- return this._buffers[0] = new X(
670
- r.buffer,
671
- r.byteOffset + e,
672
- r.length - e
673
- ), new X(r.buffer, r.byteOffset, e);
674
- }
675
- const t = Buffer.allocUnsafe(e);
676
- do {
677
- const r = this._buffers[0], i = t.length - e;
678
- e >= r.length ? t.set(this._buffers.shift(), i) : (t.set(new Uint8Array(r.buffer, r.byteOffset, e), i), this._buffers[0] = new X(
679
- r.buffer,
680
- r.byteOffset + e,
681
- r.length - e
682
- )), e -= r.length;
683
- } while (e > 0);
684
- return t;
685
- }
686
- /**
687
- * Starts the parsing loop.
688
- *
689
- * @param {Function} cb Callback
690
- * @private
691
- */
692
- startLoop(e) {
693
- let t;
694
- this._loop = !0;
695
- do
696
- switch (this._state) {
697
- case A:
698
- t = this.getInfo();
699
- break;
700
- case Be:
701
- t = this.getPayloadLength16();
702
- break;
703
- case $e:
704
- t = this.getPayloadLength64();
705
- break;
706
- case Me:
707
- this.getMask();
708
- break;
709
- case _e:
710
- t = this.getData(e);
711
- break;
712
- default:
713
- this._loop = !1;
714
- return;
715
- }
716
- while (this._loop);
717
- e(t);
718
- }
719
- /**
720
- * Reads the first two bytes of a frame.
721
- *
722
- * @return {(RangeError|undefined)} A possible error
723
- * @private
724
- */
725
- getInfo() {
726
- if (this._bufferedBytes < 2) {
727
- this._loop = !1;
728
- return;
729
- }
730
- const e = this.consume(2);
731
- if (e[0] & 48)
732
- return this._loop = !1, g(
733
- RangeError,
734
- "RSV2 and RSV3 must be clear",
735
- !0,
736
- 1002,
737
- "WS_ERR_UNEXPECTED_RSV_2_3"
738
- );
739
- const t = (e[0] & 64) === 64;
740
- if (t && !this._extensions[Pe.extensionName])
741
- return this._loop = !1, g(
742
- RangeError,
743
- "RSV1 must be clear",
744
- !0,
745
- 1002,
746
- "WS_ERR_UNEXPECTED_RSV_1"
747
- );
748
- if (this._fin = (e[0] & 128) === 128, this._opcode = e[0] & 15, this._payloadLength = e[1] & 127, this._opcode === 0) {
749
- if (t)
750
- return this._loop = !1, g(
751
- RangeError,
752
- "RSV1 must be clear",
753
- !0,
754
- 1002,
755
- "WS_ERR_UNEXPECTED_RSV_1"
756
- );
757
- if (!this._fragmented)
758
- return this._loop = !1, g(
759
- RangeError,
760
- "invalid opcode 0",
761
- !0,
762
- 1002,
763
- "WS_ERR_INVALID_OPCODE"
764
- );
765
- this._opcode = this._fragmented;
766
- } else if (this._opcode === 1 || this._opcode === 2) {
767
- if (this._fragmented)
768
- return this._loop = !1, g(
769
- RangeError,
770
- `invalid opcode ${this._opcode}`,
771
- !0,
772
- 1002,
773
- "WS_ERR_INVALID_OPCODE"
774
- );
775
- this._compressed = t;
776
- } else if (this._opcode > 7 && this._opcode < 11) {
777
- if (!this._fin)
778
- return this._loop = !1, g(
779
- RangeError,
780
- "FIN must be set",
781
- !0,
782
- 1002,
783
- "WS_ERR_EXPECTED_FIN"
784
- );
785
- if (t)
786
- return this._loop = !1, g(
787
- RangeError,
788
- "RSV1 must be clear",
789
- !0,
790
- 1002,
791
- "WS_ERR_UNEXPECTED_RSV_1"
792
- );
793
- if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1)
794
- return this._loop = !1, g(
795
- RangeError,
796
- `invalid payload length ${this._payloadLength}`,
797
- !0,
798
- 1002,
799
- "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
800
- );
801
- } else
802
- return this._loop = !1, g(
803
- RangeError,
804
- `invalid opcode ${this._opcode}`,
805
- !0,
806
- 1002,
807
- "WS_ERR_INVALID_OPCODE"
808
- );
809
- if (!this._fin && !this._fragmented && (this._fragmented = this._opcode), this._masked = (e[1] & 128) === 128, this._isServer) {
810
- if (!this._masked)
811
- return this._loop = !1, g(
812
- RangeError,
813
- "MASK must be set",
814
- !0,
815
- 1002,
816
- "WS_ERR_EXPECTED_MASK"
817
- );
818
- } else if (this._masked)
819
- return this._loop = !1, g(
820
- RangeError,
821
- "MASK must be clear",
822
- !0,
823
- 1002,
824
- "WS_ERR_UNEXPECTED_MASK"
825
- );
826
- if (this._payloadLength === 126)
827
- this._state = Be;
828
- else if (this._payloadLength === 127)
829
- this._state = $e;
830
- else
831
- return this.haveLength();
832
- }
833
- /**
834
- * Gets extended payload length (7+16).
835
- *
836
- * @return {(RangeError|undefined)} A possible error
837
- * @private
838
- */
839
- getPayloadLength16() {
840
- if (this._bufferedBytes < 2) {
841
- this._loop = !1;
842
- return;
843
- }
844
- return this._payloadLength = this.consume(2).readUInt16BE(0), this.haveLength();
845
- }
846
- /**
847
- * Gets extended payload length (7+64).
848
- *
849
- * @return {(RangeError|undefined)} A possible error
850
- * @private
851
- */
852
- getPayloadLength64() {
853
- if (this._bufferedBytes < 8) {
854
- this._loop = !1;
855
- return;
856
- }
857
- const e = this.consume(8), t = e.readUInt32BE(0);
858
- return t > Math.pow(2, 53 - 32) - 1 ? (this._loop = !1, g(
859
- RangeError,
860
- "Unsupported WebSocket frame: payload length > 2^53 - 1",
861
- !1,
862
- 1009,
863
- "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
864
- )) : (this._payloadLength = t * Math.pow(2, 32) + e.readUInt32BE(4), this.haveLength());
865
- }
866
- /**
867
- * Payload length has been read.
868
- *
869
- * @return {(RangeError|undefined)} A possible error
870
- * @private
871
- */
872
- haveLength() {
873
- if (this._payloadLength && this._opcode < 8 && (this._totalPayloadLength += this._payloadLength, this._totalPayloadLength > this._maxPayload && this._maxPayload > 0))
874
- return this._loop = !1, g(
875
- RangeError,
876
- "Max payload size exceeded",
877
- !1,
878
- 1009,
879
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
880
- );
881
- this._masked ? this._state = Me : this._state = _e;
882
- }
883
- /**
884
- * Reads mask bytes.
885
- *
886
- * @private
887
- */
888
- getMask() {
889
- if (this._bufferedBytes < 4) {
890
- this._loop = !1;
891
- return;
892
- }
893
- this._mask = this.consume(4), this._state = _e;
894
- }
895
- /**
896
- * Reads data bytes.
897
- *
898
- * @param {Function} cb Callback
899
- * @return {(Error|RangeError|undefined)} A possible error
900
- * @private
901
- */
902
- getData(e) {
903
- let t = Re;
904
- if (this._payloadLength) {
905
- if (this._bufferedBytes < this._payloadLength) {
906
- this._loop = !1;
907
- return;
908
- }
909
- t = this.consume(this._payloadLength), this._masked && this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3] && Ht(t, this._mask);
910
- }
911
- if (this._opcode > 7)
912
- return this.controlMessage(t);
913
- if (this._compressed) {
914
- this._state = Yt, this.decompress(t, e);
915
- return;
916
- }
917
- return t.length && (this._messageLength = this._totalPayloadLength, this._fragments.push(t)), this.dataMessage();
918
- }
919
- /**
920
- * Decompresses data.
921
- *
922
- * @param {Buffer} data Compressed data
923
- * @param {Function} cb Callback
924
- * @private
925
- */
926
- decompress(e, t) {
927
- this._extensions[Pe.extensionName].decompress(e, this._fin, (i, n) => {
928
- if (i)
929
- return t(i);
930
- if (n.length) {
931
- if (this._messageLength += n.length, this._messageLength > this._maxPayload && this._maxPayload > 0)
932
- return t(
933
- g(
934
- RangeError,
935
- "Max payload size exceeded",
936
- !1,
937
- 1009,
938
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
939
- )
940
- );
941
- this._fragments.push(n);
942
- }
943
- const o = this.dataMessage();
944
- if (o)
945
- return t(o);
946
- this.startLoop(t);
947
- });
948
- }
949
- /**
950
- * Handles a data message.
951
- *
952
- * @return {(Error|undefined)} A possible error
953
- * @private
954
- */
955
- dataMessage() {
956
- if (this._fin) {
957
- const e = this._messageLength, t = this._fragments;
958
- if (this._totalPayloadLength = 0, this._messageLength = 0, this._fragmented = 0, this._fragments = [], this._opcode === 2) {
959
- let r;
960
- this._binaryType === "nodebuffer" ? r = de(t, e) : this._binaryType === "arraybuffer" ? r = Vt(de(t, e)) : r = t, this.emit("message", r, !0);
961
- } else {
962
- const r = de(t, e);
963
- if (!this._skipUTF8Validation && !Ue(r))
964
- return this._loop = !1, g(
965
- Error,
966
- "invalid UTF-8 sequence",
967
- !0,
968
- 1007,
969
- "WS_ERR_INVALID_UTF8"
970
- );
971
- this.emit("message", r, !1);
972
- }
973
- }
974
- this._state = A;
975
- }
976
- /**
977
- * Handles a control message.
978
- *
979
- * @param {Buffer} data Data to handle
980
- * @return {(Error|RangeError|undefined)} A possible error
981
- * @private
982
- */
983
- controlMessage(e) {
984
- if (this._opcode === 8)
985
- if (this._loop = !1, e.length === 0)
986
- this.emit("conclude", 1005, Re), this.end();
987
- else {
988
- const t = e.readUInt16BE(0);
989
- if (!zt(t))
990
- return g(
991
- RangeError,
992
- `invalid status code ${t}`,
993
- !0,
994
- 1002,
995
- "WS_ERR_INVALID_CLOSE_CODE"
996
- );
997
- const r = new X(
998
- e.buffer,
999
- e.byteOffset + 2,
1000
- e.length - 2
1001
- );
1002
- if (!this._skipUTF8Validation && !Ue(r))
1003
- return g(
1004
- Error,
1005
- "invalid UTF-8 sequence",
1006
- !0,
1007
- 1007,
1008
- "WS_ERR_INVALID_UTF8"
1009
- );
1010
- this.emit("conclude", t, r), this.end();
1011
- }
1012
- else
1013
- this._opcode === 9 ? this.emit("ping", e) : this.emit("pong", e);
1014
- this._state = A;
1015
- }
1016
- };
1017
- var rt = qt;
1018
- function g(s, e, t, r, i) {
1019
- const n = new s(
1020
- t ? `Invalid WebSocket frame: ${e}` : e
1021
- );
1022
- return Error.captureStackTrace(n, g), n.code = i, n[jt] = r, n;
1023
- }
1024
- const qs = /* @__PURE__ */ z(rt), { randomFillSync: Kt } = S, Ie = oe, { EMPTY_BUFFER: Xt } = U, { isValidStatusCode: Zt } = ae, { mask: De, toBuffer: M } = ne, x = Symbol("kByteLength"), Qt = Buffer.alloc(4);
1025
- let Jt = class P {
1026
- /**
1027
- * Creates a Sender instance.
1028
- *
1029
- * @param {(net.Socket|tls.Socket)} socket The connection socket
1030
- * @param {Object} [extensions] An object containing the negotiated extensions
1031
- * @param {Function} [generateMask] The function used to generate the masking
1032
- * key
1033
- */
1034
- constructor(e, t, r) {
1035
- this._extensions = t || {}, r && (this._generateMask = r, this._maskBuffer = Buffer.alloc(4)), this._socket = e, this._firstFragment = !0, this._compress = !1, this._bufferedBytes = 0, this._deflating = !1, this._queue = [];
1036
- }
1037
- /**
1038
- * Frames a piece of data according to the HyBi WebSocket protocol.
1039
- *
1040
- * @param {(Buffer|String)} data The data to frame
1041
- * @param {Object} options Options object
1042
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1043
- * FIN bit
1044
- * @param {Function} [options.generateMask] The function used to generate the
1045
- * masking key
1046
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1047
- * `data`
1048
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1049
- * key
1050
- * @param {Number} options.opcode The opcode
1051
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1052
- * modified
1053
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1054
- * RSV1 bit
1055
- * @return {(Buffer|String)[]} The framed data
1056
- * @public
1057
- */
1058
- static frame(e, t) {
1059
- let r, i = !1, n = 2, o = !1;
1060
- t.mask && (r = t.maskBuffer || Qt, t.generateMask ? t.generateMask(r) : Kt(r, 0, 4), o = (r[0] | r[1] | r[2] | r[3]) === 0, n = 6);
1061
- let l;
1062
- typeof e == "string" ? (!t.mask || o) && t[x] !== void 0 ? l = t[x] : (e = Buffer.from(e), l = e.length) : (l = e.length, i = t.mask && t.readOnly && !o);
1063
- let f = l;
1064
- l >= 65536 ? (n += 8, f = 127) : l > 125 && (n += 2, f = 126);
1065
- const a = Buffer.allocUnsafe(i ? l + n : n);
1066
- return a[0] = t.fin ? t.opcode | 128 : t.opcode, t.rsv1 && (a[0] |= 64), a[1] = f, f === 126 ? a.writeUInt16BE(l, 2) : f === 127 && (a[2] = a[3] = 0, a.writeUIntBE(l, 4, 6)), t.mask ? (a[1] |= 128, a[n - 4] = r[0], a[n - 3] = r[1], a[n - 2] = r[2], a[n - 1] = r[3], o ? [a, e] : i ? (De(e, r, a, n, l), [a]) : (De(e, r, e, 0, l), [a, e])) : [a, e];
1067
- }
1068
- /**
1069
- * Sends a close message to the other peer.
1070
- *
1071
- * @param {Number} [code] The status code component of the body
1072
- * @param {(String|Buffer)} [data] The message component of the body
1073
- * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1074
- * @param {Function} [cb] Callback
1075
- * @public
1076
- */
1077
- close(e, t, r, i) {
1078
- let n;
1079
- if (e === void 0)
1080
- n = Xt;
1081
- else {
1082
- if (typeof e != "number" || !Zt(e))
1083
- throw new TypeError("First argument must be a valid error code number");
1084
- if (t === void 0 || !t.length)
1085
- n = Buffer.allocUnsafe(2), n.writeUInt16BE(e, 0);
1086
- else {
1087
- const l = Buffer.byteLength(t);
1088
- if (l > 123)
1089
- throw new RangeError("The message must not be greater than 123 bytes");
1090
- n = Buffer.allocUnsafe(2 + l), n.writeUInt16BE(e, 0), typeof t == "string" ? n.write(t, 2) : n.set(t, 2);
1091
- }
1092
- }
1093
- const o = {
1094
- [x]: n.length,
1095
- fin: !0,
1096
- generateMask: this._generateMask,
1097
- mask: r,
1098
- maskBuffer: this._maskBuffer,
1099
- opcode: 8,
1100
- readOnly: !1,
1101
- rsv1: !1
1102
- };
1103
- this._deflating ? this.enqueue([this.dispatch, n, !1, o, i]) : this.sendFrame(P.frame(n, o), i);
1104
- }
1105
- /**
1106
- * Sends a ping message to the other peer.
1107
- *
1108
- * @param {*} data The message to send
1109
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1110
- * @param {Function} [cb] Callback
1111
- * @public
1112
- */
1113
- ping(e, t, r) {
1114
- let i, n;
1115
- if (typeof e == "string" ? (i = Buffer.byteLength(e), n = !1) : (e = M(e), i = e.length, n = M.readOnly), i > 125)
1116
- throw new RangeError("The data size must not be greater than 125 bytes");
1117
- const o = {
1118
- [x]: i,
1119
- fin: !0,
1120
- generateMask: this._generateMask,
1121
- mask: t,
1122
- maskBuffer: this._maskBuffer,
1123
- opcode: 9,
1124
- readOnly: n,
1125
- rsv1: !1
1126
- };
1127
- this._deflating ? this.enqueue([this.dispatch, e, !1, o, r]) : this.sendFrame(P.frame(e, o), r);
1128
- }
1129
- /**
1130
- * Sends a pong message to the other peer.
1131
- *
1132
- * @param {*} data The message to send
1133
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1134
- * @param {Function} [cb] Callback
1135
- * @public
1136
- */
1137
- pong(e, t, r) {
1138
- let i, n;
1139
- if (typeof e == "string" ? (i = Buffer.byteLength(e), n = !1) : (e = M(e), i = e.length, n = M.readOnly), i > 125)
1140
- throw new RangeError("The data size must not be greater than 125 bytes");
1141
- const o = {
1142
- [x]: i,
1143
- fin: !0,
1144
- generateMask: this._generateMask,
1145
- mask: t,
1146
- maskBuffer: this._maskBuffer,
1147
- opcode: 10,
1148
- readOnly: n,
1149
- rsv1: !1
1150
- };
1151
- this._deflating ? this.enqueue([this.dispatch, e, !1, o, r]) : this.sendFrame(P.frame(e, o), r);
1152
- }
1153
- /**
1154
- * Sends a data message to the other peer.
1155
- *
1156
- * @param {*} data The message to send
1157
- * @param {Object} options Options object
1158
- * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1159
- * or text
1160
- * @param {Boolean} [options.compress=false] Specifies whether or not to
1161
- * compress `data`
1162
- * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1163
- * last one
1164
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1165
- * `data`
1166
- * @param {Function} [cb] Callback
1167
- * @public
1168
- */
1169
- send(e, t, r) {
1170
- const i = this._extensions[Ie.extensionName];
1171
- let n = t.binary ? 2 : 1, o = t.compress, l, f;
1172
- if (typeof e == "string" ? (l = Buffer.byteLength(e), f = !1) : (e = M(e), l = e.length, f = M.readOnly), this._firstFragment ? (this._firstFragment = !1, o && i && i.params[i._isServer ? "server_no_context_takeover" : "client_no_context_takeover"] && (o = l >= i._threshold), this._compress = o) : (o = !1, n = 0), t.fin && (this._firstFragment = !0), i) {
1173
- const a = {
1174
- [x]: l,
1175
- fin: t.fin,
1176
- generateMask: this._generateMask,
1177
- mask: t.mask,
1178
- maskBuffer: this._maskBuffer,
1179
- opcode: n,
1180
- readOnly: f,
1181
- rsv1: o
1182
- };
1183
- this._deflating ? this.enqueue([this.dispatch, e, this._compress, a, r]) : this.dispatch(e, this._compress, a, r);
1184
- } else
1185
- this.sendFrame(
1186
- P.frame(e, {
1187
- [x]: l,
1188
- fin: t.fin,
1189
- generateMask: this._generateMask,
1190
- mask: t.mask,
1191
- maskBuffer: this._maskBuffer,
1192
- opcode: n,
1193
- readOnly: f,
1194
- rsv1: !1
1195
- }),
1196
- r
1197
- );
1198
- }
1199
- /**
1200
- * Dispatches a message.
1201
- *
1202
- * @param {(Buffer|String)} data The message to send
1203
- * @param {Boolean} [compress=false] Specifies whether or not to compress
1204
- * `data`
1205
- * @param {Object} options Options object
1206
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1207
- * FIN bit
1208
- * @param {Function} [options.generateMask] The function used to generate the
1209
- * masking key
1210
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1211
- * `data`
1212
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1213
- * key
1214
- * @param {Number} options.opcode The opcode
1215
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1216
- * modified
1217
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1218
- * RSV1 bit
1219
- * @param {Function} [cb] Callback
1220
- * @private
1221
- */
1222
- dispatch(e, t, r, i) {
1223
- if (!t) {
1224
- this.sendFrame(P.frame(e, r), i);
1225
- return;
1226
- }
1227
- const n = this._extensions[Ie.extensionName];
1228
- this._bufferedBytes += r[x], this._deflating = !0, n.compress(e, r.fin, (o, l) => {
1229
- if (this._socket.destroyed) {
1230
- const f = new Error(
1231
- "The socket was closed while data was being compressed"
1232
- );
1233
- typeof i == "function" && i(f);
1234
- for (let a = 0; a < this._queue.length; a++) {
1235
- const c = this._queue[a], h = c[c.length - 1];
1236
- typeof h == "function" && h(f);
1237
- }
1238
- return;
1239
- }
1240
- this._bufferedBytes -= r[x], this._deflating = !1, r.readOnly = !1, this.sendFrame(P.frame(l, r), i), this.dequeue();
1241
- });
1242
- }
1243
- /**
1244
- * Executes queued send operations.
1245
- *
1246
- * @private
1247
- */
1248
- dequeue() {
1249
- for (; !this._deflating && this._queue.length; ) {
1250
- const e = this._queue.shift();
1251
- this._bufferedBytes -= e[3][x], Reflect.apply(e[0], this, e.slice(1));
1252
- }
1253
- }
1254
- /**
1255
- * Enqueues a send operation.
1256
- *
1257
- * @param {Array} params Send operation parameters.
1258
- * @private
1259
- */
1260
- enqueue(e) {
1261
- this._bufferedBytes += e[3][x], this._queue.push(e);
1262
- }
1263
- /**
1264
- * Sends a frame.
1265
- *
1266
- * @param {Buffer[]} list The frame to send
1267
- * @param {Function} [cb] Callback
1268
- * @private
1269
- */
1270
- sendFrame(e, t) {
1271
- e.length === 2 ? (this._socket.cork(), this._socket.write(e[0]), this._socket.write(e[1], t), this._socket.uncork()) : this._socket.write(e[0], t);
1272
- }
1273
- };
1274
- var it = Jt;
1275
- const Ks = /* @__PURE__ */ z(it), { kForOnEventAttribute: F, kListener: pe } = U, We = Symbol("kCode"), Ae = Symbol("kData"), Fe = Symbol("kError"), je = Symbol("kMessage"), Ge = Symbol("kReason"), I = Symbol("kTarget"), Ve = Symbol("kType"), He = Symbol("kWasClean");
1276
- class B {
1277
- /**
1278
- * Create a new `Event`.
1279
- *
1280
- * @param {String} type The name of the event
1281
- * @throws {TypeError} If the `type` argument is not specified
1282
- */
1283
- constructor(e) {
1284
- this[I] = null, this[Ve] = e;
1285
- }
1286
- /**
1287
- * @type {*}
1288
- */
1289
- get target() {
1290
- return this[I];
1291
- }
1292
- /**
1293
- * @type {String}
1294
- */
1295
- get type() {
1296
- return this[Ve];
1297
- }
1298
- }
1299
- Object.defineProperty(B.prototype, "target", { enumerable: !0 });
1300
- Object.defineProperty(B.prototype, "type", { enumerable: !0 });
1301
- class Y extends B {
1302
- /**
1303
- * Create a new `CloseEvent`.
1304
- *
1305
- * @param {String} type The name of the event
1306
- * @param {Object} [options] A dictionary object that allows for setting
1307
- * attributes via object members of the same name
1308
- * @param {Number} [options.code=0] The status code explaining why the
1309
- * connection was closed
1310
- * @param {String} [options.reason=''] A human-readable string explaining why
1311
- * the connection was closed
1312
- * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1313
- * connection was cleanly closed
1314
- */
1315
- constructor(e, t = {}) {
1316
- super(e), this[We] = t.code === void 0 ? 0 : t.code, this[Ge] = t.reason === void 0 ? "" : t.reason, this[He] = t.wasClean === void 0 ? !1 : t.wasClean;
1317
- }
1318
- /**
1319
- * @type {Number}
1320
- */
1321
- get code() {
1322
- return this[We];
1323
- }
1324
- /**
1325
- * @type {String}
1326
- */
1327
- get reason() {
1328
- return this[Ge];
1329
- }
1330
- /**
1331
- * @type {Boolean}
1332
- */
1333
- get wasClean() {
1334
- return this[He];
1335
- }
1336
- }
1337
- Object.defineProperty(Y.prototype, "code", { enumerable: !0 });
1338
- Object.defineProperty(Y.prototype, "reason", { enumerable: !0 });
1339
- Object.defineProperty(Y.prototype, "wasClean", { enumerable: !0 });
1340
- class le extends B {
1341
- /**
1342
- * Create a new `ErrorEvent`.
1343
- *
1344
- * @param {String} type The name of the event
1345
- * @param {Object} [options] A dictionary object that allows for setting
1346
- * attributes via object members of the same name
1347
- * @param {*} [options.error=null] The error that generated this event
1348
- * @param {String} [options.message=''] The error message
1349
- */
1350
- constructor(e, t = {}) {
1351
- super(e), this[Fe] = t.error === void 0 ? null : t.error, this[je] = t.message === void 0 ? "" : t.message;
1352
- }
1353
- /**
1354
- * @type {*}
1355
- */
1356
- get error() {
1357
- return this[Fe];
1358
- }
1359
- /**
1360
- * @type {String}
1361
- */
1362
- get message() {
1363
- return this[je];
1364
- }
1365
- }
1366
- Object.defineProperty(le.prototype, "error", { enumerable: !0 });
1367
- Object.defineProperty(le.prototype, "message", { enumerable: !0 });
1368
- class xe extends B {
1369
- /**
1370
- * Create a new `MessageEvent`.
1371
- *
1372
- * @param {String} type The name of the event
1373
- * @param {Object} [options] A dictionary object that allows for setting
1374
- * attributes via object members of the same name
1375
- * @param {*} [options.data=null] The message content
1376
- */
1377
- constructor(e, t = {}) {
1378
- super(e), this[Ae] = t.data === void 0 ? null : t.data;
1379
- }
1380
- /**
1381
- * @type {*}
1382
- */
1383
- get data() {
1384
- return this[Ae];
1385
- }
1386
- }
1387
- Object.defineProperty(xe.prototype, "data", { enumerable: !0 });
1388
- const es = {
1389
- /**
1390
- * Register an event listener.
1391
- *
1392
- * @param {String} type A string representing the event type to listen for
1393
- * @param {(Function|Object)} handler The listener to add
1394
- * @param {Object} [options] An options object specifies characteristics about
1395
- * the event listener
1396
- * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1397
- * listener should be invoked at most once after being added. If `true`,
1398
- * the listener would be automatically removed when invoked.
1399
- * @public
1400
- */
1401
- addEventListener(s, e, t = {}) {
1402
- for (const i of this.listeners(s))
1403
- if (!t[F] && i[pe] === e && !i[F])
1404
- return;
1405
- let r;
1406
- if (s === "message")
1407
- r = function(n, o) {
1408
- const l = new xe("message", {
1409
- data: o ? n : n.toString()
1410
- });
1411
- l[I] = this, Z(e, this, l);
1412
- };
1413
- else if (s === "close")
1414
- r = function(n, o) {
1415
- const l = new Y("close", {
1416
- code: n,
1417
- reason: o.toString(),
1418
- wasClean: this._closeFrameReceived && this._closeFrameSent
1419
- });
1420
- l[I] = this, Z(e, this, l);
1421
- };
1422
- else if (s === "error")
1423
- r = function(n) {
1424
- const o = new le("error", {
1425
- error: n,
1426
- message: n.message
1427
- });
1428
- o[I] = this, Z(e, this, o);
1429
- };
1430
- else if (s === "open")
1431
- r = function() {
1432
- const n = new B("open");
1433
- n[I] = this, Z(e, this, n);
1434
- };
1435
- else
1436
- return;
1437
- r[F] = !!t[F], r[pe] = e, t.once ? this.once(s, r) : this.on(s, r);
1438
- },
1439
- /**
1440
- * Remove an event listener.
1441
- *
1442
- * @param {String} type A string representing the event type to remove
1443
- * @param {(Function|Object)} handler The listener to remove
1444
- * @public
1445
- */
1446
- removeEventListener(s, e) {
1447
- for (const t of this.listeners(s))
1448
- if (t[pe] === e && !t[F]) {
1449
- this.removeListener(s, t);
1450
- break;
1451
- }
1452
- }
1453
- };
1454
- var ts = {
1455
- CloseEvent: Y,
1456
- ErrorEvent: le,
1457
- Event: B,
1458
- EventTarget: es,
1459
- MessageEvent: xe
1460
- };
1461
- function Z(s, e, t) {
1462
- typeof s == "object" && s.handleEvent ? s.handleEvent.call(s, t) : s.call(e, t);
1463
- }
1464
- const { tokenChars: j } = ae;
1465
- function k(s, e, t) {
1466
- s[e] === void 0 ? s[e] = [t] : s[e].push(t);
1467
- }
1468
- function ss(s) {
1469
- const e = /* @__PURE__ */ Object.create(null);
1470
- let t = /* @__PURE__ */ Object.create(null), r = !1, i = !1, n = !1, o, l, f = -1, a = -1, c = -1, h = 0;
1471
- for (; h < s.length; h++)
1472
- if (a = s.charCodeAt(h), o === void 0)
1473
- if (c === -1 && j[a] === 1)
1474
- f === -1 && (f = h);
1475
- else if (h !== 0 && (a === 32 || a === 9))
1476
- c === -1 && f !== -1 && (c = h);
1477
- else if (a === 59 || a === 44) {
1478
- if (f === -1)
1479
- throw new SyntaxError(`Unexpected character at index ${h}`);
1480
- c === -1 && (c = h);
1481
- const v = s.slice(f, c);
1482
- a === 44 ? (k(e, v, t), t = /* @__PURE__ */ Object.create(null)) : o = v, f = c = -1;
1483
- } else
1484
- throw new SyntaxError(`Unexpected character at index ${h}`);
1485
- else if (l === void 0)
1486
- if (c === -1 && j[a] === 1)
1487
- f === -1 && (f = h);
1488
- else if (a === 32 || a === 9)
1489
- c === -1 && f !== -1 && (c = h);
1490
- else if (a === 59 || a === 44) {
1491
- if (f === -1)
1492
- throw new SyntaxError(`Unexpected character at index ${h}`);
1493
- c === -1 && (c = h), k(t, s.slice(f, c), !0), a === 44 && (k(e, o, t), t = /* @__PURE__ */ Object.create(null), o = void 0), f = c = -1;
1494
- } else if (a === 61 && f !== -1 && c === -1)
1495
- l = s.slice(f, h), f = c = -1;
1496
- else
1497
- throw new SyntaxError(`Unexpected character at index ${h}`);
1498
- else if (i) {
1499
- if (j[a] !== 1)
1500
- throw new SyntaxError(`Unexpected character at index ${h}`);
1501
- f === -1 ? f = h : r || (r = !0), i = !1;
1502
- } else if (n)
1503
- if (j[a] === 1)
1504
- f === -1 && (f = h);
1505
- else if (a === 34 && f !== -1)
1506
- n = !1, c = h;
1507
- else if (a === 92)
1508
- i = !0;
1509
- else
1510
- throw new SyntaxError(`Unexpected character at index ${h}`);
1511
- else if (a === 34 && s.charCodeAt(h - 1) === 61)
1512
- n = !0;
1513
- else if (c === -1 && j[a] === 1)
1514
- f === -1 && (f = h);
1515
- else if (f !== -1 && (a === 32 || a === 9))
1516
- c === -1 && (c = h);
1517
- else if (a === 59 || a === 44) {
1518
- if (f === -1)
1519
- throw new SyntaxError(`Unexpected character at index ${h}`);
1520
- c === -1 && (c = h);
1521
- let v = s.slice(f, c);
1522
- r && (v = v.replace(/\\/g, ""), r = !1), k(t, l, v), a === 44 && (k(e, o, t), t = /* @__PURE__ */ Object.create(null), o = void 0), l = void 0, f = c = -1;
1523
- } else
1524
- throw new SyntaxError(`Unexpected character at index ${h}`);
1525
- if (f === -1 || n || a === 32 || a === 9)
1526
- throw new SyntaxError("Unexpected end of input");
1527
- c === -1 && (c = h);
1528
- const p = s.slice(f, c);
1529
- return o === void 0 ? k(e, p, t) : (l === void 0 ? k(t, p, !0) : r ? k(t, l, p.replace(/\\/g, "")) : k(t, l, p), k(e, o, t)), e;
1530
- }
1531
- function rs(s) {
1532
- return Object.keys(s).map((e) => {
1533
- let t = s[e];
1534
- return Array.isArray(t) || (t = [t]), t.map((r) => [e].concat(
1535
- Object.keys(r).map((i) => {
1536
- let n = r[i];
1537
- return Array.isArray(n) || (n = [n]), n.map((o) => o === !0 ? i : `${i}=${o}`).join("; ");
1538
- })
1539
- ).join("; ")).join(", ");
1540
- }).join(", ");
1541
- }
1542
- var nt = { format: rs, parse: ss };
1543
- const is = S, ns = S, os = S, ot = S, as = S, { randomBytes: ls, createHash: fs } = S, { URL: me } = S, T = oe, hs = rt, cs = it, {
1544
- BINARY_TYPES: ze,
1545
- EMPTY_BUFFER: Q,
1546
- GUID: us,
1547
- kForOnEventAttribute: ge,
1548
- kListener: ds,
1549
- kStatusCode: _s,
1550
- kWebSocket: y,
1551
- NOOP: at
1552
- } = U, {
1553
- EventTarget: { addEventListener: ps, removeEventListener: ms }
1554
- } = ts, { format: gs, parse: ys } = nt, { toBuffer: vs } = ne, Ss = 30 * 1e3, lt = Symbol("kAborted"), ye = [8, 13], O = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"], Es = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
1555
- let m = class d extends is {
1556
- /**
1557
- * Create a new `WebSocket`.
1558
- *
1559
- * @param {(String|URL)} address The URL to which to connect
1560
- * @param {(String|String[])} [protocols] The subprotocols
1561
- * @param {Object} [options] Connection options
1562
- */
1563
- constructor(e, t, r) {
1564
- super(), this._binaryType = ze[0], this._closeCode = 1006, this._closeFrameReceived = !1, this._closeFrameSent = !1, this._closeMessage = Q, this._closeTimer = null, this._extensions = {}, this._paused = !1, this._protocol = "", this._readyState = d.CONNECTING, this._receiver = null, this._sender = null, this._socket = null, e !== null ? (this._bufferedAmount = 0, this._isServer = !1, this._redirects = 0, t === void 0 ? t = [] : Array.isArray(t) || (typeof t == "object" && t !== null ? (r = t, t = []) : t = [t]), ht(this, e, t, r)) : this._isServer = !0;
1565
- }
1566
- /**
1567
- * This deviates from the WHATWG interface since ws doesn't support the
1568
- * required default "blob" type (instead we define a custom "nodebuffer"
1569
- * type).
1570
- *
1571
- * @type {String}
1572
- */
1573
- get binaryType() {
1574
- return this._binaryType;
1575
- }
1576
- set binaryType(e) {
1577
- ze.includes(e) && (this._binaryType = e, this._receiver && (this._receiver._binaryType = e));
1578
- }
1579
- /**
1580
- * @type {Number}
1581
- */
1582
- get bufferedAmount() {
1583
- return this._socket ? this._socket._writableState.length + this._sender._bufferedBytes : this._bufferedAmount;
1584
- }
1585
- /**
1586
- * @type {String}
1587
- */
1588
- get extensions() {
1589
- return Object.keys(this._extensions).join();
1590
- }
1591
- /**
1592
- * @type {Boolean}
1593
- */
1594
- get isPaused() {
1595
- return this._paused;
1596
- }
1597
- /**
1598
- * @type {Function}
1599
- */
1600
- /* istanbul ignore next */
1601
- get onclose() {
1602
- return null;
1603
- }
1604
- /**
1605
- * @type {Function}
1606
- */
1607
- /* istanbul ignore next */
1608
- get onerror() {
1609
- return null;
1610
- }
1611
- /**
1612
- * @type {Function}
1613
- */
1614
- /* istanbul ignore next */
1615
- get onopen() {
1616
- return null;
1617
- }
1618
- /**
1619
- * @type {Function}
1620
- */
1621
- /* istanbul ignore next */
1622
- get onmessage() {
1623
- return null;
1624
- }
1625
- /**
1626
- * @type {String}
1627
- */
1628
- get protocol() {
1629
- return this._protocol;
1630
- }
1631
- /**
1632
- * @type {Number}
1633
- */
1634
- get readyState() {
1635
- return this._readyState;
1636
- }
1637
- /**
1638
- * @type {String}
1639
- */
1640
- get url() {
1641
- return this._url;
1642
- }
1643
- /**
1644
- * Set up the socket and the internal resources.
1645
- *
1646
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
1647
- * server and client
1648
- * @param {Buffer} head The first packet of the upgraded stream
1649
- * @param {Object} options Options object
1650
- * @param {Function} [options.generateMask] The function used to generate the
1651
- * masking key
1652
- * @param {Number} [options.maxPayload=0] The maximum allowed message size
1653
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
1654
- * not to skip UTF-8 validation for text and close messages
1655
- * @private
1656
- */
1657
- setSocket(e, t, r) {
1658
- const i = new hs({
1659
- binaryType: this.binaryType,
1660
- extensions: this._extensions,
1661
- isServer: this._isServer,
1662
- maxPayload: r.maxPayload,
1663
- skipUTF8Validation: r.skipUTF8Validation
1664
- });
1665
- this._sender = new cs(e, this._extensions, r.generateMask), this._receiver = i, this._socket = e, i[y] = this, e[y] = this, i.on("conclude", ks), i.on("drain", ws), i.on("error", Os), i.on("message", Cs), i.on("ping", Ts), i.on("pong", Ls), e.setTimeout(0), e.setNoDelay(), t.length > 0 && e.unshift(t), e.on("close", ut), e.on("data", fe), e.on("end", dt), e.on("error", _t), this._readyState = d.OPEN, this.emit("open");
1666
- }
1667
- /**
1668
- * Emit the `'close'` event.
1669
- *
1670
- * @private
1671
- */
1672
- emitClose() {
1673
- if (!this._socket) {
1674
- this._readyState = d.CLOSED, this.emit("close", this._closeCode, this._closeMessage);
1675
- return;
1676
- }
1677
- this._extensions[T.extensionName] && this._extensions[T.extensionName].cleanup(), this._receiver.removeAllListeners(), this._readyState = d.CLOSED, this.emit("close", this._closeCode, this._closeMessage);
1678
- }
1679
- /**
1680
- * Start a closing handshake.
1681
- *
1682
- * +----------+ +-----------+ +----------+
1683
- * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
1684
- * | +----------+ +-----------+ +----------+ |
1685
- * +----------+ +-----------+ |
1686
- * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
1687
- * +----------+ +-----------+ |
1688
- * | | | +---+ |
1689
- * +------------------------+-->|fin| - - - -
1690
- * | +---+ | +---+
1691
- * - - - - -|fin|<---------------------+
1692
- * +---+
1693
- *
1694
- * @param {Number} [code] Status code explaining why the connection is closing
1695
- * @param {(String|Buffer)} [data] The reason why the connection is
1696
- * closing
1697
- * @public
1698
- */
1699
- close(e, t) {
1700
- if (this.readyState !== d.CLOSED) {
1701
- if (this.readyState === d.CONNECTING) {
1702
- const r = "WebSocket was closed before the connection was established";
1703
- b(this, this._req, r);
1704
- return;
1705
- }
1706
- if (this.readyState === d.CLOSING) {
1707
- this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end();
1708
- return;
1709
- }
1710
- this._readyState = d.CLOSING, this._sender.close(e, t, !this._isServer, (r) => {
1711
- r || (this._closeFrameSent = !0, (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end());
1712
- }), this._closeTimer = setTimeout(
1713
- this._socket.destroy.bind(this._socket),
1714
- Ss
1715
- );
1716
- }
1717
- }
1718
- /**
1719
- * Pause the socket.
1720
- *
1721
- * @public
1722
- */
1723
- pause() {
1724
- this.readyState === d.CONNECTING || this.readyState === d.CLOSED || (this._paused = !0, this._socket.pause());
1725
- }
1726
- /**
1727
- * Send a ping.
1728
- *
1729
- * @param {*} [data] The data to send
1730
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
1731
- * @param {Function} [cb] Callback which is executed when the ping is sent
1732
- * @public
1733
- */
1734
- ping(e, t, r) {
1735
- if (this.readyState === d.CONNECTING)
1736
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1737
- if (typeof e == "function" ? (r = e, e = t = void 0) : typeof t == "function" && (r = t, t = void 0), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1738
- ve(this, e, r);
1739
- return;
1740
- }
1741
- t === void 0 && (t = !this._isServer), this._sender.ping(e || Q, t, r);
1742
- }
1743
- /**
1744
- * Send a pong.
1745
- *
1746
- * @param {*} [data] The data to send
1747
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
1748
- * @param {Function} [cb] Callback which is executed when the pong is sent
1749
- * @public
1750
- */
1751
- pong(e, t, r) {
1752
- if (this.readyState === d.CONNECTING)
1753
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1754
- if (typeof e == "function" ? (r = e, e = t = void 0) : typeof t == "function" && (r = t, t = void 0), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1755
- ve(this, e, r);
1756
- return;
1757
- }
1758
- t === void 0 && (t = !this._isServer), this._sender.pong(e || Q, t, r);
1759
- }
1760
- /**
1761
- * Resume the socket.
1762
- *
1763
- * @public
1764
- */
1765
- resume() {
1766
- this.readyState === d.CONNECTING || this.readyState === d.CLOSED || (this._paused = !1, this._receiver._writableState.needDrain || this._socket.resume());
1767
- }
1768
- /**
1769
- * Send a data message.
1770
- *
1771
- * @param {*} data The message to send
1772
- * @param {Object} [options] Options object
1773
- * @param {Boolean} [options.binary] Specifies whether `data` is binary or
1774
- * text
1775
- * @param {Boolean} [options.compress] Specifies whether or not to compress
1776
- * `data`
1777
- * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
1778
- * last one
1779
- * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
1780
- * @param {Function} [cb] Callback which is executed when data is written out
1781
- * @public
1782
- */
1783
- send(e, t, r) {
1784
- if (this.readyState === d.CONNECTING)
1785
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1786
- if (typeof t == "function" && (r = t, t = {}), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1787
- ve(this, e, r);
1788
- return;
1789
- }
1790
- const i = {
1791
- binary: typeof e != "string",
1792
- mask: !this._isServer,
1793
- compress: !0,
1794
- fin: !0,
1795
- ...t
1796
- };
1797
- this._extensions[T.extensionName] || (i.compress = !1), this._sender.send(e || Q, i, r);
1798
- }
1799
- /**
1800
- * Forcibly close the connection.
1801
- *
1802
- * @public
1803
- */
1804
- terminate() {
1805
- if (this.readyState !== d.CLOSED) {
1806
- if (this.readyState === d.CONNECTING) {
1807
- const e = "WebSocket was closed before the connection was established";
1808
- b(this, this._req, e);
1809
- return;
1810
- }
1811
- this._socket && (this._readyState = d.CLOSING, this._socket.destroy());
1812
- }
1813
- }
1814
- };
1815
- Object.defineProperty(m, "CONNECTING", {
1816
- enumerable: !0,
1817
- value: O.indexOf("CONNECTING")
1818
- });
1819
- Object.defineProperty(m.prototype, "CONNECTING", {
1820
- enumerable: !0,
1821
- value: O.indexOf("CONNECTING")
1822
- });
1823
- Object.defineProperty(m, "OPEN", {
1824
- enumerable: !0,
1825
- value: O.indexOf("OPEN")
1826
- });
1827
- Object.defineProperty(m.prototype, "OPEN", {
1828
- enumerable: !0,
1829
- value: O.indexOf("OPEN")
1830
- });
1831
- Object.defineProperty(m, "CLOSING", {
1832
- enumerable: !0,
1833
- value: O.indexOf("CLOSING")
1834
- });
1835
- Object.defineProperty(m.prototype, "CLOSING", {
1836
- enumerable: !0,
1837
- value: O.indexOf("CLOSING")
1838
- });
1839
- Object.defineProperty(m, "CLOSED", {
1840
- enumerable: !0,
1841
- value: O.indexOf("CLOSED")
1842
- });
1843
- Object.defineProperty(m.prototype, "CLOSED", {
1844
- enumerable: !0,
1845
- value: O.indexOf("CLOSED")
1846
- });
1847
- [
1848
- "binaryType",
1849
- "bufferedAmount",
1850
- "extensions",
1851
- "isPaused",
1852
- "protocol",
1853
- "readyState",
1854
- "url"
1855
- ].forEach((s) => {
1856
- Object.defineProperty(m.prototype, s, { enumerable: !0 });
1857
- });
1858
- ["open", "error", "close", "message"].forEach((s) => {
1859
- Object.defineProperty(m.prototype, `on${s}`, {
1860
- enumerable: !0,
1861
- get() {
1862
- for (const e of this.listeners(s))
1863
- if (e[ge])
1864
- return e[ds];
1865
- return null;
1866
- },
1867
- set(e) {
1868
- for (const t of this.listeners(s))
1869
- if (t[ge]) {
1870
- this.removeListener(s, t);
1871
- break;
1872
- }
1873
- typeof e == "function" && this.addEventListener(s, e, {
1874
- [ge]: !0
1875
- });
1876
- }
1877
- });
1878
- });
1879
- m.prototype.addEventListener = ps;
1880
- m.prototype.removeEventListener = ms;
1881
- var ft = m;
1882
- function ht(s, e, t, r) {
1883
- const i = {
1884
- protocolVersion: ye[1],
1885
- maxPayload: 104857600,
1886
- skipUTF8Validation: !1,
1887
- perMessageDeflate: !0,
1888
- followRedirects: !1,
1889
- maxRedirects: 10,
1890
- ...r,
1891
- createConnection: void 0,
1892
- socketPath: void 0,
1893
- hostname: void 0,
1894
- protocol: void 0,
1895
- timeout: void 0,
1896
- method: "GET",
1897
- host: void 0,
1898
- path: void 0,
1899
- port: void 0
1900
- };
1901
- if (!ye.includes(i.protocolVersion))
1902
- throw new RangeError(
1903
- `Unsupported protocol version: ${i.protocolVersion} (supported versions: ${ye.join(", ")})`
1904
- );
1905
- let n;
1906
- if (e instanceof me)
1907
- n = e, s._url = e.href;
1908
- else {
1909
- try {
1910
- n = new me(e);
1911
- } catch {
1912
- throw new SyntaxError(`Invalid URL: ${e}`);
1913
- }
1914
- s._url = e;
1915
- }
1916
- const o = n.protocol === "wss:", l = n.protocol === "ws+unix:";
1917
- let f;
1918
- if (n.protocol !== "ws:" && !o && !l ? f = `The URL's protocol must be one of "ws:", "wss:", or "ws+unix:"` : l && !n.pathname ? f = "The URL's pathname is empty" : n.hash && (f = "The URL contains a fragment identifier"), f) {
1919
- const u = new SyntaxError(f);
1920
- if (s._redirects === 0)
1921
- throw u;
1922
- ee(s, u);
1923
- return;
1924
- }
1925
- const a = o ? 443 : 80, c = ls(16).toString("base64"), h = o ? ns.request : os.request, p = /* @__PURE__ */ new Set();
1926
- let v;
1927
- if (i.createConnection = o ? xs : bs, i.defaultPort = i.defaultPort || a, i.port = n.port || a, i.host = n.hostname.startsWith("[") ? n.hostname.slice(1, -1) : n.hostname, i.headers = {
1928
- ...i.headers,
1929
- "Sec-WebSocket-Version": i.protocolVersion,
1930
- "Sec-WebSocket-Key": c,
1931
- Connection: "Upgrade",
1932
- Upgrade: "websocket"
1933
- }, i.path = n.pathname + n.search, i.timeout = i.handshakeTimeout, i.perMessageDeflate && (v = new T(
1934
- i.perMessageDeflate !== !0 ? i.perMessageDeflate : {},
1935
- !1,
1936
- i.maxPayload
1937
- ), i.headers["Sec-WebSocket-Extensions"] = gs({
1938
- [T.extensionName]: v.offer()
1939
- })), t.length) {
1940
- for (const u of t) {
1941
- if (typeof u != "string" || !Es.test(u) || p.has(u))
1942
- throw new SyntaxError(
1943
- "An invalid or duplicated subprotocol was specified"
1944
- );
1945
- p.add(u);
1946
- }
1947
- i.headers["Sec-WebSocket-Protocol"] = t.join(",");
1948
- }
1949
- if (i.origin && (i.protocolVersion < 13 ? i.headers["Sec-WebSocket-Origin"] = i.origin : i.headers.Origin = i.origin), (n.username || n.password) && (i.auth = `${n.username}:${n.password}`), l) {
1950
- const u = i.path.split(":");
1951
- i.socketPath = u[0], i.path = u[1];
1952
- }
1953
- let _;
1954
- if (i.followRedirects) {
1955
- if (s._redirects === 0) {
1956
- s._originalIpc = l, s._originalSecure = o, s._originalHostOrSocketPath = l ? i.socketPath : n.host;
1957
- const u = r && r.headers;
1958
- if (r = { ...r, headers: {} }, u)
1959
- for (const [E, $] of Object.entries(u))
1960
- r.headers[E.toLowerCase()] = $;
1961
- } else if (s.listenerCount("redirect") === 0) {
1962
- const u = l ? s._originalIpc ? i.socketPath === s._originalHostOrSocketPath : !1 : s._originalIpc ? !1 : n.host === s._originalHostOrSocketPath;
1963
- (!u || s._originalSecure && !o) && (delete i.headers.authorization, delete i.headers.cookie, u || delete i.headers.host, i.auth = void 0);
1964
- }
1965
- i.auth && !r.headers.authorization && (r.headers.authorization = "Basic " + Buffer.from(i.auth).toString("base64")), _ = s._req = h(i), s._redirects && s.emit("redirect", s.url, _);
1966
- } else
1967
- _ = s._req = h(i);
1968
- i.timeout && _.on("timeout", () => {
1969
- b(s, _, "Opening handshake has timed out");
1970
- }), _.on("error", (u) => {
1971
- _ === null || _[lt] || (_ = s._req = null, ee(s, u));
1972
- }), _.on("response", (u) => {
1973
- const E = u.headers.location, $ = u.statusCode;
1974
- if (E && i.followRedirects && $ >= 300 && $ < 400) {
1975
- if (++s._redirects > i.maxRedirects) {
1976
- b(s, _, "Maximum redirects exceeded");
1977
- return;
1978
- }
1979
- _.abort();
1980
- let q;
1981
- try {
1982
- q = new me(E, e);
1983
- } catch {
1984
- const L = new SyntaxError(`Invalid URL: ${E}`);
1985
- ee(s, L);
1986
- return;
1987
- }
1988
- ht(s, q, t, r);
1989
- } else
1990
- s.emit("unexpected-response", _, u) || b(
1991
- s,
1992
- _,
1993
- `Unexpected server response: ${u.statusCode}`
1994
- );
1995
- }), _.on("upgrade", (u, E, $) => {
1996
- if (s.emit("upgrade", u), s.readyState !== m.CONNECTING)
1997
- return;
1998
- if (_ = s._req = null, u.headers.upgrade.toLowerCase() !== "websocket") {
1999
- b(s, E, "Invalid Upgrade header");
2000
- return;
2001
- }
2002
- const q = fs("sha1").update(c + us).digest("base64");
2003
- if (u.headers["sec-websocket-accept"] !== q) {
2004
- b(s, E, "Invalid Sec-WebSocket-Accept header");
2005
- return;
2006
- }
2007
- const D = u.headers["sec-websocket-protocol"];
2008
- let L;
2009
- if (D !== void 0 ? p.size ? p.has(D) || (L = "Server sent an invalid subprotocol") : L = "Server sent a subprotocol but none was requested" : p.size && (L = "Server sent no subprotocol"), L) {
2010
- b(s, E, L);
2011
- return;
2012
- }
2013
- D && (s._protocol = D);
2014
- const ke = u.headers["sec-websocket-extensions"];
2015
- if (ke !== void 0) {
2016
- if (!v) {
2017
- b(s, E, "Server sent a Sec-WebSocket-Extensions header but no extension was requested");
2018
- return;
2019
- }
2020
- let he;
2021
- try {
2022
- he = ys(ke);
2023
- } catch {
2024
- b(s, E, "Invalid Sec-WebSocket-Extensions header");
2025
- return;
2026
- }
2027
- const we = Object.keys(he);
2028
- if (we.length !== 1 || we[0] !== T.extensionName) {
2029
- b(s, E, "Server indicated an extension that was not requested");
2030
- return;
2031
- }
2032
- try {
2033
- v.accept(he[T.extensionName]);
2034
- } catch {
2035
- b(s, E, "Invalid Sec-WebSocket-Extensions header");
2036
- return;
2037
- }
2038
- s._extensions[T.extensionName] = v;
2039
- }
2040
- s.setSocket(E, $, {
2041
- generateMask: i.generateMask,
2042
- maxPayload: i.maxPayload,
2043
- skipUTF8Validation: i.skipUTF8Validation
2044
- });
2045
- }), i.finishRequest ? i.finishRequest(_, s) : _.end();
2046
- }
2047
- function ee(s, e) {
2048
- s._readyState = m.CLOSING, s.emit("error", e), s.emitClose();
2049
- }
2050
- function bs(s) {
2051
- return s.path = s.socketPath, ot.connect(s);
2052
- }
2053
- function xs(s) {
2054
- return s.path = void 0, !s.servername && s.servername !== "" && (s.servername = ot.isIP(s.host) ? "" : s.host), as.connect(s);
2055
- }
2056
- function b(s, e, t) {
2057
- s._readyState = m.CLOSING;
2058
- const r = new Error(t);
2059
- Error.captureStackTrace(r, b), e.setHeader ? (e[lt] = !0, e.abort(), e.socket && !e.socket.destroyed && e.socket.destroy(), process.nextTick(ee, s, r)) : (e.destroy(r), e.once("error", s.emit.bind(s, "error")), e.once("close", s.emitClose.bind(s)));
2060
- }
2061
- function ve(s, e, t) {
2062
- if (e) {
2063
- const r = vs(e).length;
2064
- s._socket ? s._sender._bufferedBytes += r : s._bufferedAmount += r;
2065
- }
2066
- if (t) {
2067
- const r = new Error(
2068
- `WebSocket is not open: readyState ${s.readyState} (${O[s.readyState]})`
2069
- );
2070
- process.nextTick(t, r);
2071
- }
2072
- }
2073
- function ks(s, e) {
2074
- const t = this[y];
2075
- t._closeFrameReceived = !0, t._closeMessage = e, t._closeCode = s, t._socket[y] !== void 0 && (t._socket.removeListener("data", fe), process.nextTick(ct, t._socket), s === 1005 ? t.close() : t.close(s, e));
2076
- }
2077
- function ws() {
2078
- const s = this[y];
2079
- s.isPaused || s._socket.resume();
2080
- }
2081
- function Os(s) {
2082
- const e = this[y];
2083
- e._socket[y] !== void 0 && (e._socket.removeListener("data", fe), process.nextTick(ct, e._socket), e.close(s[_s])), e.emit("error", s);
2084
- }
2085
- function Ye() {
2086
- this[y].emitClose();
2087
- }
2088
- function Cs(s, e) {
2089
- this[y].emit("message", s, e);
2090
- }
2091
- function Ts(s) {
2092
- const e = this[y];
2093
- e.pong(s, !e._isServer, at), e.emit("ping", s);
2094
- }
2095
- function Ls(s) {
2096
- this[y].emit("pong", s);
2097
- }
2098
- function ct(s) {
2099
- s.resume();
2100
- }
2101
- function ut() {
2102
- const s = this[y];
2103
- this.removeListener("close", ut), this.removeListener("data", fe), this.removeListener("end", dt), s._readyState = m.CLOSING;
2104
- let e;
2105
- !this._readableState.endEmitted && !s._closeFrameReceived && !s._receiver._writableState.errorEmitted && (e = s._socket.read()) !== null && s._receiver.write(e), s._receiver.end(), this[y] = void 0, clearTimeout(s._closeTimer), s._receiver._writableState.finished || s._receiver._writableState.errorEmitted ? s.emitClose() : (s._receiver.on("error", Ye), s._receiver.on("finish", Ye));
2106
- }
2107
- function fe(s) {
2108
- this[y]._receiver.write(s) || this.pause();
2109
- }
2110
- function dt() {
2111
- const s = this[y];
2112
- s._readyState = m.CLOSING, s._receiver.end(), this.end();
2113
- }
2114
- function _t() {
2115
- const s = this[y];
2116
- this.removeListener("error", _t), this.on("error", at), s && (s._readyState = m.CLOSING, this.destroy());
2117
- }
2118
- const Xs = /* @__PURE__ */ z(ft), { tokenChars: Ns } = ae;
2119
- function Ps(s) {
2120
- const e = /* @__PURE__ */ new Set();
2121
- let t = -1, r = -1, i = 0;
2122
- for (i; i < s.length; i++) {
2123
- const o = s.charCodeAt(i);
2124
- if (r === -1 && Ns[o] === 1)
2125
- t === -1 && (t = i);
2126
- else if (i !== 0 && (o === 32 || o === 9))
2127
- r === -1 && t !== -1 && (r = i);
2128
- else if (o === 44) {
2129
- if (t === -1)
2130
- throw new SyntaxError(`Unexpected character at index ${i}`);
2131
- r === -1 && (r = i);
2132
- const l = s.slice(t, r);
2133
- if (e.has(l))
2134
- throw new SyntaxError(`The "${l}" subprotocol is duplicated`);
2135
- e.add(l), t = r = -1;
2136
- } else
2137
- throw new SyntaxError(`Unexpected character at index ${i}`);
2138
- }
2139
- if (t === -1 || r !== -1)
2140
- throw new SyntaxError("Unexpected end of input");
2141
- const n = s.slice(t, i);
2142
- if (e.has(n))
2143
- throw new SyntaxError(`The "${n}" subprotocol is duplicated`);
2144
- return e.add(n), e;
2145
- }
2146
- var Rs = { parse: Ps };
2147
- const Us = S, ie = S, { createHash: Bs } = S, qe = nt, N = oe, $s = Rs, Ms = ft, { GUID: Is, kWebSocket: Ds } = U, Ws = /^[+/0-9A-Za-z]{22}==$/, Ke = 0, Xe = 1, pt = 2;
2148
- class As extends Us {
2149
- /**
2150
- * Create a `WebSocketServer` instance.
2151
- *
2152
- * @param {Object} options Configuration options
2153
- * @param {Number} [options.backlog=511] The maximum length of the queue of
2154
- * pending connections
2155
- * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
2156
- * track clients
2157
- * @param {Function} [options.handleProtocols] A hook to handle protocols
2158
- * @param {String} [options.host] The hostname where to bind the server
2159
- * @param {Number} [options.maxPayload=104857600] The maximum allowed message
2160
- * size
2161
- * @param {Boolean} [options.noServer=false] Enable no server mode
2162
- * @param {String} [options.path] Accept only connections matching this path
2163
- * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
2164
- * permessage-deflate
2165
- * @param {Number} [options.port] The port where to bind the server
2166
- * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
2167
- * server to use
2168
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2169
- * not to skip UTF-8 validation for text and close messages
2170
- * @param {Function} [options.verifyClient] A hook to reject connections
2171
- * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
2172
- * class to use. It must be the `WebSocket` class or class that extends it
2173
- * @param {Function} [callback] A listener for the `listening` event
2174
- */
2175
- constructor(e, t) {
2176
- if (super(), e = {
2177
- maxPayload: 100 * 1024 * 1024,
2178
- skipUTF8Validation: !1,
2179
- perMessageDeflate: !1,
2180
- handleProtocols: null,
2181
- clientTracking: !0,
2182
- verifyClient: null,
2183
- noServer: !1,
2184
- backlog: null,
2185
- // use default (511 as implemented in net.js)
2186
- server: null,
2187
- host: null,
2188
- path: null,
2189
- port: null,
2190
- WebSocket: Ms,
2191
- ...e
2192
- }, e.port == null && !e.server && !e.noServer || e.port != null && (e.server || e.noServer) || e.server && e.noServer)
2193
- throw new TypeError(
2194
- 'One and only one of the "port", "server", or "noServer" options must be specified'
2195
- );
2196
- if (e.port != null ? (this._server = ie.createServer((r, i) => {
2197
- const n = ie.STATUS_CODES[426];
2198
- i.writeHead(426, {
2199
- "Content-Length": n.length,
2200
- "Content-Type": "text/plain"
2201
- }), i.end(n);
2202
- }), this._server.listen(
2203
- e.port,
2204
- e.host,
2205
- e.backlog,
2206
- t
2207
- )) : e.server && (this._server = e.server), this._server) {
2208
- const r = this.emit.bind(this, "connection");
2209
- this._removeListeners = js(this._server, {
2210
- listening: this.emit.bind(this, "listening"),
2211
- error: this.emit.bind(this, "error"),
2212
- upgrade: (i, n, o) => {
2213
- this.handleUpgrade(i, n, o, r);
2214
- }
2215
- });
2216
- }
2217
- e.perMessageDeflate === !0 && (e.perMessageDeflate = {}), e.clientTracking && (this.clients = /* @__PURE__ */ new Set(), this._shouldEmitClose = !1), this.options = e, this._state = Ke;
2218
- }
2219
- /**
2220
- * Returns the bound address, the address family name, and port of the server
2221
- * as reported by the operating system if listening on an IP socket.
2222
- * If the server is listening on a pipe or UNIX domain socket, the name is
2223
- * returned as a string.
2224
- *
2225
- * @return {(Object|String|null)} The address of the server
2226
- * @public
2227
- */
2228
- address() {
2229
- if (this.options.noServer)
2230
- throw new Error('The server is operating in "noServer" mode');
2231
- return this._server ? this._server.address() : null;
2232
- }
2233
- /**
2234
- * Stop the server from accepting new connections and emit the `'close'` event
2235
- * when all existing connections are closed.
2236
- *
2237
- * @param {Function} [cb] A one-time listener for the `'close'` event
2238
- * @public
2239
- */
2240
- close(e) {
2241
- if (this._state === pt) {
2242
- e && this.once("close", () => {
2243
- e(new Error("The server is not running"));
2244
- }), process.nextTick(G, this);
2245
- return;
2246
- }
2247
- if (e && this.once("close", e), this._state !== Xe)
2248
- if (this._state = Xe, this.options.noServer || this.options.server)
2249
- this._server && (this._removeListeners(), this._removeListeners = this._server = null), this.clients ? this.clients.size ? this._shouldEmitClose = !0 : process.nextTick(G, this) : process.nextTick(G, this);
2250
- else {
2251
- const t = this._server;
2252
- this._removeListeners(), this._removeListeners = this._server = null, t.close(() => {
2253
- G(this);
2254
- });
2255
- }
2256
- }
2257
- /**
2258
- * See if a given request should be handled by this server instance.
2259
- *
2260
- * @param {http.IncomingMessage} req Request object to inspect
2261
- * @return {Boolean} `true` if the request is valid, else `false`
2262
- * @public
2263
- */
2264
- shouldHandle(e) {
2265
- if (this.options.path) {
2266
- const t = e.url.indexOf("?");
2267
- if ((t !== -1 ? e.url.slice(0, t) : e.url) !== this.options.path)
2268
- return !1;
2269
- }
2270
- return !0;
2271
- }
2272
- /**
2273
- * Handle a HTTP Upgrade request.
2274
- *
2275
- * @param {http.IncomingMessage} req The request object
2276
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
2277
- * server and client
2278
- * @param {Buffer} head The first packet of the upgraded stream
2279
- * @param {Function} cb Callback
2280
- * @public
2281
- */
2282
- handleUpgrade(e, t, r, i) {
2283
- t.on("error", Ze);
2284
- const n = e.headers["sec-websocket-key"], o = +e.headers["sec-websocket-version"];
2285
- if (e.method !== "GET") {
2286
- R(this, e, t, 405, "Invalid HTTP method");
2287
- return;
2288
- }
2289
- if (e.headers.upgrade.toLowerCase() !== "websocket") {
2290
- R(this, e, t, 400, "Invalid Upgrade header");
2291
- return;
2292
- }
2293
- if (!n || !Ws.test(n)) {
2294
- R(this, e, t, 400, "Missing or invalid Sec-WebSocket-Key header");
2295
- return;
2296
- }
2297
- if (o !== 8 && o !== 13) {
2298
- R(this, e, t, 400, "Missing or invalid Sec-WebSocket-Version header");
2299
- return;
2300
- }
2301
- if (!this.shouldHandle(e)) {
2302
- H(t, 400);
2303
- return;
2304
- }
2305
- const l = e.headers["sec-websocket-protocol"];
2306
- let f = /* @__PURE__ */ new Set();
2307
- if (l !== void 0)
2308
- try {
2309
- f = $s.parse(l);
2310
- } catch {
2311
- R(this, e, t, 400, "Invalid Sec-WebSocket-Protocol header");
2312
- return;
2313
- }
2314
- const a = e.headers["sec-websocket-extensions"], c = {};
2315
- if (this.options.perMessageDeflate && a !== void 0) {
2316
- const h = new N(
2317
- this.options.perMessageDeflate,
2318
- !0,
2319
- this.options.maxPayload
2320
- );
2321
- try {
2322
- const p = qe.parse(a);
2323
- p[N.extensionName] && (h.accept(p[N.extensionName]), c[N.extensionName] = h);
2324
- } catch {
2325
- R(this, e, t, 400, "Invalid or unacceptable Sec-WebSocket-Extensions header");
2326
- return;
2327
- }
2328
- }
2329
- if (this.options.verifyClient) {
2330
- const h = {
2331
- origin: e.headers[`${o === 8 ? "sec-websocket-origin" : "origin"}`],
2332
- secure: !!(e.socket.authorized || e.socket.encrypted),
2333
- req: e
2334
- };
2335
- if (this.options.verifyClient.length === 2) {
2336
- this.options.verifyClient(h, (p, v, _, u) => {
2337
- if (!p)
2338
- return H(t, v || 401, _, u);
2339
- this.completeUpgrade(
2340
- c,
2341
- n,
2342
- f,
2343
- e,
2344
- t,
2345
- r,
2346
- i
2347
- );
2348
- });
2349
- return;
2350
- }
2351
- if (!this.options.verifyClient(h))
2352
- return H(t, 401);
2353
- }
2354
- this.completeUpgrade(c, n, f, e, t, r, i);
2355
- }
2356
- /**
2357
- * Upgrade the connection to WebSocket.
2358
- *
2359
- * @param {Object} extensions The accepted extensions
2360
- * @param {String} key The value of the `Sec-WebSocket-Key` header
2361
- * @param {Set} protocols The subprotocols
2362
- * @param {http.IncomingMessage} req The request object
2363
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
2364
- * server and client
2365
- * @param {Buffer} head The first packet of the upgraded stream
2366
- * @param {Function} cb Callback
2367
- * @throws {Error} If called more than once with the same socket
2368
- * @private
2369
- */
2370
- completeUpgrade(e, t, r, i, n, o, l) {
2371
- if (!n.readable || !n.writable)
2372
- return n.destroy();
2373
- if (n[Ds])
2374
- throw new Error(
2375
- "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
2376
- );
2377
- if (this._state > Ke)
2378
- return H(n, 503);
2379
- const a = [
2380
- "HTTP/1.1 101 Switching Protocols",
2381
- "Upgrade: websocket",
2382
- "Connection: Upgrade",
2383
- `Sec-WebSocket-Accept: ${Bs("sha1").update(t + Is).digest("base64")}`
2384
- ], c = new this.options.WebSocket(null);
2385
- if (r.size) {
2386
- const h = this.options.handleProtocols ? this.options.handleProtocols(r, i) : r.values().next().value;
2387
- h && (a.push(`Sec-WebSocket-Protocol: ${h}`), c._protocol = h);
2388
- }
2389
- if (e[N.extensionName]) {
2390
- const h = e[N.extensionName].params, p = qe.format({
2391
- [N.extensionName]: [h]
2392
- });
2393
- a.push(`Sec-WebSocket-Extensions: ${p}`), c._extensions = e;
2394
- }
2395
- this.emit("headers", a, i), n.write(a.concat(`\r
2396
- `).join(`\r
2397
- `)), n.removeListener("error", Ze), c.setSocket(n, o, {
2398
- maxPayload: this.options.maxPayload,
2399
- skipUTF8Validation: this.options.skipUTF8Validation
2400
- }), this.clients && (this.clients.add(c), c.on("close", () => {
2401
- this.clients.delete(c), this._shouldEmitClose && !this.clients.size && process.nextTick(G, this);
2402
- })), l(c, i);
2403
- }
2404
- }
2405
- var Fs = As;
2406
- function js(s, e) {
2407
- for (const t of Object.keys(e))
2408
- s.on(t, e[t]);
2409
- return function() {
2410
- for (const r of Object.keys(e))
2411
- s.removeListener(r, e[r]);
2412
- };
2413
- }
2414
- function G(s) {
2415
- s._state = pt, s.emit("close");
2416
- }
2417
- function Ze() {
2418
- this.destroy();
2419
- }
2420
- function H(s, e, t, r) {
2421
- t = t || ie.STATUS_CODES[e], r = {
2422
- Connection: "close",
2423
- "Content-Type": "text/html",
2424
- "Content-Length": Buffer.byteLength(t),
2425
- ...r
2426
- }, s.once("finish", s.destroy), s.end(
2427
- `HTTP/1.1 ${e} ${ie.STATUS_CODES[e]}\r
2428
- ` + Object.keys(r).map((i) => `${i}: ${r[i]}`).join(`\r
2429
- `) + `\r
2430
- \r
2431
- ` + t
2432
- );
2433
- }
2434
- function R(s, e, t, r, i) {
2435
- if (s.listenerCount("wsClientError")) {
2436
- const n = new Error(i);
2437
- Error.captureStackTrace(n, R), s.emit("wsClientError", n, t, e);
2438
- } else
2439
- H(t, r, i);
2440
- }
2441
- const Zs = /* @__PURE__ */ z(Fs);
2442
- export {
2443
- qs as Receiver,
2444
- Ks as Sender,
2445
- Xs as WebSocket,
2446
- Zs as WebSocketServer,
2447
- Vs as createWebSocketStream,
2448
- Xs as default
2449
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/backend/gradio_pdf/templates/component/wrapper-98f94c21-9201c0de.js DELETED
@@ -1,2449 +0,0 @@
1
- import { r as S } from "./Index-f36f7747.js";
2
- function z(s) {
3
- return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
4
- }
5
- function gt(s) {
6
- if (s.__esModule)
7
- return s;
8
- var e = s.default;
9
- if (typeof e == "function") {
10
- var t = function r() {
11
- return this instanceof r ? Reflect.construct(e, arguments, this.constructor) : e.apply(this, arguments);
12
- };
13
- t.prototype = e.prototype;
14
- } else
15
- t = {};
16
- return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(s).forEach(function(r) {
17
- var i = Object.getOwnPropertyDescriptor(s, r);
18
- Object.defineProperty(t, r, i.get ? i : {
19
- enumerable: !0,
20
- get: function() {
21
- return s[r];
22
- }
23
- });
24
- }), t;
25
- }
26
- const { Duplex: yt } = S;
27
- function Oe(s) {
28
- s.emit("close");
29
- }
30
- function vt() {
31
- !this.destroyed && this._writableState.finished && this.destroy();
32
- }
33
- function Qe(s) {
34
- this.removeListener("error", Qe), this.destroy(), this.listenerCount("error") === 0 && this.emit("error", s);
35
- }
36
- function St(s, e) {
37
- let t = !0;
38
- const r = new yt({
39
- ...e,
40
- autoDestroy: !1,
41
- emitClose: !1,
42
- objectMode: !1,
43
- writableObjectMode: !1
44
- });
45
- return s.on("message", function(n, o) {
46
- const l = !o && r._readableState.objectMode ? n.toString() : n;
47
- r.push(l) || s.pause();
48
- }), s.once("error", function(n) {
49
- r.destroyed || (t = !1, r.destroy(n));
50
- }), s.once("close", function() {
51
- r.destroyed || r.push(null);
52
- }), r._destroy = function(i, n) {
53
- if (s.readyState === s.CLOSED) {
54
- n(i), process.nextTick(Oe, r);
55
- return;
56
- }
57
- let o = !1;
58
- s.once("error", function(f) {
59
- o = !0, n(f);
60
- }), s.once("close", function() {
61
- o || n(i), process.nextTick(Oe, r);
62
- }), t && s.terminate();
63
- }, r._final = function(i) {
64
- if (s.readyState === s.CONNECTING) {
65
- s.once("open", function() {
66
- r._final(i);
67
- });
68
- return;
69
- }
70
- s._socket !== null && (s._socket._writableState.finished ? (i(), r._readableState.endEmitted && r.destroy()) : (s._socket.once("finish", function() {
71
- i();
72
- }), s.close()));
73
- }, r._read = function() {
74
- s.isPaused && s.resume();
75
- }, r._write = function(i, n, o) {
76
- if (s.readyState === s.CONNECTING) {
77
- s.once("open", function() {
78
- r._write(i, n, o);
79
- });
80
- return;
81
- }
82
- s.send(i, o);
83
- }, r.on("end", vt), r.on("error", Qe), r;
84
- }
85
- var Et = St;
86
- const Vs = /* @__PURE__ */ z(Et);
87
- var te = { exports: {} }, U = {
88
- BINARY_TYPES: ["nodebuffer", "arraybuffer", "fragments"],
89
- EMPTY_BUFFER: Buffer.alloc(0),
90
- GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
91
- kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
92
- kListener: Symbol("kListener"),
93
- kStatusCode: Symbol("status-code"),
94
- kWebSocket: Symbol("websocket"),
95
- NOOP: () => {
96
- }
97
- }, bt, xt;
98
- const { EMPTY_BUFFER: kt } = U, Se = Buffer[Symbol.species];
99
- function wt(s, e) {
100
- if (s.length === 0)
101
- return kt;
102
- if (s.length === 1)
103
- return s[0];
104
- const t = Buffer.allocUnsafe(e);
105
- let r = 0;
106
- for (let i = 0; i < s.length; i++) {
107
- const n = s[i];
108
- t.set(n, r), r += n.length;
109
- }
110
- return r < e ? new Se(t.buffer, t.byteOffset, r) : t;
111
- }
112
- function Je(s, e, t, r, i) {
113
- for (let n = 0; n < i; n++)
114
- t[r + n] = s[n] ^ e[n & 3];
115
- }
116
- function et(s, e) {
117
- for (let t = 0; t < s.length; t++)
118
- s[t] ^= e[t & 3];
119
- }
120
- function Ot(s) {
121
- return s.length === s.buffer.byteLength ? s.buffer : s.buffer.slice(s.byteOffset, s.byteOffset + s.length);
122
- }
123
- function Ee(s) {
124
- if (Ee.readOnly = !0, Buffer.isBuffer(s))
125
- return s;
126
- let e;
127
- return s instanceof ArrayBuffer ? e = new Se(s) : ArrayBuffer.isView(s) ? e = new Se(s.buffer, s.byteOffset, s.byteLength) : (e = Buffer.from(s), Ee.readOnly = !1), e;
128
- }
129
- te.exports = {
130
- concat: wt,
131
- mask: Je,
132
- toArrayBuffer: Ot,
133
- toBuffer: Ee,
134
- unmask: et
135
- };
136
- if (!process.env.WS_NO_BUFFER_UTIL)
137
- try {
138
- const s = require("bufferutil");
139
- xt = te.exports.mask = function(e, t, r, i, n) {
140
- n < 48 ? Je(e, t, r, i, n) : s.mask(e, t, r, i, n);
141
- }, bt = te.exports.unmask = function(e, t) {
142
- e.length < 32 ? et(e, t) : s.unmask(e, t);
143
- };
144
- } catch {
145
- }
146
- var ne = te.exports;
147
- const Ce = Symbol("kDone"), ue = Symbol("kRun");
148
- let Ct = class {
149
- /**
150
- * Creates a new `Limiter`.
151
- *
152
- * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
153
- * to run concurrently
154
- */
155
- constructor(e) {
156
- this[Ce] = () => {
157
- this.pending--, this[ue]();
158
- }, this.concurrency = e || 1 / 0, this.jobs = [], this.pending = 0;
159
- }
160
- /**
161
- * Adds a job to the queue.
162
- *
163
- * @param {Function} job The job to run
164
- * @public
165
- */
166
- add(e) {
167
- this.jobs.push(e), this[ue]();
168
- }
169
- /**
170
- * Removes a job from the queue and runs it if possible.
171
- *
172
- * @private
173
- */
174
- [ue]() {
175
- if (this.pending !== this.concurrency && this.jobs.length) {
176
- const e = this.jobs.shift();
177
- this.pending++, e(this[Ce]);
178
- }
179
- }
180
- };
181
- var Tt = Ct;
182
- const W = S, Te = ne, Lt = Tt, { kStatusCode: tt } = U, Nt = Buffer[Symbol.species], Pt = Buffer.from([0, 0, 255, 255]), se = Symbol("permessage-deflate"), w = Symbol("total-length"), V = Symbol("callback"), C = Symbol("buffers"), J = Symbol("error");
183
- let K, Rt = class {
184
- /**
185
- * Creates a PerMessageDeflate instance.
186
- *
187
- * @param {Object} [options] Configuration options
188
- * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
189
- * for, or request, a custom client window size
190
- * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
191
- * acknowledge disabling of client context takeover
192
- * @param {Number} [options.concurrencyLimit=10] The number of concurrent
193
- * calls to zlib
194
- * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
195
- * use of a custom server window size
196
- * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
197
- * disabling of server context takeover
198
- * @param {Number} [options.threshold=1024] Size (in bytes) below which
199
- * messages should not be compressed if context takeover is disabled
200
- * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
201
- * deflate
202
- * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
203
- * inflate
204
- * @param {Boolean} [isServer=false] Create the instance in either server or
205
- * client mode
206
- * @param {Number} [maxPayload=0] The maximum allowed message length
207
- */
208
- constructor(e, t, r) {
209
- if (this._maxPayload = r | 0, this._options = e || {}, this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024, this._isServer = !!t, this._deflate = null, this._inflate = null, this.params = null, !K) {
210
- const i = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
211
- K = new Lt(i);
212
- }
213
- }
214
- /**
215
- * @type {String}
216
- */
217
- static get extensionName() {
218
- return "permessage-deflate";
219
- }
220
- /**
221
- * Create an extension negotiation offer.
222
- *
223
- * @return {Object} Extension parameters
224
- * @public
225
- */
226
- offer() {
227
- const e = {};
228
- return this._options.serverNoContextTakeover && (e.server_no_context_takeover = !0), this._options.clientNoContextTakeover && (e.client_no_context_takeover = !0), this._options.serverMaxWindowBits && (e.server_max_window_bits = this._options.serverMaxWindowBits), this._options.clientMaxWindowBits ? e.client_max_window_bits = this._options.clientMaxWindowBits : this._options.clientMaxWindowBits == null && (e.client_max_window_bits = !0), e;
229
- }
230
- /**
231
- * Accept an extension negotiation offer/response.
232
- *
233
- * @param {Array} configurations The extension negotiation offers/reponse
234
- * @return {Object} Accepted configuration
235
- * @public
236
- */
237
- accept(e) {
238
- return e = this.normalizeParams(e), this.params = this._isServer ? this.acceptAsServer(e) : this.acceptAsClient(e), this.params;
239
- }
240
- /**
241
- * Releases all resources used by the extension.
242
- *
243
- * @public
244
- */
245
- cleanup() {
246
- if (this._inflate && (this._inflate.close(), this._inflate = null), this._deflate) {
247
- const e = this._deflate[V];
248
- this._deflate.close(), this._deflate = null, e && e(
249
- new Error(
250
- "The deflate stream was closed while data was being processed"
251
- )
252
- );
253
- }
254
- }
255
- /**
256
- * Accept an extension negotiation offer.
257
- *
258
- * @param {Array} offers The extension negotiation offers
259
- * @return {Object} Accepted configuration
260
- * @private
261
- */
262
- acceptAsServer(e) {
263
- const t = this._options, r = e.find((i) => !(t.serverNoContextTakeover === !1 && i.server_no_context_takeover || i.server_max_window_bits && (t.serverMaxWindowBits === !1 || typeof t.serverMaxWindowBits == "number" && t.serverMaxWindowBits > i.server_max_window_bits) || typeof t.clientMaxWindowBits == "number" && !i.client_max_window_bits));
264
- if (!r)
265
- throw new Error("None of the extension offers can be accepted");
266
- return t.serverNoContextTakeover && (r.server_no_context_takeover = !0), t.clientNoContextTakeover && (r.client_no_context_takeover = !0), typeof t.serverMaxWindowBits == "number" && (r.server_max_window_bits = t.serverMaxWindowBits), typeof t.clientMaxWindowBits == "number" ? r.client_max_window_bits = t.clientMaxWindowBits : (r.client_max_window_bits === !0 || t.clientMaxWindowBits === !1) && delete r.client_max_window_bits, r;
267
- }
268
- /**
269
- * Accept the extension negotiation response.
270
- *
271
- * @param {Array} response The extension negotiation response
272
- * @return {Object} Accepted configuration
273
- * @private
274
- */
275
- acceptAsClient(e) {
276
- const t = e[0];
277
- if (this._options.clientNoContextTakeover === !1 && t.client_no_context_takeover)
278
- throw new Error('Unexpected parameter "client_no_context_takeover"');
279
- if (!t.client_max_window_bits)
280
- typeof this._options.clientMaxWindowBits == "number" && (t.client_max_window_bits = this._options.clientMaxWindowBits);
281
- else if (this._options.clientMaxWindowBits === !1 || typeof this._options.clientMaxWindowBits == "number" && t.client_max_window_bits > this._options.clientMaxWindowBits)
282
- throw new Error(
283
- 'Unexpected or invalid parameter "client_max_window_bits"'
284
- );
285
- return t;
286
- }
287
- /**
288
- * Normalize parameters.
289
- *
290
- * @param {Array} configurations The extension negotiation offers/reponse
291
- * @return {Array} The offers/response with normalized parameters
292
- * @private
293
- */
294
- normalizeParams(e) {
295
- return e.forEach((t) => {
296
- Object.keys(t).forEach((r) => {
297
- let i = t[r];
298
- if (i.length > 1)
299
- throw new Error(`Parameter "${r}" must have only a single value`);
300
- if (i = i[0], r === "client_max_window_bits") {
301
- if (i !== !0) {
302
- const n = +i;
303
- if (!Number.isInteger(n) || n < 8 || n > 15)
304
- throw new TypeError(
305
- `Invalid value for parameter "${r}": ${i}`
306
- );
307
- i = n;
308
- } else if (!this._isServer)
309
- throw new TypeError(
310
- `Invalid value for parameter "${r}": ${i}`
311
- );
312
- } else if (r === "server_max_window_bits") {
313
- const n = +i;
314
- if (!Number.isInteger(n) || n < 8 || n > 15)
315
- throw new TypeError(
316
- `Invalid value for parameter "${r}": ${i}`
317
- );
318
- i = n;
319
- } else if (r === "client_no_context_takeover" || r === "server_no_context_takeover") {
320
- if (i !== !0)
321
- throw new TypeError(
322
- `Invalid value for parameter "${r}": ${i}`
323
- );
324
- } else
325
- throw new Error(`Unknown parameter "${r}"`);
326
- t[r] = i;
327
- });
328
- }), e;
329
- }
330
- /**
331
- * Decompress data. Concurrency limited.
332
- *
333
- * @param {Buffer} data Compressed data
334
- * @param {Boolean} fin Specifies whether or not this is the last fragment
335
- * @param {Function} callback Callback
336
- * @public
337
- */
338
- decompress(e, t, r) {
339
- K.add((i) => {
340
- this._decompress(e, t, (n, o) => {
341
- i(), r(n, o);
342
- });
343
- });
344
- }
345
- /**
346
- * Compress data. Concurrency limited.
347
- *
348
- * @param {(Buffer|String)} data Data to compress
349
- * @param {Boolean} fin Specifies whether or not this is the last fragment
350
- * @param {Function} callback Callback
351
- * @public
352
- */
353
- compress(e, t, r) {
354
- K.add((i) => {
355
- this._compress(e, t, (n, o) => {
356
- i(), r(n, o);
357
- });
358
- });
359
- }
360
- /**
361
- * Decompress data.
362
- *
363
- * @param {Buffer} data Compressed data
364
- * @param {Boolean} fin Specifies whether or not this is the last fragment
365
- * @param {Function} callback Callback
366
- * @private
367
- */
368
- _decompress(e, t, r) {
369
- const i = this._isServer ? "client" : "server";
370
- if (!this._inflate) {
371
- const n = `${i}_max_window_bits`, o = typeof this.params[n] != "number" ? W.Z_DEFAULT_WINDOWBITS : this.params[n];
372
- this._inflate = W.createInflateRaw({
373
- ...this._options.zlibInflateOptions,
374
- windowBits: o
375
- }), this._inflate[se] = this, this._inflate[w] = 0, this._inflate[C] = [], this._inflate.on("error", Bt), this._inflate.on("data", st);
376
- }
377
- this._inflate[V] = r, this._inflate.write(e), t && this._inflate.write(Pt), this._inflate.flush(() => {
378
- const n = this._inflate[J];
379
- if (n) {
380
- this._inflate.close(), this._inflate = null, r(n);
381
- return;
382
- }
383
- const o = Te.concat(
384
- this._inflate[C],
385
- this._inflate[w]
386
- );
387
- this._inflate._readableState.endEmitted ? (this._inflate.close(), this._inflate = null) : (this._inflate[w] = 0, this._inflate[C] = [], t && this.params[`${i}_no_context_takeover`] && this._inflate.reset()), r(null, o);
388
- });
389
- }
390
- /**
391
- * Compress data.
392
- *
393
- * @param {(Buffer|String)} data Data to compress
394
- * @param {Boolean} fin Specifies whether or not this is the last fragment
395
- * @param {Function} callback Callback
396
- * @private
397
- */
398
- _compress(e, t, r) {
399
- const i = this._isServer ? "server" : "client";
400
- if (!this._deflate) {
401
- const n = `${i}_max_window_bits`, o = typeof this.params[n] != "number" ? W.Z_DEFAULT_WINDOWBITS : this.params[n];
402
- this._deflate = W.createDeflateRaw({
403
- ...this._options.zlibDeflateOptions,
404
- windowBits: o
405
- }), this._deflate[w] = 0, this._deflate[C] = [], this._deflate.on("data", Ut);
406
- }
407
- this._deflate[V] = r, this._deflate.write(e), this._deflate.flush(W.Z_SYNC_FLUSH, () => {
408
- if (!this._deflate)
409
- return;
410
- let n = Te.concat(
411
- this._deflate[C],
412
- this._deflate[w]
413
- );
414
- t && (n = new Nt(n.buffer, n.byteOffset, n.length - 4)), this._deflate[V] = null, this._deflate[w] = 0, this._deflate[C] = [], t && this.params[`${i}_no_context_takeover`] && this._deflate.reset(), r(null, n);
415
- });
416
- }
417
- };
418
- var oe = Rt;
419
- function Ut(s) {
420
- this[C].push(s), this[w] += s.length;
421
- }
422
- function st(s) {
423
- if (this[w] += s.length, this[se]._maxPayload < 1 || this[w] <= this[se]._maxPayload) {
424
- this[C].push(s);
425
- return;
426
- }
427
- this[J] = new RangeError("Max payload size exceeded"), this[J].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH", this[J][tt] = 1009, this.removeListener("data", st), this.reset();
428
- }
429
- function Bt(s) {
430
- this[se]._inflate = null, s[tt] = 1007, this[V](s);
431
- }
432
- var re = { exports: {} };
433
- const $t = {}, Mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
434
- __proto__: null,
435
- default: $t
436
- }, Symbol.toStringTag, { value: "Module" })), It = /* @__PURE__ */ gt(Mt);
437
- var Le;
438
- const { isUtf8: Ne } = S, Dt = [
439
- 0,
440
- 0,
441
- 0,
442
- 0,
443
- 0,
444
- 0,
445
- 0,
446
- 0,
447
- 0,
448
- 0,
449
- 0,
450
- 0,
451
- 0,
452
- 0,
453
- 0,
454
- 0,
455
- // 0 - 15
456
- 0,
457
- 0,
458
- 0,
459
- 0,
460
- 0,
461
- 0,
462
- 0,
463
- 0,
464
- 0,
465
- 0,
466
- 0,
467
- 0,
468
- 0,
469
- 0,
470
- 0,
471
- 0,
472
- // 16 - 31
473
- 0,
474
- 1,
475
- 0,
476
- 1,
477
- 1,
478
- 1,
479
- 1,
480
- 1,
481
- 0,
482
- 0,
483
- 1,
484
- 1,
485
- 0,
486
- 1,
487
- 1,
488
- 0,
489
- // 32 - 47
490
- 1,
491
- 1,
492
- 1,
493
- 1,
494
- 1,
495
- 1,
496
- 1,
497
- 1,
498
- 1,
499
- 1,
500
- 0,
501
- 0,
502
- 0,
503
- 0,
504
- 0,
505
- 0,
506
- // 48 - 63
507
- 0,
508
- 1,
509
- 1,
510
- 1,
511
- 1,
512
- 1,
513
- 1,
514
- 1,
515
- 1,
516
- 1,
517
- 1,
518
- 1,
519
- 1,
520
- 1,
521
- 1,
522
- 1,
523
- // 64 - 79
524
- 1,
525
- 1,
526
- 1,
527
- 1,
528
- 1,
529
- 1,
530
- 1,
531
- 1,
532
- 1,
533
- 1,
534
- 1,
535
- 0,
536
- 0,
537
- 0,
538
- 1,
539
- 1,
540
- // 80 - 95
541
- 1,
542
- 1,
543
- 1,
544
- 1,
545
- 1,
546
- 1,
547
- 1,
548
- 1,
549
- 1,
550
- 1,
551
- 1,
552
- 1,
553
- 1,
554
- 1,
555
- 1,
556
- 1,
557
- // 96 - 111
558
- 1,
559
- 1,
560
- 1,
561
- 1,
562
- 1,
563
- 1,
564
- 1,
565
- 1,
566
- 1,
567
- 1,
568
- 1,
569
- 0,
570
- 1,
571
- 0,
572
- 1,
573
- 0
574
- // 112 - 127
575
- ];
576
- function Wt(s) {
577
- return s >= 1e3 && s <= 1014 && s !== 1004 && s !== 1005 && s !== 1006 || s >= 3e3 && s <= 4999;
578
- }
579
- function be(s) {
580
- const e = s.length;
581
- let t = 0;
582
- for (; t < e; )
583
- if (!(s[t] & 128))
584
- t++;
585
- else if ((s[t] & 224) === 192) {
586
- if (t + 1 === e || (s[t + 1] & 192) !== 128 || (s[t] & 254) === 192)
587
- return !1;
588
- t += 2;
589
- } else if ((s[t] & 240) === 224) {
590
- if (t + 2 >= e || (s[t + 1] & 192) !== 128 || (s[t + 2] & 192) !== 128 || s[t] === 224 && (s[t + 1] & 224) === 128 || // Overlong
591
- s[t] === 237 && (s[t + 1] & 224) === 160)
592
- return !1;
593
- t += 3;
594
- } else if ((s[t] & 248) === 240) {
595
- if (t + 3 >= e || (s[t + 1] & 192) !== 128 || (s[t + 2] & 192) !== 128 || (s[t + 3] & 192) !== 128 || s[t] === 240 && (s[t + 1] & 240) === 128 || // Overlong
596
- s[t] === 244 && s[t + 1] > 143 || s[t] > 244)
597
- return !1;
598
- t += 4;
599
- } else
600
- return !1;
601
- return !0;
602
- }
603
- re.exports = {
604
- isValidStatusCode: Wt,
605
- isValidUTF8: be,
606
- tokenChars: Dt
607
- };
608
- if (Ne)
609
- Le = re.exports.isValidUTF8 = function(s) {
610
- return s.length < 24 ? be(s) : Ne(s);
611
- };
612
- else if (!process.env.WS_NO_UTF_8_VALIDATE)
613
- try {
614
- const s = It;
615
- Le = re.exports.isValidUTF8 = function(e) {
616
- return e.length < 32 ? be(e) : s(e);
617
- };
618
- } catch {
619
- }
620
- var ae = re.exports;
621
- const { Writable: At } = S, Pe = oe, {
622
- BINARY_TYPES: Ft,
623
- EMPTY_BUFFER: Re,
624
- kStatusCode: jt,
625
- kWebSocket: Gt
626
- } = U, { concat: de, toArrayBuffer: Vt, unmask: Ht } = ne, { isValidStatusCode: zt, isValidUTF8: Ue } = ae, X = Buffer[Symbol.species], A = 0, Be = 1, $e = 2, Me = 3, _e = 4, Yt = 5;
627
- let qt = class extends At {
628
- /**
629
- * Creates a Receiver instance.
630
- *
631
- * @param {Object} [options] Options object
632
- * @param {String} [options.binaryType=nodebuffer] The type for binary data
633
- * @param {Object} [options.extensions] An object containing the negotiated
634
- * extensions
635
- * @param {Boolean} [options.isServer=false] Specifies whether to operate in
636
- * client or server mode
637
- * @param {Number} [options.maxPayload=0] The maximum allowed message length
638
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
639
- * not to skip UTF-8 validation for text and close messages
640
- */
641
- constructor(e = {}) {
642
- super(), this._binaryType = e.binaryType || Ft[0], this._extensions = e.extensions || {}, this._isServer = !!e.isServer, this._maxPayload = e.maxPayload | 0, this._skipUTF8Validation = !!e.skipUTF8Validation, this[Gt] = void 0, this._bufferedBytes = 0, this._buffers = [], this._compressed = !1, this._payloadLength = 0, this._mask = void 0, this._fragmented = 0, this._masked = !1, this._fin = !1, this._opcode = 0, this._totalPayloadLength = 0, this._messageLength = 0, this._fragments = [], this._state = A, this._loop = !1;
643
- }
644
- /**
645
- * Implements `Writable.prototype._write()`.
646
- *
647
- * @param {Buffer} chunk The chunk of data to write
648
- * @param {String} encoding The character encoding of `chunk`
649
- * @param {Function} cb Callback
650
- * @private
651
- */
652
- _write(e, t, r) {
653
- if (this._opcode === 8 && this._state == A)
654
- return r();
655
- this._bufferedBytes += e.length, this._buffers.push(e), this.startLoop(r);
656
- }
657
- /**
658
- * Consumes `n` bytes from the buffered data.
659
- *
660
- * @param {Number} n The number of bytes to consume
661
- * @return {Buffer} The consumed bytes
662
- * @private
663
- */
664
- consume(e) {
665
- if (this._bufferedBytes -= e, e === this._buffers[0].length)
666
- return this._buffers.shift();
667
- if (e < this._buffers[0].length) {
668
- const r = this._buffers[0];
669
- return this._buffers[0] = new X(
670
- r.buffer,
671
- r.byteOffset + e,
672
- r.length - e
673
- ), new X(r.buffer, r.byteOffset, e);
674
- }
675
- const t = Buffer.allocUnsafe(e);
676
- do {
677
- const r = this._buffers[0], i = t.length - e;
678
- e >= r.length ? t.set(this._buffers.shift(), i) : (t.set(new Uint8Array(r.buffer, r.byteOffset, e), i), this._buffers[0] = new X(
679
- r.buffer,
680
- r.byteOffset + e,
681
- r.length - e
682
- )), e -= r.length;
683
- } while (e > 0);
684
- return t;
685
- }
686
- /**
687
- * Starts the parsing loop.
688
- *
689
- * @param {Function} cb Callback
690
- * @private
691
- */
692
- startLoop(e) {
693
- let t;
694
- this._loop = !0;
695
- do
696
- switch (this._state) {
697
- case A:
698
- t = this.getInfo();
699
- break;
700
- case Be:
701
- t = this.getPayloadLength16();
702
- break;
703
- case $e:
704
- t = this.getPayloadLength64();
705
- break;
706
- case Me:
707
- this.getMask();
708
- break;
709
- case _e:
710
- t = this.getData(e);
711
- break;
712
- default:
713
- this._loop = !1;
714
- return;
715
- }
716
- while (this._loop);
717
- e(t);
718
- }
719
- /**
720
- * Reads the first two bytes of a frame.
721
- *
722
- * @return {(RangeError|undefined)} A possible error
723
- * @private
724
- */
725
- getInfo() {
726
- if (this._bufferedBytes < 2) {
727
- this._loop = !1;
728
- return;
729
- }
730
- const e = this.consume(2);
731
- if (e[0] & 48)
732
- return this._loop = !1, g(
733
- RangeError,
734
- "RSV2 and RSV3 must be clear",
735
- !0,
736
- 1002,
737
- "WS_ERR_UNEXPECTED_RSV_2_3"
738
- );
739
- const t = (e[0] & 64) === 64;
740
- if (t && !this._extensions[Pe.extensionName])
741
- return this._loop = !1, g(
742
- RangeError,
743
- "RSV1 must be clear",
744
- !0,
745
- 1002,
746
- "WS_ERR_UNEXPECTED_RSV_1"
747
- );
748
- if (this._fin = (e[0] & 128) === 128, this._opcode = e[0] & 15, this._payloadLength = e[1] & 127, this._opcode === 0) {
749
- if (t)
750
- return this._loop = !1, g(
751
- RangeError,
752
- "RSV1 must be clear",
753
- !0,
754
- 1002,
755
- "WS_ERR_UNEXPECTED_RSV_1"
756
- );
757
- if (!this._fragmented)
758
- return this._loop = !1, g(
759
- RangeError,
760
- "invalid opcode 0",
761
- !0,
762
- 1002,
763
- "WS_ERR_INVALID_OPCODE"
764
- );
765
- this._opcode = this._fragmented;
766
- } else if (this._opcode === 1 || this._opcode === 2) {
767
- if (this._fragmented)
768
- return this._loop = !1, g(
769
- RangeError,
770
- `invalid opcode ${this._opcode}`,
771
- !0,
772
- 1002,
773
- "WS_ERR_INVALID_OPCODE"
774
- );
775
- this._compressed = t;
776
- } else if (this._opcode > 7 && this._opcode < 11) {
777
- if (!this._fin)
778
- return this._loop = !1, g(
779
- RangeError,
780
- "FIN must be set",
781
- !0,
782
- 1002,
783
- "WS_ERR_EXPECTED_FIN"
784
- );
785
- if (t)
786
- return this._loop = !1, g(
787
- RangeError,
788
- "RSV1 must be clear",
789
- !0,
790
- 1002,
791
- "WS_ERR_UNEXPECTED_RSV_1"
792
- );
793
- if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1)
794
- return this._loop = !1, g(
795
- RangeError,
796
- `invalid payload length ${this._payloadLength}`,
797
- !0,
798
- 1002,
799
- "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
800
- );
801
- } else
802
- return this._loop = !1, g(
803
- RangeError,
804
- `invalid opcode ${this._opcode}`,
805
- !0,
806
- 1002,
807
- "WS_ERR_INVALID_OPCODE"
808
- );
809
- if (!this._fin && !this._fragmented && (this._fragmented = this._opcode), this._masked = (e[1] & 128) === 128, this._isServer) {
810
- if (!this._masked)
811
- return this._loop = !1, g(
812
- RangeError,
813
- "MASK must be set",
814
- !0,
815
- 1002,
816
- "WS_ERR_EXPECTED_MASK"
817
- );
818
- } else if (this._masked)
819
- return this._loop = !1, g(
820
- RangeError,
821
- "MASK must be clear",
822
- !0,
823
- 1002,
824
- "WS_ERR_UNEXPECTED_MASK"
825
- );
826
- if (this._payloadLength === 126)
827
- this._state = Be;
828
- else if (this._payloadLength === 127)
829
- this._state = $e;
830
- else
831
- return this.haveLength();
832
- }
833
- /**
834
- * Gets extended payload length (7+16).
835
- *
836
- * @return {(RangeError|undefined)} A possible error
837
- * @private
838
- */
839
- getPayloadLength16() {
840
- if (this._bufferedBytes < 2) {
841
- this._loop = !1;
842
- return;
843
- }
844
- return this._payloadLength = this.consume(2).readUInt16BE(0), this.haveLength();
845
- }
846
- /**
847
- * Gets extended payload length (7+64).
848
- *
849
- * @return {(RangeError|undefined)} A possible error
850
- * @private
851
- */
852
- getPayloadLength64() {
853
- if (this._bufferedBytes < 8) {
854
- this._loop = !1;
855
- return;
856
- }
857
- const e = this.consume(8), t = e.readUInt32BE(0);
858
- return t > Math.pow(2, 53 - 32) - 1 ? (this._loop = !1, g(
859
- RangeError,
860
- "Unsupported WebSocket frame: payload length > 2^53 - 1",
861
- !1,
862
- 1009,
863
- "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
864
- )) : (this._payloadLength = t * Math.pow(2, 32) + e.readUInt32BE(4), this.haveLength());
865
- }
866
- /**
867
- * Payload length has been read.
868
- *
869
- * @return {(RangeError|undefined)} A possible error
870
- * @private
871
- */
872
- haveLength() {
873
- if (this._payloadLength && this._opcode < 8 && (this._totalPayloadLength += this._payloadLength, this._totalPayloadLength > this._maxPayload && this._maxPayload > 0))
874
- return this._loop = !1, g(
875
- RangeError,
876
- "Max payload size exceeded",
877
- !1,
878
- 1009,
879
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
880
- );
881
- this._masked ? this._state = Me : this._state = _e;
882
- }
883
- /**
884
- * Reads mask bytes.
885
- *
886
- * @private
887
- */
888
- getMask() {
889
- if (this._bufferedBytes < 4) {
890
- this._loop = !1;
891
- return;
892
- }
893
- this._mask = this.consume(4), this._state = _e;
894
- }
895
- /**
896
- * Reads data bytes.
897
- *
898
- * @param {Function} cb Callback
899
- * @return {(Error|RangeError|undefined)} A possible error
900
- * @private
901
- */
902
- getData(e) {
903
- let t = Re;
904
- if (this._payloadLength) {
905
- if (this._bufferedBytes < this._payloadLength) {
906
- this._loop = !1;
907
- return;
908
- }
909
- t = this.consume(this._payloadLength), this._masked && this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3] && Ht(t, this._mask);
910
- }
911
- if (this._opcode > 7)
912
- return this.controlMessage(t);
913
- if (this._compressed) {
914
- this._state = Yt, this.decompress(t, e);
915
- return;
916
- }
917
- return t.length && (this._messageLength = this._totalPayloadLength, this._fragments.push(t)), this.dataMessage();
918
- }
919
- /**
920
- * Decompresses data.
921
- *
922
- * @param {Buffer} data Compressed data
923
- * @param {Function} cb Callback
924
- * @private
925
- */
926
- decompress(e, t) {
927
- this._extensions[Pe.extensionName].decompress(e, this._fin, (i, n) => {
928
- if (i)
929
- return t(i);
930
- if (n.length) {
931
- if (this._messageLength += n.length, this._messageLength > this._maxPayload && this._maxPayload > 0)
932
- return t(
933
- g(
934
- RangeError,
935
- "Max payload size exceeded",
936
- !1,
937
- 1009,
938
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
939
- )
940
- );
941
- this._fragments.push(n);
942
- }
943
- const o = this.dataMessage();
944
- if (o)
945
- return t(o);
946
- this.startLoop(t);
947
- });
948
- }
949
- /**
950
- * Handles a data message.
951
- *
952
- * @return {(Error|undefined)} A possible error
953
- * @private
954
- */
955
- dataMessage() {
956
- if (this._fin) {
957
- const e = this._messageLength, t = this._fragments;
958
- if (this._totalPayloadLength = 0, this._messageLength = 0, this._fragmented = 0, this._fragments = [], this._opcode === 2) {
959
- let r;
960
- this._binaryType === "nodebuffer" ? r = de(t, e) : this._binaryType === "arraybuffer" ? r = Vt(de(t, e)) : r = t, this.emit("message", r, !0);
961
- } else {
962
- const r = de(t, e);
963
- if (!this._skipUTF8Validation && !Ue(r))
964
- return this._loop = !1, g(
965
- Error,
966
- "invalid UTF-8 sequence",
967
- !0,
968
- 1007,
969
- "WS_ERR_INVALID_UTF8"
970
- );
971
- this.emit("message", r, !1);
972
- }
973
- }
974
- this._state = A;
975
- }
976
- /**
977
- * Handles a control message.
978
- *
979
- * @param {Buffer} data Data to handle
980
- * @return {(Error|RangeError|undefined)} A possible error
981
- * @private
982
- */
983
- controlMessage(e) {
984
- if (this._opcode === 8)
985
- if (this._loop = !1, e.length === 0)
986
- this.emit("conclude", 1005, Re), this.end();
987
- else {
988
- const t = e.readUInt16BE(0);
989
- if (!zt(t))
990
- return g(
991
- RangeError,
992
- `invalid status code ${t}`,
993
- !0,
994
- 1002,
995
- "WS_ERR_INVALID_CLOSE_CODE"
996
- );
997
- const r = new X(
998
- e.buffer,
999
- e.byteOffset + 2,
1000
- e.length - 2
1001
- );
1002
- if (!this._skipUTF8Validation && !Ue(r))
1003
- return g(
1004
- Error,
1005
- "invalid UTF-8 sequence",
1006
- !0,
1007
- 1007,
1008
- "WS_ERR_INVALID_UTF8"
1009
- );
1010
- this.emit("conclude", t, r), this.end();
1011
- }
1012
- else
1013
- this._opcode === 9 ? this.emit("ping", e) : this.emit("pong", e);
1014
- this._state = A;
1015
- }
1016
- };
1017
- var rt = qt;
1018
- function g(s, e, t, r, i) {
1019
- const n = new s(
1020
- t ? `Invalid WebSocket frame: ${e}` : e
1021
- );
1022
- return Error.captureStackTrace(n, g), n.code = i, n[jt] = r, n;
1023
- }
1024
- const qs = /* @__PURE__ */ z(rt), { randomFillSync: Kt } = S, Ie = oe, { EMPTY_BUFFER: Xt } = U, { isValidStatusCode: Zt } = ae, { mask: De, toBuffer: M } = ne, x = Symbol("kByteLength"), Qt = Buffer.alloc(4);
1025
- let Jt = class P {
1026
- /**
1027
- * Creates a Sender instance.
1028
- *
1029
- * @param {(net.Socket|tls.Socket)} socket The connection socket
1030
- * @param {Object} [extensions] An object containing the negotiated extensions
1031
- * @param {Function} [generateMask] The function used to generate the masking
1032
- * key
1033
- */
1034
- constructor(e, t, r) {
1035
- this._extensions = t || {}, r && (this._generateMask = r, this._maskBuffer = Buffer.alloc(4)), this._socket = e, this._firstFragment = !0, this._compress = !1, this._bufferedBytes = 0, this._deflating = !1, this._queue = [];
1036
- }
1037
- /**
1038
- * Frames a piece of data according to the HyBi WebSocket protocol.
1039
- *
1040
- * @param {(Buffer|String)} data The data to frame
1041
- * @param {Object} options Options object
1042
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1043
- * FIN bit
1044
- * @param {Function} [options.generateMask] The function used to generate the
1045
- * masking key
1046
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1047
- * `data`
1048
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1049
- * key
1050
- * @param {Number} options.opcode The opcode
1051
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1052
- * modified
1053
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1054
- * RSV1 bit
1055
- * @return {(Buffer|String)[]} The framed data
1056
- * @public
1057
- */
1058
- static frame(e, t) {
1059
- let r, i = !1, n = 2, o = !1;
1060
- t.mask && (r = t.maskBuffer || Qt, t.generateMask ? t.generateMask(r) : Kt(r, 0, 4), o = (r[0] | r[1] | r[2] | r[3]) === 0, n = 6);
1061
- let l;
1062
- typeof e == "string" ? (!t.mask || o) && t[x] !== void 0 ? l = t[x] : (e = Buffer.from(e), l = e.length) : (l = e.length, i = t.mask && t.readOnly && !o);
1063
- let f = l;
1064
- l >= 65536 ? (n += 8, f = 127) : l > 125 && (n += 2, f = 126);
1065
- const a = Buffer.allocUnsafe(i ? l + n : n);
1066
- return a[0] = t.fin ? t.opcode | 128 : t.opcode, t.rsv1 && (a[0] |= 64), a[1] = f, f === 126 ? a.writeUInt16BE(l, 2) : f === 127 && (a[2] = a[3] = 0, a.writeUIntBE(l, 4, 6)), t.mask ? (a[1] |= 128, a[n - 4] = r[0], a[n - 3] = r[1], a[n - 2] = r[2], a[n - 1] = r[3], o ? [a, e] : i ? (De(e, r, a, n, l), [a]) : (De(e, r, e, 0, l), [a, e])) : [a, e];
1067
- }
1068
- /**
1069
- * Sends a close message to the other peer.
1070
- *
1071
- * @param {Number} [code] The status code component of the body
1072
- * @param {(String|Buffer)} [data] The message component of the body
1073
- * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1074
- * @param {Function} [cb] Callback
1075
- * @public
1076
- */
1077
- close(e, t, r, i) {
1078
- let n;
1079
- if (e === void 0)
1080
- n = Xt;
1081
- else {
1082
- if (typeof e != "number" || !Zt(e))
1083
- throw new TypeError("First argument must be a valid error code number");
1084
- if (t === void 0 || !t.length)
1085
- n = Buffer.allocUnsafe(2), n.writeUInt16BE(e, 0);
1086
- else {
1087
- const l = Buffer.byteLength(t);
1088
- if (l > 123)
1089
- throw new RangeError("The message must not be greater than 123 bytes");
1090
- n = Buffer.allocUnsafe(2 + l), n.writeUInt16BE(e, 0), typeof t == "string" ? n.write(t, 2) : n.set(t, 2);
1091
- }
1092
- }
1093
- const o = {
1094
- [x]: n.length,
1095
- fin: !0,
1096
- generateMask: this._generateMask,
1097
- mask: r,
1098
- maskBuffer: this._maskBuffer,
1099
- opcode: 8,
1100
- readOnly: !1,
1101
- rsv1: !1
1102
- };
1103
- this._deflating ? this.enqueue([this.dispatch, n, !1, o, i]) : this.sendFrame(P.frame(n, o), i);
1104
- }
1105
- /**
1106
- * Sends a ping message to the other peer.
1107
- *
1108
- * @param {*} data The message to send
1109
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1110
- * @param {Function} [cb] Callback
1111
- * @public
1112
- */
1113
- ping(e, t, r) {
1114
- let i, n;
1115
- if (typeof e == "string" ? (i = Buffer.byteLength(e), n = !1) : (e = M(e), i = e.length, n = M.readOnly), i > 125)
1116
- throw new RangeError("The data size must not be greater than 125 bytes");
1117
- const o = {
1118
- [x]: i,
1119
- fin: !0,
1120
- generateMask: this._generateMask,
1121
- mask: t,
1122
- maskBuffer: this._maskBuffer,
1123
- opcode: 9,
1124
- readOnly: n,
1125
- rsv1: !1
1126
- };
1127
- this._deflating ? this.enqueue([this.dispatch, e, !1, o, r]) : this.sendFrame(P.frame(e, o), r);
1128
- }
1129
- /**
1130
- * Sends a pong message to the other peer.
1131
- *
1132
- * @param {*} data The message to send
1133
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1134
- * @param {Function} [cb] Callback
1135
- * @public
1136
- */
1137
- pong(e, t, r) {
1138
- let i, n;
1139
- if (typeof e == "string" ? (i = Buffer.byteLength(e), n = !1) : (e = M(e), i = e.length, n = M.readOnly), i > 125)
1140
- throw new RangeError("The data size must not be greater than 125 bytes");
1141
- const o = {
1142
- [x]: i,
1143
- fin: !0,
1144
- generateMask: this._generateMask,
1145
- mask: t,
1146
- maskBuffer: this._maskBuffer,
1147
- opcode: 10,
1148
- readOnly: n,
1149
- rsv1: !1
1150
- };
1151
- this._deflating ? this.enqueue([this.dispatch, e, !1, o, r]) : this.sendFrame(P.frame(e, o), r);
1152
- }
1153
- /**
1154
- * Sends a data message to the other peer.
1155
- *
1156
- * @param {*} data The message to send
1157
- * @param {Object} options Options object
1158
- * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1159
- * or text
1160
- * @param {Boolean} [options.compress=false] Specifies whether or not to
1161
- * compress `data`
1162
- * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1163
- * last one
1164
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1165
- * `data`
1166
- * @param {Function} [cb] Callback
1167
- * @public
1168
- */
1169
- send(e, t, r) {
1170
- const i = this._extensions[Ie.extensionName];
1171
- let n = t.binary ? 2 : 1, o = t.compress, l, f;
1172
- if (typeof e == "string" ? (l = Buffer.byteLength(e), f = !1) : (e = M(e), l = e.length, f = M.readOnly), this._firstFragment ? (this._firstFragment = !1, o && i && i.params[i._isServer ? "server_no_context_takeover" : "client_no_context_takeover"] && (o = l >= i._threshold), this._compress = o) : (o = !1, n = 0), t.fin && (this._firstFragment = !0), i) {
1173
- const a = {
1174
- [x]: l,
1175
- fin: t.fin,
1176
- generateMask: this._generateMask,
1177
- mask: t.mask,
1178
- maskBuffer: this._maskBuffer,
1179
- opcode: n,
1180
- readOnly: f,
1181
- rsv1: o
1182
- };
1183
- this._deflating ? this.enqueue([this.dispatch, e, this._compress, a, r]) : this.dispatch(e, this._compress, a, r);
1184
- } else
1185
- this.sendFrame(
1186
- P.frame(e, {
1187
- [x]: l,
1188
- fin: t.fin,
1189
- generateMask: this._generateMask,
1190
- mask: t.mask,
1191
- maskBuffer: this._maskBuffer,
1192
- opcode: n,
1193
- readOnly: f,
1194
- rsv1: !1
1195
- }),
1196
- r
1197
- );
1198
- }
1199
- /**
1200
- * Dispatches a message.
1201
- *
1202
- * @param {(Buffer|String)} data The message to send
1203
- * @param {Boolean} [compress=false] Specifies whether or not to compress
1204
- * `data`
1205
- * @param {Object} options Options object
1206
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1207
- * FIN bit
1208
- * @param {Function} [options.generateMask] The function used to generate the
1209
- * masking key
1210
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1211
- * `data`
1212
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1213
- * key
1214
- * @param {Number} options.opcode The opcode
1215
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1216
- * modified
1217
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1218
- * RSV1 bit
1219
- * @param {Function} [cb] Callback
1220
- * @private
1221
- */
1222
- dispatch(e, t, r, i) {
1223
- if (!t) {
1224
- this.sendFrame(P.frame(e, r), i);
1225
- return;
1226
- }
1227
- const n = this._extensions[Ie.extensionName];
1228
- this._bufferedBytes += r[x], this._deflating = !0, n.compress(e, r.fin, (o, l) => {
1229
- if (this._socket.destroyed) {
1230
- const f = new Error(
1231
- "The socket was closed while data was being compressed"
1232
- );
1233
- typeof i == "function" && i(f);
1234
- for (let a = 0; a < this._queue.length; a++) {
1235
- const c = this._queue[a], h = c[c.length - 1];
1236
- typeof h == "function" && h(f);
1237
- }
1238
- return;
1239
- }
1240
- this._bufferedBytes -= r[x], this._deflating = !1, r.readOnly = !1, this.sendFrame(P.frame(l, r), i), this.dequeue();
1241
- });
1242
- }
1243
- /**
1244
- * Executes queued send operations.
1245
- *
1246
- * @private
1247
- */
1248
- dequeue() {
1249
- for (; !this._deflating && this._queue.length; ) {
1250
- const e = this._queue.shift();
1251
- this._bufferedBytes -= e[3][x], Reflect.apply(e[0], this, e.slice(1));
1252
- }
1253
- }
1254
- /**
1255
- * Enqueues a send operation.
1256
- *
1257
- * @param {Array} params Send operation parameters.
1258
- * @private
1259
- */
1260
- enqueue(e) {
1261
- this._bufferedBytes += e[3][x], this._queue.push(e);
1262
- }
1263
- /**
1264
- * Sends a frame.
1265
- *
1266
- * @param {Buffer[]} list The frame to send
1267
- * @param {Function} [cb] Callback
1268
- * @private
1269
- */
1270
- sendFrame(e, t) {
1271
- e.length === 2 ? (this._socket.cork(), this._socket.write(e[0]), this._socket.write(e[1], t), this._socket.uncork()) : this._socket.write(e[0], t);
1272
- }
1273
- };
1274
- var it = Jt;
1275
- const Ks = /* @__PURE__ */ z(it), { kForOnEventAttribute: F, kListener: pe } = U, We = Symbol("kCode"), Ae = Symbol("kData"), Fe = Symbol("kError"), je = Symbol("kMessage"), Ge = Symbol("kReason"), I = Symbol("kTarget"), Ve = Symbol("kType"), He = Symbol("kWasClean");
1276
- class B {
1277
- /**
1278
- * Create a new `Event`.
1279
- *
1280
- * @param {String} type The name of the event
1281
- * @throws {TypeError} If the `type` argument is not specified
1282
- */
1283
- constructor(e) {
1284
- this[I] = null, this[Ve] = e;
1285
- }
1286
- /**
1287
- * @type {*}
1288
- */
1289
- get target() {
1290
- return this[I];
1291
- }
1292
- /**
1293
- * @type {String}
1294
- */
1295
- get type() {
1296
- return this[Ve];
1297
- }
1298
- }
1299
- Object.defineProperty(B.prototype, "target", { enumerable: !0 });
1300
- Object.defineProperty(B.prototype, "type", { enumerable: !0 });
1301
- class Y extends B {
1302
- /**
1303
- * Create a new `CloseEvent`.
1304
- *
1305
- * @param {String} type The name of the event
1306
- * @param {Object} [options] A dictionary object that allows for setting
1307
- * attributes via object members of the same name
1308
- * @param {Number} [options.code=0] The status code explaining why the
1309
- * connection was closed
1310
- * @param {String} [options.reason=''] A human-readable string explaining why
1311
- * the connection was closed
1312
- * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1313
- * connection was cleanly closed
1314
- */
1315
- constructor(e, t = {}) {
1316
- super(e), this[We] = t.code === void 0 ? 0 : t.code, this[Ge] = t.reason === void 0 ? "" : t.reason, this[He] = t.wasClean === void 0 ? !1 : t.wasClean;
1317
- }
1318
- /**
1319
- * @type {Number}
1320
- */
1321
- get code() {
1322
- return this[We];
1323
- }
1324
- /**
1325
- * @type {String}
1326
- */
1327
- get reason() {
1328
- return this[Ge];
1329
- }
1330
- /**
1331
- * @type {Boolean}
1332
- */
1333
- get wasClean() {
1334
- return this[He];
1335
- }
1336
- }
1337
- Object.defineProperty(Y.prototype, "code", { enumerable: !0 });
1338
- Object.defineProperty(Y.prototype, "reason", { enumerable: !0 });
1339
- Object.defineProperty(Y.prototype, "wasClean", { enumerable: !0 });
1340
- class le extends B {
1341
- /**
1342
- * Create a new `ErrorEvent`.
1343
- *
1344
- * @param {String} type The name of the event
1345
- * @param {Object} [options] A dictionary object that allows for setting
1346
- * attributes via object members of the same name
1347
- * @param {*} [options.error=null] The error that generated this event
1348
- * @param {String} [options.message=''] The error message
1349
- */
1350
- constructor(e, t = {}) {
1351
- super(e), this[Fe] = t.error === void 0 ? null : t.error, this[je] = t.message === void 0 ? "" : t.message;
1352
- }
1353
- /**
1354
- * @type {*}
1355
- */
1356
- get error() {
1357
- return this[Fe];
1358
- }
1359
- /**
1360
- * @type {String}
1361
- */
1362
- get message() {
1363
- return this[je];
1364
- }
1365
- }
1366
- Object.defineProperty(le.prototype, "error", { enumerable: !0 });
1367
- Object.defineProperty(le.prototype, "message", { enumerable: !0 });
1368
- class xe extends B {
1369
- /**
1370
- * Create a new `MessageEvent`.
1371
- *
1372
- * @param {String} type The name of the event
1373
- * @param {Object} [options] A dictionary object that allows for setting
1374
- * attributes via object members of the same name
1375
- * @param {*} [options.data=null] The message content
1376
- */
1377
- constructor(e, t = {}) {
1378
- super(e), this[Ae] = t.data === void 0 ? null : t.data;
1379
- }
1380
- /**
1381
- * @type {*}
1382
- */
1383
- get data() {
1384
- return this[Ae];
1385
- }
1386
- }
1387
- Object.defineProperty(xe.prototype, "data", { enumerable: !0 });
1388
- const es = {
1389
- /**
1390
- * Register an event listener.
1391
- *
1392
- * @param {String} type A string representing the event type to listen for
1393
- * @param {(Function|Object)} handler The listener to add
1394
- * @param {Object} [options] An options object specifies characteristics about
1395
- * the event listener
1396
- * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1397
- * listener should be invoked at most once after being added. If `true`,
1398
- * the listener would be automatically removed when invoked.
1399
- * @public
1400
- */
1401
- addEventListener(s, e, t = {}) {
1402
- for (const i of this.listeners(s))
1403
- if (!t[F] && i[pe] === e && !i[F])
1404
- return;
1405
- let r;
1406
- if (s === "message")
1407
- r = function(n, o) {
1408
- const l = new xe("message", {
1409
- data: o ? n : n.toString()
1410
- });
1411
- l[I] = this, Z(e, this, l);
1412
- };
1413
- else if (s === "close")
1414
- r = function(n, o) {
1415
- const l = new Y("close", {
1416
- code: n,
1417
- reason: o.toString(),
1418
- wasClean: this._closeFrameReceived && this._closeFrameSent
1419
- });
1420
- l[I] = this, Z(e, this, l);
1421
- };
1422
- else if (s === "error")
1423
- r = function(n) {
1424
- const o = new le("error", {
1425
- error: n,
1426
- message: n.message
1427
- });
1428
- o[I] = this, Z(e, this, o);
1429
- };
1430
- else if (s === "open")
1431
- r = function() {
1432
- const n = new B("open");
1433
- n[I] = this, Z(e, this, n);
1434
- };
1435
- else
1436
- return;
1437
- r[F] = !!t[F], r[pe] = e, t.once ? this.once(s, r) : this.on(s, r);
1438
- },
1439
- /**
1440
- * Remove an event listener.
1441
- *
1442
- * @param {String} type A string representing the event type to remove
1443
- * @param {(Function|Object)} handler The listener to remove
1444
- * @public
1445
- */
1446
- removeEventListener(s, e) {
1447
- for (const t of this.listeners(s))
1448
- if (t[pe] === e && !t[F]) {
1449
- this.removeListener(s, t);
1450
- break;
1451
- }
1452
- }
1453
- };
1454
- var ts = {
1455
- CloseEvent: Y,
1456
- ErrorEvent: le,
1457
- Event: B,
1458
- EventTarget: es,
1459
- MessageEvent: xe
1460
- };
1461
- function Z(s, e, t) {
1462
- typeof s == "object" && s.handleEvent ? s.handleEvent.call(s, t) : s.call(e, t);
1463
- }
1464
- const { tokenChars: j } = ae;
1465
- function k(s, e, t) {
1466
- s[e] === void 0 ? s[e] = [t] : s[e].push(t);
1467
- }
1468
- function ss(s) {
1469
- const e = /* @__PURE__ */ Object.create(null);
1470
- let t = /* @__PURE__ */ Object.create(null), r = !1, i = !1, n = !1, o, l, f = -1, a = -1, c = -1, h = 0;
1471
- for (; h < s.length; h++)
1472
- if (a = s.charCodeAt(h), o === void 0)
1473
- if (c === -1 && j[a] === 1)
1474
- f === -1 && (f = h);
1475
- else if (h !== 0 && (a === 32 || a === 9))
1476
- c === -1 && f !== -1 && (c = h);
1477
- else if (a === 59 || a === 44) {
1478
- if (f === -1)
1479
- throw new SyntaxError(`Unexpected character at index ${h}`);
1480
- c === -1 && (c = h);
1481
- const v = s.slice(f, c);
1482
- a === 44 ? (k(e, v, t), t = /* @__PURE__ */ Object.create(null)) : o = v, f = c = -1;
1483
- } else
1484
- throw new SyntaxError(`Unexpected character at index ${h}`);
1485
- else if (l === void 0)
1486
- if (c === -1 && j[a] === 1)
1487
- f === -1 && (f = h);
1488
- else if (a === 32 || a === 9)
1489
- c === -1 && f !== -1 && (c = h);
1490
- else if (a === 59 || a === 44) {
1491
- if (f === -1)
1492
- throw new SyntaxError(`Unexpected character at index ${h}`);
1493
- c === -1 && (c = h), k(t, s.slice(f, c), !0), a === 44 && (k(e, o, t), t = /* @__PURE__ */ Object.create(null), o = void 0), f = c = -1;
1494
- } else if (a === 61 && f !== -1 && c === -1)
1495
- l = s.slice(f, h), f = c = -1;
1496
- else
1497
- throw new SyntaxError(`Unexpected character at index ${h}`);
1498
- else if (i) {
1499
- if (j[a] !== 1)
1500
- throw new SyntaxError(`Unexpected character at index ${h}`);
1501
- f === -1 ? f = h : r || (r = !0), i = !1;
1502
- } else if (n)
1503
- if (j[a] === 1)
1504
- f === -1 && (f = h);
1505
- else if (a === 34 && f !== -1)
1506
- n = !1, c = h;
1507
- else if (a === 92)
1508
- i = !0;
1509
- else
1510
- throw new SyntaxError(`Unexpected character at index ${h}`);
1511
- else if (a === 34 && s.charCodeAt(h - 1) === 61)
1512
- n = !0;
1513
- else if (c === -1 && j[a] === 1)
1514
- f === -1 && (f = h);
1515
- else if (f !== -1 && (a === 32 || a === 9))
1516
- c === -1 && (c = h);
1517
- else if (a === 59 || a === 44) {
1518
- if (f === -1)
1519
- throw new SyntaxError(`Unexpected character at index ${h}`);
1520
- c === -1 && (c = h);
1521
- let v = s.slice(f, c);
1522
- r && (v = v.replace(/\\/g, ""), r = !1), k(t, l, v), a === 44 && (k(e, o, t), t = /* @__PURE__ */ Object.create(null), o = void 0), l = void 0, f = c = -1;
1523
- } else
1524
- throw new SyntaxError(`Unexpected character at index ${h}`);
1525
- if (f === -1 || n || a === 32 || a === 9)
1526
- throw new SyntaxError("Unexpected end of input");
1527
- c === -1 && (c = h);
1528
- const p = s.slice(f, c);
1529
- return o === void 0 ? k(e, p, t) : (l === void 0 ? k(t, p, !0) : r ? k(t, l, p.replace(/\\/g, "")) : k(t, l, p), k(e, o, t)), e;
1530
- }
1531
- function rs(s) {
1532
- return Object.keys(s).map((e) => {
1533
- let t = s[e];
1534
- return Array.isArray(t) || (t = [t]), t.map((r) => [e].concat(
1535
- Object.keys(r).map((i) => {
1536
- let n = r[i];
1537
- return Array.isArray(n) || (n = [n]), n.map((o) => o === !0 ? i : `${i}=${o}`).join("; ");
1538
- })
1539
- ).join("; ")).join(", ");
1540
- }).join(", ");
1541
- }
1542
- var nt = { format: rs, parse: ss };
1543
- const is = S, ns = S, os = S, ot = S, as = S, { randomBytes: ls, createHash: fs } = S, { URL: me } = S, T = oe, hs = rt, cs = it, {
1544
- BINARY_TYPES: ze,
1545
- EMPTY_BUFFER: Q,
1546
- GUID: us,
1547
- kForOnEventAttribute: ge,
1548
- kListener: ds,
1549
- kStatusCode: _s,
1550
- kWebSocket: y,
1551
- NOOP: at
1552
- } = U, {
1553
- EventTarget: { addEventListener: ps, removeEventListener: ms }
1554
- } = ts, { format: gs, parse: ys } = nt, { toBuffer: vs } = ne, Ss = 30 * 1e3, lt = Symbol("kAborted"), ye = [8, 13], O = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"], Es = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
1555
- let m = class d extends is {
1556
- /**
1557
- * Create a new `WebSocket`.
1558
- *
1559
- * @param {(String|URL)} address The URL to which to connect
1560
- * @param {(String|String[])} [protocols] The subprotocols
1561
- * @param {Object} [options] Connection options
1562
- */
1563
- constructor(e, t, r) {
1564
- super(), this._binaryType = ze[0], this._closeCode = 1006, this._closeFrameReceived = !1, this._closeFrameSent = !1, this._closeMessage = Q, this._closeTimer = null, this._extensions = {}, this._paused = !1, this._protocol = "", this._readyState = d.CONNECTING, this._receiver = null, this._sender = null, this._socket = null, e !== null ? (this._bufferedAmount = 0, this._isServer = !1, this._redirects = 0, t === void 0 ? t = [] : Array.isArray(t) || (typeof t == "object" && t !== null ? (r = t, t = []) : t = [t]), ht(this, e, t, r)) : this._isServer = !0;
1565
- }
1566
- /**
1567
- * This deviates from the WHATWG interface since ws doesn't support the
1568
- * required default "blob" type (instead we define a custom "nodebuffer"
1569
- * type).
1570
- *
1571
- * @type {String}
1572
- */
1573
- get binaryType() {
1574
- return this._binaryType;
1575
- }
1576
- set binaryType(e) {
1577
- ze.includes(e) && (this._binaryType = e, this._receiver && (this._receiver._binaryType = e));
1578
- }
1579
- /**
1580
- * @type {Number}
1581
- */
1582
- get bufferedAmount() {
1583
- return this._socket ? this._socket._writableState.length + this._sender._bufferedBytes : this._bufferedAmount;
1584
- }
1585
- /**
1586
- * @type {String}
1587
- */
1588
- get extensions() {
1589
- return Object.keys(this._extensions).join();
1590
- }
1591
- /**
1592
- * @type {Boolean}
1593
- */
1594
- get isPaused() {
1595
- return this._paused;
1596
- }
1597
- /**
1598
- * @type {Function}
1599
- */
1600
- /* istanbul ignore next */
1601
- get onclose() {
1602
- return null;
1603
- }
1604
- /**
1605
- * @type {Function}
1606
- */
1607
- /* istanbul ignore next */
1608
- get onerror() {
1609
- return null;
1610
- }
1611
- /**
1612
- * @type {Function}
1613
- */
1614
- /* istanbul ignore next */
1615
- get onopen() {
1616
- return null;
1617
- }
1618
- /**
1619
- * @type {Function}
1620
- */
1621
- /* istanbul ignore next */
1622
- get onmessage() {
1623
- return null;
1624
- }
1625
- /**
1626
- * @type {String}
1627
- */
1628
- get protocol() {
1629
- return this._protocol;
1630
- }
1631
- /**
1632
- * @type {Number}
1633
- */
1634
- get readyState() {
1635
- return this._readyState;
1636
- }
1637
- /**
1638
- * @type {String}
1639
- */
1640
- get url() {
1641
- return this._url;
1642
- }
1643
- /**
1644
- * Set up the socket and the internal resources.
1645
- *
1646
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
1647
- * server and client
1648
- * @param {Buffer} head The first packet of the upgraded stream
1649
- * @param {Object} options Options object
1650
- * @param {Function} [options.generateMask] The function used to generate the
1651
- * masking key
1652
- * @param {Number} [options.maxPayload=0] The maximum allowed message size
1653
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
1654
- * not to skip UTF-8 validation for text and close messages
1655
- * @private
1656
- */
1657
- setSocket(e, t, r) {
1658
- const i = new hs({
1659
- binaryType: this.binaryType,
1660
- extensions: this._extensions,
1661
- isServer: this._isServer,
1662
- maxPayload: r.maxPayload,
1663
- skipUTF8Validation: r.skipUTF8Validation
1664
- });
1665
- this._sender = new cs(e, this._extensions, r.generateMask), this._receiver = i, this._socket = e, i[y] = this, e[y] = this, i.on("conclude", ks), i.on("drain", ws), i.on("error", Os), i.on("message", Cs), i.on("ping", Ts), i.on("pong", Ls), e.setTimeout(0), e.setNoDelay(), t.length > 0 && e.unshift(t), e.on("close", ut), e.on("data", fe), e.on("end", dt), e.on("error", _t), this._readyState = d.OPEN, this.emit("open");
1666
- }
1667
- /**
1668
- * Emit the `'close'` event.
1669
- *
1670
- * @private
1671
- */
1672
- emitClose() {
1673
- if (!this._socket) {
1674
- this._readyState = d.CLOSED, this.emit("close", this._closeCode, this._closeMessage);
1675
- return;
1676
- }
1677
- this._extensions[T.extensionName] && this._extensions[T.extensionName].cleanup(), this._receiver.removeAllListeners(), this._readyState = d.CLOSED, this.emit("close", this._closeCode, this._closeMessage);
1678
- }
1679
- /**
1680
- * Start a closing handshake.
1681
- *
1682
- * +----------+ +-----------+ +----------+
1683
- * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
1684
- * | +----------+ +-----------+ +----------+ |
1685
- * +----------+ +-----------+ |
1686
- * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
1687
- * +----------+ +-----------+ |
1688
- * | | | +---+ |
1689
- * +------------------------+-->|fin| - - - -
1690
- * | +---+ | +---+
1691
- * - - - - -|fin|<---------------------+
1692
- * +---+
1693
- *
1694
- * @param {Number} [code] Status code explaining why the connection is closing
1695
- * @param {(String|Buffer)} [data] The reason why the connection is
1696
- * closing
1697
- * @public
1698
- */
1699
- close(e, t) {
1700
- if (this.readyState !== d.CLOSED) {
1701
- if (this.readyState === d.CONNECTING) {
1702
- const r = "WebSocket was closed before the connection was established";
1703
- b(this, this._req, r);
1704
- return;
1705
- }
1706
- if (this.readyState === d.CLOSING) {
1707
- this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end();
1708
- return;
1709
- }
1710
- this._readyState = d.CLOSING, this._sender.close(e, t, !this._isServer, (r) => {
1711
- r || (this._closeFrameSent = !0, (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end());
1712
- }), this._closeTimer = setTimeout(
1713
- this._socket.destroy.bind(this._socket),
1714
- Ss
1715
- );
1716
- }
1717
- }
1718
- /**
1719
- * Pause the socket.
1720
- *
1721
- * @public
1722
- */
1723
- pause() {
1724
- this.readyState === d.CONNECTING || this.readyState === d.CLOSED || (this._paused = !0, this._socket.pause());
1725
- }
1726
- /**
1727
- * Send a ping.
1728
- *
1729
- * @param {*} [data] The data to send
1730
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
1731
- * @param {Function} [cb] Callback which is executed when the ping is sent
1732
- * @public
1733
- */
1734
- ping(e, t, r) {
1735
- if (this.readyState === d.CONNECTING)
1736
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1737
- if (typeof e == "function" ? (r = e, e = t = void 0) : typeof t == "function" && (r = t, t = void 0), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1738
- ve(this, e, r);
1739
- return;
1740
- }
1741
- t === void 0 && (t = !this._isServer), this._sender.ping(e || Q, t, r);
1742
- }
1743
- /**
1744
- * Send a pong.
1745
- *
1746
- * @param {*} [data] The data to send
1747
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
1748
- * @param {Function} [cb] Callback which is executed when the pong is sent
1749
- * @public
1750
- */
1751
- pong(e, t, r) {
1752
- if (this.readyState === d.CONNECTING)
1753
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1754
- if (typeof e == "function" ? (r = e, e = t = void 0) : typeof t == "function" && (r = t, t = void 0), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1755
- ve(this, e, r);
1756
- return;
1757
- }
1758
- t === void 0 && (t = !this._isServer), this._sender.pong(e || Q, t, r);
1759
- }
1760
- /**
1761
- * Resume the socket.
1762
- *
1763
- * @public
1764
- */
1765
- resume() {
1766
- this.readyState === d.CONNECTING || this.readyState === d.CLOSED || (this._paused = !1, this._receiver._writableState.needDrain || this._socket.resume());
1767
- }
1768
- /**
1769
- * Send a data message.
1770
- *
1771
- * @param {*} data The message to send
1772
- * @param {Object} [options] Options object
1773
- * @param {Boolean} [options.binary] Specifies whether `data` is binary or
1774
- * text
1775
- * @param {Boolean} [options.compress] Specifies whether or not to compress
1776
- * `data`
1777
- * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
1778
- * last one
1779
- * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
1780
- * @param {Function} [cb] Callback which is executed when data is written out
1781
- * @public
1782
- */
1783
- send(e, t, r) {
1784
- if (this.readyState === d.CONNECTING)
1785
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1786
- if (typeof t == "function" && (r = t, t = {}), typeof e == "number" && (e = e.toString()), this.readyState !== d.OPEN) {
1787
- ve(this, e, r);
1788
- return;
1789
- }
1790
- const i = {
1791
- binary: typeof e != "string",
1792
- mask: !this._isServer,
1793
- compress: !0,
1794
- fin: !0,
1795
- ...t
1796
- };
1797
- this._extensions[T.extensionName] || (i.compress = !1), this._sender.send(e || Q, i, r);
1798
- }
1799
- /**
1800
- * Forcibly close the connection.
1801
- *
1802
- * @public
1803
- */
1804
- terminate() {
1805
- if (this.readyState !== d.CLOSED) {
1806
- if (this.readyState === d.CONNECTING) {
1807
- const e = "WebSocket was closed before the connection was established";
1808
- b(this, this._req, e);
1809
- return;
1810
- }
1811
- this._socket && (this._readyState = d.CLOSING, this._socket.destroy());
1812
- }
1813
- }
1814
- };
1815
- Object.defineProperty(m, "CONNECTING", {
1816
- enumerable: !0,
1817
- value: O.indexOf("CONNECTING")
1818
- });
1819
- Object.defineProperty(m.prototype, "CONNECTING", {
1820
- enumerable: !0,
1821
- value: O.indexOf("CONNECTING")
1822
- });
1823
- Object.defineProperty(m, "OPEN", {
1824
- enumerable: !0,
1825
- value: O.indexOf("OPEN")
1826
- });
1827
- Object.defineProperty(m.prototype, "OPEN", {
1828
- enumerable: !0,
1829
- value: O.indexOf("OPEN")
1830
- });
1831
- Object.defineProperty(m, "CLOSING", {
1832
- enumerable: !0,
1833
- value: O.indexOf("CLOSING")
1834
- });
1835
- Object.defineProperty(m.prototype, "CLOSING", {
1836
- enumerable: !0,
1837
- value: O.indexOf("CLOSING")
1838
- });
1839
- Object.defineProperty(m, "CLOSED", {
1840
- enumerable: !0,
1841
- value: O.indexOf("CLOSED")
1842
- });
1843
- Object.defineProperty(m.prototype, "CLOSED", {
1844
- enumerable: !0,
1845
- value: O.indexOf("CLOSED")
1846
- });
1847
- [
1848
- "binaryType",
1849
- "bufferedAmount",
1850
- "extensions",
1851
- "isPaused",
1852
- "protocol",
1853
- "readyState",
1854
- "url"
1855
- ].forEach((s) => {
1856
- Object.defineProperty(m.prototype, s, { enumerable: !0 });
1857
- });
1858
- ["open", "error", "close", "message"].forEach((s) => {
1859
- Object.defineProperty(m.prototype, `on${s}`, {
1860
- enumerable: !0,
1861
- get() {
1862
- for (const e of this.listeners(s))
1863
- if (e[ge])
1864
- return e[ds];
1865
- return null;
1866
- },
1867
- set(e) {
1868
- for (const t of this.listeners(s))
1869
- if (t[ge]) {
1870
- this.removeListener(s, t);
1871
- break;
1872
- }
1873
- typeof e == "function" && this.addEventListener(s, e, {
1874
- [ge]: !0
1875
- });
1876
- }
1877
- });
1878
- });
1879
- m.prototype.addEventListener = ps;
1880
- m.prototype.removeEventListener = ms;
1881
- var ft = m;
1882
- function ht(s, e, t, r) {
1883
- const i = {
1884
- protocolVersion: ye[1],
1885
- maxPayload: 104857600,
1886
- skipUTF8Validation: !1,
1887
- perMessageDeflate: !0,
1888
- followRedirects: !1,
1889
- maxRedirects: 10,
1890
- ...r,
1891
- createConnection: void 0,
1892
- socketPath: void 0,
1893
- hostname: void 0,
1894
- protocol: void 0,
1895
- timeout: void 0,
1896
- method: "GET",
1897
- host: void 0,
1898
- path: void 0,
1899
- port: void 0
1900
- };
1901
- if (!ye.includes(i.protocolVersion))
1902
- throw new RangeError(
1903
- `Unsupported protocol version: ${i.protocolVersion} (supported versions: ${ye.join(", ")})`
1904
- );
1905
- let n;
1906
- if (e instanceof me)
1907
- n = e, s._url = e.href;
1908
- else {
1909
- try {
1910
- n = new me(e);
1911
- } catch {
1912
- throw new SyntaxError(`Invalid URL: ${e}`);
1913
- }
1914
- s._url = e;
1915
- }
1916
- const o = n.protocol === "wss:", l = n.protocol === "ws+unix:";
1917
- let f;
1918
- if (n.protocol !== "ws:" && !o && !l ? f = `The URL's protocol must be one of "ws:", "wss:", or "ws+unix:"` : l && !n.pathname ? f = "The URL's pathname is empty" : n.hash && (f = "The URL contains a fragment identifier"), f) {
1919
- const u = new SyntaxError(f);
1920
- if (s._redirects === 0)
1921
- throw u;
1922
- ee(s, u);
1923
- return;
1924
- }
1925
- const a = o ? 443 : 80, c = ls(16).toString("base64"), h = o ? ns.request : os.request, p = /* @__PURE__ */ new Set();
1926
- let v;
1927
- if (i.createConnection = o ? xs : bs, i.defaultPort = i.defaultPort || a, i.port = n.port || a, i.host = n.hostname.startsWith("[") ? n.hostname.slice(1, -1) : n.hostname, i.headers = {
1928
- ...i.headers,
1929
- "Sec-WebSocket-Version": i.protocolVersion,
1930
- "Sec-WebSocket-Key": c,
1931
- Connection: "Upgrade",
1932
- Upgrade: "websocket"
1933
- }, i.path = n.pathname + n.search, i.timeout = i.handshakeTimeout, i.perMessageDeflate && (v = new T(
1934
- i.perMessageDeflate !== !0 ? i.perMessageDeflate : {},
1935
- !1,
1936
- i.maxPayload
1937
- ), i.headers["Sec-WebSocket-Extensions"] = gs({
1938
- [T.extensionName]: v.offer()
1939
- })), t.length) {
1940
- for (const u of t) {
1941
- if (typeof u != "string" || !Es.test(u) || p.has(u))
1942
- throw new SyntaxError(
1943
- "An invalid or duplicated subprotocol was specified"
1944
- );
1945
- p.add(u);
1946
- }
1947
- i.headers["Sec-WebSocket-Protocol"] = t.join(",");
1948
- }
1949
- if (i.origin && (i.protocolVersion < 13 ? i.headers["Sec-WebSocket-Origin"] = i.origin : i.headers.Origin = i.origin), (n.username || n.password) && (i.auth = `${n.username}:${n.password}`), l) {
1950
- const u = i.path.split(":");
1951
- i.socketPath = u[0], i.path = u[1];
1952
- }
1953
- let _;
1954
- if (i.followRedirects) {
1955
- if (s._redirects === 0) {
1956
- s._originalIpc = l, s._originalSecure = o, s._originalHostOrSocketPath = l ? i.socketPath : n.host;
1957
- const u = r && r.headers;
1958
- if (r = { ...r, headers: {} }, u)
1959
- for (const [E, $] of Object.entries(u))
1960
- r.headers[E.toLowerCase()] = $;
1961
- } else if (s.listenerCount("redirect") === 0) {
1962
- const u = l ? s._originalIpc ? i.socketPath === s._originalHostOrSocketPath : !1 : s._originalIpc ? !1 : n.host === s._originalHostOrSocketPath;
1963
- (!u || s._originalSecure && !o) && (delete i.headers.authorization, delete i.headers.cookie, u || delete i.headers.host, i.auth = void 0);
1964
- }
1965
- i.auth && !r.headers.authorization && (r.headers.authorization = "Basic " + Buffer.from(i.auth).toString("base64")), _ = s._req = h(i), s._redirects && s.emit("redirect", s.url, _);
1966
- } else
1967
- _ = s._req = h(i);
1968
- i.timeout && _.on("timeout", () => {
1969
- b(s, _, "Opening handshake has timed out");
1970
- }), _.on("error", (u) => {
1971
- _ === null || _[lt] || (_ = s._req = null, ee(s, u));
1972
- }), _.on("response", (u) => {
1973
- const E = u.headers.location, $ = u.statusCode;
1974
- if (E && i.followRedirects && $ >= 300 && $ < 400) {
1975
- if (++s._redirects > i.maxRedirects) {
1976
- b(s, _, "Maximum redirects exceeded");
1977
- return;
1978
- }
1979
- _.abort();
1980
- let q;
1981
- try {
1982
- q = new me(E, e);
1983
- } catch {
1984
- const L = new SyntaxError(`Invalid URL: ${E}`);
1985
- ee(s, L);
1986
- return;
1987
- }
1988
- ht(s, q, t, r);
1989
- } else
1990
- s.emit("unexpected-response", _, u) || b(
1991
- s,
1992
- _,
1993
- `Unexpected server response: ${u.statusCode}`
1994
- );
1995
- }), _.on("upgrade", (u, E, $) => {
1996
- if (s.emit("upgrade", u), s.readyState !== m.CONNECTING)
1997
- return;
1998
- if (_ = s._req = null, u.headers.upgrade.toLowerCase() !== "websocket") {
1999
- b(s, E, "Invalid Upgrade header");
2000
- return;
2001
- }
2002
- const q = fs("sha1").update(c + us).digest("base64");
2003
- if (u.headers["sec-websocket-accept"] !== q) {
2004
- b(s, E, "Invalid Sec-WebSocket-Accept header");
2005
- return;
2006
- }
2007
- const D = u.headers["sec-websocket-protocol"];
2008
- let L;
2009
- if (D !== void 0 ? p.size ? p.has(D) || (L = "Server sent an invalid subprotocol") : L = "Server sent a subprotocol but none was requested" : p.size && (L = "Server sent no subprotocol"), L) {
2010
- b(s, E, L);
2011
- return;
2012
- }
2013
- D && (s._protocol = D);
2014
- const ke = u.headers["sec-websocket-extensions"];
2015
- if (ke !== void 0) {
2016
- if (!v) {
2017
- b(s, E, "Server sent a Sec-WebSocket-Extensions header but no extension was requested");
2018
- return;
2019
- }
2020
- let he;
2021
- try {
2022
- he = ys(ke);
2023
- } catch {
2024
- b(s, E, "Invalid Sec-WebSocket-Extensions header");
2025
- return;
2026
- }
2027
- const we = Object.keys(he);
2028
- if (we.length !== 1 || we[0] !== T.extensionName) {
2029
- b(s, E, "Server indicated an extension that was not requested");
2030
- return;
2031
- }
2032
- try {
2033
- v.accept(he[T.extensionName]);
2034
- } catch {
2035
- b(s, E, "Invalid Sec-WebSocket-Extensions header");
2036
- return;
2037
- }
2038
- s._extensions[T.extensionName] = v;
2039
- }
2040
- s.setSocket(E, $, {
2041
- generateMask: i.generateMask,
2042
- maxPayload: i.maxPayload,
2043
- skipUTF8Validation: i.skipUTF8Validation
2044
- });
2045
- }), i.finishRequest ? i.finishRequest(_, s) : _.end();
2046
- }
2047
- function ee(s, e) {
2048
- s._readyState = m.CLOSING, s.emit("error", e), s.emitClose();
2049
- }
2050
- function bs(s) {
2051
- return s.path = s.socketPath, ot.connect(s);
2052
- }
2053
- function xs(s) {
2054
- return s.path = void 0, !s.servername && s.servername !== "" && (s.servername = ot.isIP(s.host) ? "" : s.host), as.connect(s);
2055
- }
2056
- function b(s, e, t) {
2057
- s._readyState = m.CLOSING;
2058
- const r = new Error(t);
2059
- Error.captureStackTrace(r, b), e.setHeader ? (e[lt] = !0, e.abort(), e.socket && !e.socket.destroyed && e.socket.destroy(), process.nextTick(ee, s, r)) : (e.destroy(r), e.once("error", s.emit.bind(s, "error")), e.once("close", s.emitClose.bind(s)));
2060
- }
2061
- function ve(s, e, t) {
2062
- if (e) {
2063
- const r = vs(e).length;
2064
- s._socket ? s._sender._bufferedBytes += r : s._bufferedAmount += r;
2065
- }
2066
- if (t) {
2067
- const r = new Error(
2068
- `WebSocket is not open: readyState ${s.readyState} (${O[s.readyState]})`
2069
- );
2070
- process.nextTick(t, r);
2071
- }
2072
- }
2073
- function ks(s, e) {
2074
- const t = this[y];
2075
- t._closeFrameReceived = !0, t._closeMessage = e, t._closeCode = s, t._socket[y] !== void 0 && (t._socket.removeListener("data", fe), process.nextTick(ct, t._socket), s === 1005 ? t.close() : t.close(s, e));
2076
- }
2077
- function ws() {
2078
- const s = this[y];
2079
- s.isPaused || s._socket.resume();
2080
- }
2081
- function Os(s) {
2082
- const e = this[y];
2083
- e._socket[y] !== void 0 && (e._socket.removeListener("data", fe), process.nextTick(ct, e._socket), e.close(s[_s])), e.emit("error", s);
2084
- }
2085
- function Ye() {
2086
- this[y].emitClose();
2087
- }
2088
- function Cs(s, e) {
2089
- this[y].emit("message", s, e);
2090
- }
2091
- function Ts(s) {
2092
- const e = this[y];
2093
- e.pong(s, !e._isServer, at), e.emit("ping", s);
2094
- }
2095
- function Ls(s) {
2096
- this[y].emit("pong", s);
2097
- }
2098
- function ct(s) {
2099
- s.resume();
2100
- }
2101
- function ut() {
2102
- const s = this[y];
2103
- this.removeListener("close", ut), this.removeListener("data", fe), this.removeListener("end", dt), s._readyState = m.CLOSING;
2104
- let e;
2105
- !this._readableState.endEmitted && !s._closeFrameReceived && !s._receiver._writableState.errorEmitted && (e = s._socket.read()) !== null && s._receiver.write(e), s._receiver.end(), this[y] = void 0, clearTimeout(s._closeTimer), s._receiver._writableState.finished || s._receiver._writableState.errorEmitted ? s.emitClose() : (s._receiver.on("error", Ye), s._receiver.on("finish", Ye));
2106
- }
2107
- function fe(s) {
2108
- this[y]._receiver.write(s) || this.pause();
2109
- }
2110
- function dt() {
2111
- const s = this[y];
2112
- s._readyState = m.CLOSING, s._receiver.end(), this.end();
2113
- }
2114
- function _t() {
2115
- const s = this[y];
2116
- this.removeListener("error", _t), this.on("error", at), s && (s._readyState = m.CLOSING, this.destroy());
2117
- }
2118
- const Xs = /* @__PURE__ */ z(ft), { tokenChars: Ns } = ae;
2119
- function Ps(s) {
2120
- const e = /* @__PURE__ */ new Set();
2121
- let t = -1, r = -1, i = 0;
2122
- for (i; i < s.length; i++) {
2123
- const o = s.charCodeAt(i);
2124
- if (r === -1 && Ns[o] === 1)
2125
- t === -1 && (t = i);
2126
- else if (i !== 0 && (o === 32 || o === 9))
2127
- r === -1 && t !== -1 && (r = i);
2128
- else if (o === 44) {
2129
- if (t === -1)
2130
- throw new SyntaxError(`Unexpected character at index ${i}`);
2131
- r === -1 && (r = i);
2132
- const l = s.slice(t, r);
2133
- if (e.has(l))
2134
- throw new SyntaxError(`The "${l}" subprotocol is duplicated`);
2135
- e.add(l), t = r = -1;
2136
- } else
2137
- throw new SyntaxError(`Unexpected character at index ${i}`);
2138
- }
2139
- if (t === -1 || r !== -1)
2140
- throw new SyntaxError("Unexpected end of input");
2141
- const n = s.slice(t, i);
2142
- if (e.has(n))
2143
- throw new SyntaxError(`The "${n}" subprotocol is duplicated`);
2144
- return e.add(n), e;
2145
- }
2146
- var Rs = { parse: Ps };
2147
- const Us = S, ie = S, { createHash: Bs } = S, qe = nt, N = oe, $s = Rs, Ms = ft, { GUID: Is, kWebSocket: Ds } = U, Ws = /^[+/0-9A-Za-z]{22}==$/, Ke = 0, Xe = 1, pt = 2;
2148
- class As extends Us {
2149
- /**
2150
- * Create a `WebSocketServer` instance.
2151
- *
2152
- * @param {Object} options Configuration options
2153
- * @param {Number} [options.backlog=511] The maximum length of the queue of
2154
- * pending connections
2155
- * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
2156
- * track clients
2157
- * @param {Function} [options.handleProtocols] A hook to handle protocols
2158
- * @param {String} [options.host] The hostname where to bind the server
2159
- * @param {Number} [options.maxPayload=104857600] The maximum allowed message
2160
- * size
2161
- * @param {Boolean} [options.noServer=false] Enable no server mode
2162
- * @param {String} [options.path] Accept only connections matching this path
2163
- * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
2164
- * permessage-deflate
2165
- * @param {Number} [options.port] The port where to bind the server
2166
- * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
2167
- * server to use
2168
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2169
- * not to skip UTF-8 validation for text and close messages
2170
- * @param {Function} [options.verifyClient] A hook to reject connections
2171
- * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
2172
- * class to use. It must be the `WebSocket` class or class that extends it
2173
- * @param {Function} [callback] A listener for the `listening` event
2174
- */
2175
- constructor(e, t) {
2176
- if (super(), e = {
2177
- maxPayload: 100 * 1024 * 1024,
2178
- skipUTF8Validation: !1,
2179
- perMessageDeflate: !1,
2180
- handleProtocols: null,
2181
- clientTracking: !0,
2182
- verifyClient: null,
2183
- noServer: !1,
2184
- backlog: null,
2185
- // use default (511 as implemented in net.js)
2186
- server: null,
2187
- host: null,
2188
- path: null,
2189
- port: null,
2190
- WebSocket: Ms,
2191
- ...e
2192
- }, e.port == null && !e.server && !e.noServer || e.port != null && (e.server || e.noServer) || e.server && e.noServer)
2193
- throw new TypeError(
2194
- 'One and only one of the "port", "server", or "noServer" options must be specified'
2195
- );
2196
- if (e.port != null ? (this._server = ie.createServer((r, i) => {
2197
- const n = ie.STATUS_CODES[426];
2198
- i.writeHead(426, {
2199
- "Content-Length": n.length,
2200
- "Content-Type": "text/plain"
2201
- }), i.end(n);
2202
- }), this._server.listen(
2203
- e.port,
2204
- e.host,
2205
- e.backlog,
2206
- t
2207
- )) : e.server && (this._server = e.server), this._server) {
2208
- const r = this.emit.bind(this, "connection");
2209
- this._removeListeners = js(this._server, {
2210
- listening: this.emit.bind(this, "listening"),
2211
- error: this.emit.bind(this, "error"),
2212
- upgrade: (i, n, o) => {
2213
- this.handleUpgrade(i, n, o, r);
2214
- }
2215
- });
2216
- }
2217
- e.perMessageDeflate === !0 && (e.perMessageDeflate = {}), e.clientTracking && (this.clients = /* @__PURE__ */ new Set(), this._shouldEmitClose = !1), this.options = e, this._state = Ke;
2218
- }
2219
- /**
2220
- * Returns the bound address, the address family name, and port of the server
2221
- * as reported by the operating system if listening on an IP socket.
2222
- * If the server is listening on a pipe or UNIX domain socket, the name is
2223
- * returned as a string.
2224
- *
2225
- * @return {(Object|String|null)} The address of the server
2226
- * @public
2227
- */
2228
- address() {
2229
- if (this.options.noServer)
2230
- throw new Error('The server is operating in "noServer" mode');
2231
- return this._server ? this._server.address() : null;
2232
- }
2233
- /**
2234
- * Stop the server from accepting new connections and emit the `'close'` event
2235
- * when all existing connections are closed.
2236
- *
2237
- * @param {Function} [cb] A one-time listener for the `'close'` event
2238
- * @public
2239
- */
2240
- close(e) {
2241
- if (this._state === pt) {
2242
- e && this.once("close", () => {
2243
- e(new Error("The server is not running"));
2244
- }), process.nextTick(G, this);
2245
- return;
2246
- }
2247
- if (e && this.once("close", e), this._state !== Xe)
2248
- if (this._state = Xe, this.options.noServer || this.options.server)
2249
- this._server && (this._removeListeners(), this._removeListeners = this._server = null), this.clients ? this.clients.size ? this._shouldEmitClose = !0 : process.nextTick(G, this) : process.nextTick(G, this);
2250
- else {
2251
- const t = this._server;
2252
- this._removeListeners(), this._removeListeners = this._server = null, t.close(() => {
2253
- G(this);
2254
- });
2255
- }
2256
- }
2257
- /**
2258
- * See if a given request should be handled by this server instance.
2259
- *
2260
- * @param {http.IncomingMessage} req Request object to inspect
2261
- * @return {Boolean} `true` if the request is valid, else `false`
2262
- * @public
2263
- */
2264
- shouldHandle(e) {
2265
- if (this.options.path) {
2266
- const t = e.url.indexOf("?");
2267
- if ((t !== -1 ? e.url.slice(0, t) : e.url) !== this.options.path)
2268
- return !1;
2269
- }
2270
- return !0;
2271
- }
2272
- /**
2273
- * Handle a HTTP Upgrade request.
2274
- *
2275
- * @param {http.IncomingMessage} req The request object
2276
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
2277
- * server and client
2278
- * @param {Buffer} head The first packet of the upgraded stream
2279
- * @param {Function} cb Callback
2280
- * @public
2281
- */
2282
- handleUpgrade(e, t, r, i) {
2283
- t.on("error", Ze);
2284
- const n = e.headers["sec-websocket-key"], o = +e.headers["sec-websocket-version"];
2285
- if (e.method !== "GET") {
2286
- R(this, e, t, 405, "Invalid HTTP method");
2287
- return;
2288
- }
2289
- if (e.headers.upgrade.toLowerCase() !== "websocket") {
2290
- R(this, e, t, 400, "Invalid Upgrade header");
2291
- return;
2292
- }
2293
- if (!n || !Ws.test(n)) {
2294
- R(this, e, t, 400, "Missing or invalid Sec-WebSocket-Key header");
2295
- return;
2296
- }
2297
- if (o !== 8 && o !== 13) {
2298
- R(this, e, t, 400, "Missing or invalid Sec-WebSocket-Version header");
2299
- return;
2300
- }
2301
- if (!this.shouldHandle(e)) {
2302
- H(t, 400);
2303
- return;
2304
- }
2305
- const l = e.headers["sec-websocket-protocol"];
2306
- let f = /* @__PURE__ */ new Set();
2307
- if (l !== void 0)
2308
- try {
2309
- f = $s.parse(l);
2310
- } catch {
2311
- R(this, e, t, 400, "Invalid Sec-WebSocket-Protocol header");
2312
- return;
2313
- }
2314
- const a = e.headers["sec-websocket-extensions"], c = {};
2315
- if (this.options.perMessageDeflate && a !== void 0) {
2316
- const h = new N(
2317
- this.options.perMessageDeflate,
2318
- !0,
2319
- this.options.maxPayload
2320
- );
2321
- try {
2322
- const p = qe.parse(a);
2323
- p[N.extensionName] && (h.accept(p[N.extensionName]), c[N.extensionName] = h);
2324
- } catch {
2325
- R(this, e, t, 400, "Invalid or unacceptable Sec-WebSocket-Extensions header");
2326
- return;
2327
- }
2328
- }
2329
- if (this.options.verifyClient) {
2330
- const h = {
2331
- origin: e.headers[`${o === 8 ? "sec-websocket-origin" : "origin"}`],
2332
- secure: !!(e.socket.authorized || e.socket.encrypted),
2333
- req: e
2334
- };
2335
- if (this.options.verifyClient.length === 2) {
2336
- this.options.verifyClient(h, (p, v, _, u) => {
2337
- if (!p)
2338
- return H(t, v || 401, _, u);
2339
- this.completeUpgrade(
2340
- c,
2341
- n,
2342
- f,
2343
- e,
2344
- t,
2345
- r,
2346
- i
2347
- );
2348
- });
2349
- return;
2350
- }
2351
- if (!this.options.verifyClient(h))
2352
- return H(t, 401);
2353
- }
2354
- this.completeUpgrade(c, n, f, e, t, r, i);
2355
- }
2356
- /**
2357
- * Upgrade the connection to WebSocket.
2358
- *
2359
- * @param {Object} extensions The accepted extensions
2360
- * @param {String} key The value of the `Sec-WebSocket-Key` header
2361
- * @param {Set} protocols The subprotocols
2362
- * @param {http.IncomingMessage} req The request object
2363
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
2364
- * server and client
2365
- * @param {Buffer} head The first packet of the upgraded stream
2366
- * @param {Function} cb Callback
2367
- * @throws {Error} If called more than once with the same socket
2368
- * @private
2369
- */
2370
- completeUpgrade(e, t, r, i, n, o, l) {
2371
- if (!n.readable || !n.writable)
2372
- return n.destroy();
2373
- if (n[Ds])
2374
- throw new Error(
2375
- "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
2376
- );
2377
- if (this._state > Ke)
2378
- return H(n, 503);
2379
- const a = [
2380
- "HTTP/1.1 101 Switching Protocols",
2381
- "Upgrade: websocket",
2382
- "Connection: Upgrade",
2383
- `Sec-WebSocket-Accept: ${Bs("sha1").update(t + Is).digest("base64")}`
2384
- ], c = new this.options.WebSocket(null);
2385
- if (r.size) {
2386
- const h = this.options.handleProtocols ? this.options.handleProtocols(r, i) : r.values().next().value;
2387
- h && (a.push(`Sec-WebSocket-Protocol: ${h}`), c._protocol = h);
2388
- }
2389
- if (e[N.extensionName]) {
2390
- const h = e[N.extensionName].params, p = qe.format({
2391
- [N.extensionName]: [h]
2392
- });
2393
- a.push(`Sec-WebSocket-Extensions: ${p}`), c._extensions = e;
2394
- }
2395
- this.emit("headers", a, i), n.write(a.concat(`\r
2396
- `).join(`\r
2397
- `)), n.removeListener("error", Ze), c.setSocket(n, o, {
2398
- maxPayload: this.options.maxPayload,
2399
- skipUTF8Validation: this.options.skipUTF8Validation
2400
- }), this.clients && (this.clients.add(c), c.on("close", () => {
2401
- this.clients.delete(c), this._shouldEmitClose && !this.clients.size && process.nextTick(G, this);
2402
- })), l(c, i);
2403
- }
2404
- }
2405
- var Fs = As;
2406
- function js(s, e) {
2407
- for (const t of Object.keys(e))
2408
- s.on(t, e[t]);
2409
- return function() {
2410
- for (const r of Object.keys(e))
2411
- s.removeListener(r, e[r]);
2412
- };
2413
- }
2414
- function G(s) {
2415
- s._state = pt, s.emit("close");
2416
- }
2417
- function Ze() {
2418
- this.destroy();
2419
- }
2420
- function H(s, e, t, r) {
2421
- t = t || ie.STATUS_CODES[e], r = {
2422
- Connection: "close",
2423
- "Content-Type": "text/html",
2424
- "Content-Length": Buffer.byteLength(t),
2425
- ...r
2426
- }, s.once("finish", s.destroy), s.end(
2427
- `HTTP/1.1 ${e} ${ie.STATUS_CODES[e]}\r
2428
- ` + Object.keys(r).map((i) => `${i}: ${r[i]}`).join(`\r
2429
- `) + `\r
2430
- \r
2431
- ` + t
2432
- );
2433
- }
2434
- function R(s, e, t, r, i) {
2435
- if (s.listenerCount("wsClientError")) {
2436
- const n = new Error(i);
2437
- Error.captureStackTrace(n, R), s.emit("wsClientError", n, t, e);
2438
- } else
2439
- H(t, r, i);
2440
- }
2441
- const Zs = /* @__PURE__ */ z(Fs);
2442
- export {
2443
- qs as Receiver,
2444
- Ks as Sender,
2445
- Xs as WebSocket,
2446
- Zs as WebSocketServer,
2447
- Vs as createWebSocketStream,
2448
- Xs as default
2449
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/backend/gradio_pdf/templates/example/index.js DELETED
The diff for this file is too large to render. See raw diff
 
src/backend/gradio_pdf/templates/example/style.css DELETED
@@ -1 +0,0 @@
1
- .gallery.svelte-1gecy8w{padding:var(--size-1) var(--size-2)}
 
 
src/demo/__init__.py DELETED
File without changes
src/demo/_app.py DELETED
@@ -1,30 +0,0 @@
1
-
2
- import gradio as gr
3
- from gradio_pdf import PDF
4
- from pdf2image import convert_from_path
5
- from transformers import pipeline
6
- from pathlib import Path
7
-
8
- dir_ = Path(__file__).parent
9
-
10
- p = pipeline(
11
- "document-question-answering",
12
- model="impira/layoutlm-document-qa",
13
- )
14
-
15
- def qa(question: str, doc: str) -> str:
16
- img = convert_from_path(doc)[0]
17
- output = p(img, question)
18
- return sorted(output, key=lambda x: x["score"], reverse=True)[0]['answer']
19
-
20
-
21
- demo = gr.Interface(
22
- qa,
23
- [gr.Textbox(label="Question"), PDF(label="Document")],
24
- gr.Textbox(),
25
- examples=[["What is the total gross worth?", str(dir_ / "invoice_2.pdf")],
26
- ["Whos is being invoiced?", str(dir_ / "sample_invoice.pdf")]]
27
- )
28
-
29
- if __name__ == "__main__":
30
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/demo/app.py DELETED
@@ -1,151 +0,0 @@
1
-
2
- import gradio as gr
3
- from _app import demo as app
4
- import os
5
-
6
- _docs = {'PDF': {'description': 'A base class for defining methods that all input/output components should have.', 'members': {'__init__': {'value': {'type': 'Any', 'default': 'None', 'description': None}, 'height': {'type': 'int | None', 'default': 'None', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | None', 'description': None}}, 'preprocess': {'return': {'type': 'str', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'upload': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'PDF': []}}}
7
-
8
- abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
-
10
- with gr.Blocks(
11
- css=abs_path,
12
- theme=gr.themes.Default(
13
- font_mono=[
14
- gr.themes.GoogleFont("Inconsolata"),
15
- "monospace",
16
- ],
17
- ),
18
- ) as demo:
19
- gr.Markdown(
20
- """
21
- # `gradio_pdf`
22
-
23
- <div style="display: flex; gap: 7px;">
24
- <a href="https://pypi.org/project/gradio_pdf/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_pdf"></a> <a href="https://github.com/freddyaboulton/gradio-pdf/issues" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Issues-white?logo=github&logoColor=black"></a> <a href="https://huggingface.co/spaces/freddyaboulton/gradio_pdf/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
25
- </div>
26
-
27
- Easily display PDFs in Gradio
28
- """, elem_classes=["md-custom"], header_links=True)
29
- app.render()
30
- gr.Markdown(
31
- """
32
- ## Installation
33
-
34
- ```bash
35
- pip install gradio_pdf
36
- ```
37
-
38
- ## Usage
39
-
40
- ```python
41
-
42
- import gradio as gr
43
- from gradio_pdf import PDF
44
- from pdf2image import convert_from_path
45
- from transformers import pipeline
46
- from pathlib import Path
47
-
48
- dir_ = Path(__file__).parent
49
-
50
- p = pipeline(
51
- "document-question-answering",
52
- model="impira/layoutlm-document-qa",
53
- )
54
-
55
- def qa(question: str, doc: str) -> str:
56
- img = convert_from_path(doc)[0]
57
- output = p(img, question)
58
- return sorted(output, key=lambda x: x["score"], reverse=True)[0]['answer']
59
-
60
-
61
- demo = gr.Interface(
62
- qa,
63
- [gr.Textbox(label="Question"), PDF(label="Document")],
64
- gr.Textbox(),
65
- examples=[["What is the total gross worth?", str(dir_ / "invoice_2.pdf")],
66
- ["Whos is being invoiced?", str(dir_ / "sample_invoice.pdf")]]
67
- )
68
-
69
- if __name__ == "__main__":
70
- demo.launch()
71
-
72
- ```
73
- """, elem_classes=["md-custom"], header_links=True)
74
-
75
-
76
- gr.Markdown("""
77
- ## `PDF`
78
-
79
- ### Initialization
80
- """, elem_classes=["md-custom"], header_links=True)
81
-
82
- gr.ParamViewer(value=_docs["PDF"]["members"]["__init__"], linkify=[])
83
-
84
-
85
- gr.Markdown("### Events")
86
- gr.ParamViewer(value=_docs["PDF"]["events"], linkify=['Event'])
87
-
88
-
89
-
90
-
91
- gr.Markdown("""
92
-
93
- ### User function
94
-
95
- The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
96
-
97
- - When used as an Input, the component only impacts the input signature of the user function.
98
- - When used as an output, the component only impacts the return signature of the user function.
99
-
100
- The code snippet below is accurate in cases where the component is used as both an input and an output.
101
-
102
-
103
-
104
- ```python
105
- def predict(
106
- value: str
107
- ) -> str | None:
108
- return value
109
- ```
110
- """, elem_classes=["md-custom", "PDF-user-fn"], header_links=True)
111
-
112
-
113
-
114
-
115
- demo.load(None, js=r"""function() {
116
- const refs = {};
117
- const user_fn_refs = {
118
- PDF: [], };
119
- requestAnimationFrame(() => {
120
-
121
- Object.entries(user_fn_refs).forEach(([key, refs]) => {
122
- if (refs.length > 0) {
123
- const el = document.querySelector(`.${key}-user-fn`);
124
- if (!el) return;
125
- refs.forEach(ref => {
126
- el.innerHTML = el.innerHTML.replace(
127
- new RegExp("\\b"+ref+"\\b", "g"),
128
- `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
129
- );
130
- })
131
- }
132
- })
133
-
134
- Object.entries(refs).forEach(([key, refs]) => {
135
- if (refs.length > 0) {
136
- const el = document.querySelector(`.${key}`);
137
- if (!el) return;
138
- refs.forEach(ref => {
139
- el.innerHTML = el.innerHTML.replace(
140
- new RegExp("\\b"+ref+"\\b", "g"),
141
- `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
142
- );
143
- })
144
- }
145
- })
146
- })
147
- }
148
-
149
- """)
150
-
151
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/demo/contract.pdf DELETED
Binary file (128 kB)
 
src/demo/css.css DELETED
@@ -1,157 +0,0 @@
1
- html {
2
- font-family: Inter;
3
- font-size: 16px;
4
- font-weight: 400;
5
- line-height: 1.5;
6
- -webkit-text-size-adjust: 100%;
7
- background: #fff;
8
- color: #323232;
9
- -webkit-font-smoothing: antialiased;
10
- -moz-osx-font-smoothing: grayscale;
11
- text-rendering: optimizeLegibility;
12
- }
13
-
14
- :root {
15
- --space: 1;
16
- --vspace: calc(var(--space) * 1rem);
17
- --vspace-0: calc(3 * var(--space) * 1rem);
18
- --vspace-1: calc(2 * var(--space) * 1rem);
19
- --vspace-2: calc(1.5 * var(--space) * 1rem);
20
- --vspace-3: calc(0.5 * var(--space) * 1rem);
21
- }
22
-
23
- .app {
24
- max-width: 748px !important;
25
- }
26
-
27
- .prose p {
28
- margin: var(--vspace) 0;
29
- line-height: var(--vspace * 2);
30
- font-size: 1rem;
31
- }
32
-
33
- code {
34
- font-family: "Inconsolata", sans-serif;
35
- font-size: 16px;
36
- }
37
-
38
- h1,
39
- h1 code {
40
- font-weight: 400;
41
- line-height: calc(2.5 / var(--space) * var(--vspace));
42
- }
43
-
44
- h1 code {
45
- background: none;
46
- border: none;
47
- letter-spacing: 0.05em;
48
- padding-bottom: 5px;
49
- position: relative;
50
- padding: 0;
51
- }
52
-
53
- h2 {
54
- margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
- line-height: 1em;
56
- }
57
-
58
- h3,
59
- h3 code {
60
- margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
- line-height: 1em;
62
- }
63
-
64
- h4,
65
- h5,
66
- h6 {
67
- margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
- line-height: var(--vspace);
69
- }
70
-
71
- .bigtitle,
72
- h1,
73
- h1 code {
74
- font-size: calc(8px * 4.5);
75
- word-break: break-word;
76
- }
77
-
78
- .title,
79
- h2,
80
- h2 code {
81
- font-size: calc(8px * 3.375);
82
- font-weight: lighter;
83
- word-break: break-word;
84
- border: none;
85
- background: none;
86
- }
87
-
88
- .subheading1,
89
- h3,
90
- h3 code {
91
- font-size: calc(8px * 1.8);
92
- font-weight: 600;
93
- border: none;
94
- background: none;
95
- letter-spacing: 0.1em;
96
- text-transform: uppercase;
97
- }
98
-
99
- h2 code {
100
- padding: 0;
101
- position: relative;
102
- letter-spacing: 0.05em;
103
- }
104
-
105
- blockquote {
106
- font-size: calc(8px * 1.1667);
107
- font-style: italic;
108
- line-height: calc(1.1667 * var(--vspace));
109
- margin: var(--vspace-2) var(--vspace-2);
110
- }
111
-
112
- .subheading2,
113
- h4 {
114
- font-size: calc(8px * 1.4292);
115
- text-transform: uppercase;
116
- font-weight: 600;
117
- }
118
-
119
- .subheading3,
120
- h5 {
121
- font-size: calc(8px * 1.2917);
122
- line-height: calc(1.2917 * var(--vspace));
123
-
124
- font-weight: lighter;
125
- text-transform: uppercase;
126
- letter-spacing: 0.15em;
127
- }
128
-
129
- h6 {
130
- font-size: calc(8px * 1.1667);
131
- font-size: 1.1667em;
132
- font-weight: normal;
133
- font-style: italic;
134
- font-family: "le-monde-livre-classic-byol", serif !important;
135
- letter-spacing: 0px !important;
136
- }
137
-
138
- #start .md > *:first-child {
139
- margin-top: 0;
140
- }
141
-
142
- h2 + h3 {
143
- margin-top: 0;
144
- }
145
-
146
- .md hr {
147
- border: none;
148
- border-top: 1px solid var(--block-border-color);
149
- margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
- }
151
- .prose ul {
152
- margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
- }
154
-
155
- .gap {
156
- gap: 0;
157
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/demo/invoice_2.pdf DELETED
Binary file (372 kB)
 
src/demo/requirements.txt DELETED
@@ -1,4 +0,0 @@
1
- torch
2
- transformers
3
- pdf2image
4
- pytesseract
 
 
 
 
 
src/demo/sample_invoice.pdf DELETED
Binary file (34.7 kB)
 
src/frontend/Example.svelte DELETED
@@ -1,52 +0,0 @@
1
- <script lang="ts">
2
- export let value: string;
3
- export let samples_dir: string;
4
- export let type: "gallery" | "table";
5
- export let selected = false;
6
- import pdfjsLib from "pdfjs-dist";
7
- pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdn.bootcss.com/pdf.js/3.11.174/pdf.worker.js";
8
-
9
- let pdfDoc;
10
- let canvasRef;
11
-
12
- async function get_doc(url: string) {
13
- const loadingTask = pdfjsLib.getDocument(url);
14
- pdfDoc = await loadingTask.promise;
15
- renderPage();
16
- }
17
-
18
- function renderPage() {
19
- // Render a specific page of the PDF onto the canvas
20
- pdfDoc.getPage(1).then(page => {
21
- const ctx = canvasRef.getContext('2d')
22
- ctx.clearRect(0, 0, canvasRef.width, canvasRef.height);
23
-
24
- const viewport = page.getViewport({ scale: 0.2 });
25
-
26
- const renderContext = {
27
- canvasContext: ctx,
28
- viewport
29
- };
30
- canvasRef.width = viewport.width;
31
- canvasRef.height = viewport.height;
32
- page.render(renderContext);
33
- });
34
- }
35
-
36
- $: get_doc(samples_dir + value);
37
- </script>
38
-
39
- <div
40
- class:table={type === "table"}
41
- class:gallery={type === "gallery"}
42
- class:selected
43
- style="justify-content: center; align-items: center; display: flex; flex-direction: column;"
44
- >
45
- <canvas bind:this={canvasRef}></canvas>
46
- </div>
47
-
48
- <style>
49
- .gallery {
50
- padding: var(--size-1) var(--size-2);
51
- }
52
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/frontend/Index.svelte DELETED
@@ -1,174 +0,0 @@
1
- <script lang="ts">
2
- import { tick } from "svelte";
3
- import PdfUploadText from "./PdfUploadText.svelte";
4
- import type { Gradio } from "@gradio/utils";
5
- import { Block, BlockLabel } from "@gradio/atoms";
6
- import { BaseButton } from "@gradio/button";
7
- import { File } from "@gradio/icons";
8
- import { StatusTracker } from "@gradio/statustracker";
9
- import type { LoadingStatus } from "@gradio/statustracker";
10
- import type { FileData } from "@gradio/client";
11
- import { normalise_file } from "@gradio/client";
12
- import { Upload, ModifyUpload } from "@gradio/upload";
13
- import pdfjsLib from "pdfjs-dist";
14
-
15
- export let elem_id = "";
16
- export let elem_classes: string[] = [];
17
- export let visible = true;
18
- export let value: FileData | null = null;
19
- export let container = true;
20
- export let scale: number | null = null;
21
- export let root: string;
22
- export let height: number | null = 500;
23
- export let label: string;
24
- export let proxy_url: string;
25
- export let min_width: number | undefined = undefined;
26
- export let loading_status: LoadingStatus;
27
- export let gradio: Gradio<{
28
- change: never;
29
- upload: never;
30
- }>;
31
-
32
- pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdn.bootcss.com/pdf.js/3.11.174/pdf.worker.js";
33
-
34
- let _value = value;
35
- let old_value = _value;
36
- let pdfDoc;
37
- let numPages = 1;
38
- let currentPage = 1;
39
- let canvasRef;
40
-
41
- async function handle_clear() {
42
- _value = null;
43
- await tick();
44
- gradio.dispatch("change");
45
- }
46
-
47
- async function handle_upload({detail}: CustomEvent<FileData>): Promise<void> {
48
- value = detail;
49
- await tick();
50
- gradio.dispatch("change");
51
- gradio.dispatch("upload");
52
- }
53
-
54
-
55
- async function get_doc(value: FileData) {
56
- const loadingTask = pdfjsLib.getDocument(value.url);
57
- pdfDoc = await loadingTask.promise;
58
- numPages = pdfDoc.numPages;
59
- render_page();
60
- }
61
-
62
- function render_page() {
63
- // Render a specific page of the PDF onto the canvas
64
- pdfDoc.getPage(currentPage).then(page => {
65
- const ctx = canvasRef.getContext('2d')
66
- ctx.clearRect(0, 0, canvasRef.width, canvasRef.height);
67
- let viewport = page.getViewport({ scale: 1 });
68
- let scale = height / viewport.height;
69
- viewport = page.getViewport({ scale: scale });
70
-
71
- const renderContext = {
72
- canvasContext: ctx,
73
- viewport,
74
- };
75
- canvasRef.width = viewport.width;
76
- canvasRef.height = viewport.height;
77
- page.render(renderContext);
78
- });
79
- }
80
-
81
- function next_page() {
82
- if (currentPage >= numPages) {
83
- return;
84
- }
85
- currentPage++;
86
- render_page();
87
- }
88
-
89
- function prev_page() {
90
- if (currentPage == 1) {
91
- return;
92
- }
93
- currentPage--;
94
- render_page();
95
- }
96
-
97
- $: height = height || 500;
98
-
99
- // Compute the url to fetch the file from the backend\
100
- // whenever a new value is passed in.
101
- $: _value = normalise_file(value, root, proxy_url);
102
-
103
- // If the value changes, render the PDF of the currentPage
104
- $: if(JSON.stringify(old_value) != JSON.stringify(_value)) {
105
- if (_value){
106
- get_doc(_value);
107
- }
108
- old_value = _value;
109
- gradio.dispatch("change");
110
- }
111
- </script>
112
-
113
- <Block {visible} {elem_id} {elem_classes} {container} {scale} {min_width}>
114
- {#if loading_status}
115
- <StatusTracker
116
- autoscroll={gradio.autoscroll}
117
- i18n={gradio.i18n}
118
- {...loading_status}
119
- />
120
- {/if}
121
- <BlockLabel
122
- show_label={label !== null}
123
- Icon={File}
124
- float={value === null}
125
- label={label || "File"}
126
- />
127
- {#if _value}
128
- <ModifyUpload i18n={gradio.i18n} on:clear={handle_clear} absolute />
129
- <div class="pdf-canvas" style="height: {height}px">
130
- <canvas bind:this={canvasRef}></canvas>
131
- </div>
132
- <div class="button-row">
133
- <BaseButton on:click={prev_page}>
134
- ⬅️
135
- </BaseButton>
136
- <span class="page-count"> {currentPage} / {numPages} </span>
137
- <BaseButton on:click={next_page}>
138
- ➡️
139
- </BaseButton>
140
- </div>
141
- {:else}
142
- <Upload
143
- on:load={handle_upload}
144
- filetype={"application/pdf"}
145
- file_count="single"
146
- {root}
147
- >
148
- <PdfUploadText/>
149
- </Upload>
150
- {/if}
151
- </Block>
152
-
153
- <style>
154
- .pdf-canvas {
155
- display: flex;
156
- justify-content: center;
157
- align-items: center;
158
- overflow-y: auto;
159
- }
160
-
161
- .button-row {
162
- display: flex;
163
- flex-direction: row;
164
- width: 100%;
165
- justify-content: center;
166
- align-items: center;
167
- }
168
-
169
- .page-count {
170
- margin: 0 10px;
171
- font-family: var(--font-mono);
172
- }
173
-
174
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/frontend/PdfUploadText.svelte DELETED
@@ -1,47 +0,0 @@
1
- <script lang="ts">
2
- import { Upload as UploadIcon } from "@gradio/icons";
3
- export let hovered = false;
4
-
5
- </script>
6
-
7
- <div class="wrap">
8
- <span class="icon-wrap" class:hovered><UploadIcon /> </span>
9
- Drop PDF
10
- <span class="or">- or -</span>
11
- Click to Upload
12
-
13
- </div>
14
-
15
- <style>
16
- .wrap {
17
- display: flex;
18
- flex-direction: column;
19
- justify-content: center;
20
- align-items: center;
21
- min-height: var(--size-60);
22
- color: var(--block-label-text-color);
23
- line-height: var(--line-md);
24
- height: 100%;
25
- padding-top: var(--size-3);
26
- }
27
-
28
- .or {
29
- color: var(--body-text-color-subdued);
30
- display: flex;
31
- }
32
-
33
- .icon-wrap {
34
- width: 30px;
35
- margin-bottom: var(--spacing-lg);
36
- }
37
-
38
- @media (--screen-md) {
39
- .wrap {
40
- font-size: var(--text-lg);
41
- }
42
- }
43
-
44
- .hovered {
45
- color: var(--color-accent);
46
- }
47
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/frontend/package-lock.json DELETED
@@ -1,1822 +0,0 @@
1
- {
2
- "name": "gradio_pdf",
3
- "version": "0.2.0",
4
- "lockfileVersion": 3,
5
- "requires": true,
6
- "packages": {
7
- "": {
8
- "name": "gradio_pdf",
9
- "version": "0.2.0",
10
- "license": "ISC",
11
- "dependencies": {
12
- "@gradio/atoms": "0.2.0",
13
- "@gradio/button": "0.2.3",
14
- "@gradio/client": "0.7.1",
15
- "@gradio/icons": "0.2.0",
16
- "@gradio/statustracker": "0.3.0",
17
- "@gradio/upload": "0.3.2",
18
- "@gradio/utils": "0.2.0",
19
- "pdfjs-dist": "3.11.174"
20
- },
21
- "devDependencies": {
22
- "pdfjs-dist": "3.11.174"
23
- }
24
- },
25
- "node_modules/@ampproject/remapping": {
26
- "version": "2.2.1",
27
- "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz",
28
- "integrity": "sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==",
29
- "peer": true,
30
- "dependencies": {
31
- "@jridgewell/gen-mapping": "^0.3.0",
32
- "@jridgewell/trace-mapping": "^0.3.9"
33
- },
34
- "engines": {
35
- "node": ">=6.0.0"
36
- }
37
- },
38
- "node_modules/@esbuild/android-arm": {
39
- "version": "0.19.5",
40
- "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.5.tgz",
41
- "integrity": "sha512-bhvbzWFF3CwMs5tbjf3ObfGqbl/17ict2/uwOSfr3wmxDE6VdS2GqY/FuzIPe0q0bdhj65zQsvqfArI9MY6+AA==",
42
- "cpu": [
43
- "arm"
44
- ],
45
- "optional": true,
46
- "os": [
47
- "android"
48
- ],
49
- "engines": {
50
- "node": ">=12"
51
- }
52
- },
53
- "node_modules/@esbuild/android-arm64": {
54
- "version": "0.19.5",
55
- "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.5.tgz",
56
- "integrity": "sha512-5d1OkoJxnYQfmC+Zd8NBFjkhyCNYwM4n9ODrycTFY6Jk1IGiZ+tjVJDDSwDt77nK+tfpGP4T50iMtVi4dEGzhQ==",
57
- "cpu": [
58
- "arm64"
59
- ],
60
- "optional": true,
61
- "os": [
62
- "android"
63
- ],
64
- "engines": {
65
- "node": ">=12"
66
- }
67
- },
68
- "node_modules/@esbuild/android-x64": {
69
- "version": "0.19.5",
70
- "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.5.tgz",
71
- "integrity": "sha512-9t+28jHGL7uBdkBjL90QFxe7DVA+KGqWlHCF8ChTKyaKO//VLuoBricQCgwhOjA1/qOczsw843Fy4cbs4H3DVA==",
72
- "cpu": [
73
- "x64"
74
- ],
75
- "optional": true,
76
- "os": [
77
- "android"
78
- ],
79
- "engines": {
80
- "node": ">=12"
81
- }
82
- },
83
- "node_modules/@esbuild/darwin-arm64": {
84
- "version": "0.19.5",
85
- "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.5.tgz",
86
- "integrity": "sha512-mvXGcKqqIqyKoxq26qEDPHJuBYUA5KizJncKOAf9eJQez+L9O+KfvNFu6nl7SCZ/gFb2QPaRqqmG0doSWlgkqw==",
87
- "cpu": [
88
- "arm64"
89
- ],
90
- "optional": true,
91
- "os": [
92
- "darwin"
93
- ],
94
- "engines": {
95
- "node": ">=12"
96
- }
97
- },
98
- "node_modules/@esbuild/darwin-x64": {
99
- "version": "0.19.5",
100
- "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.5.tgz",
101
- "integrity": "sha512-Ly8cn6fGLNet19s0X4unjcniX24I0RqjPv+kurpXabZYSXGM4Pwpmf85WHJN3lAgB8GSth7s5A0r856S+4DyiA==",
102
- "cpu": [
103
- "x64"
104
- ],
105
- "optional": true,
106
- "os": [
107
- "darwin"
108
- ],
109
- "engines": {
110
- "node": ">=12"
111
- }
112
- },
113
- "node_modules/@esbuild/freebsd-arm64": {
114
- "version": "0.19.5",
115
- "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.5.tgz",
116
- "integrity": "sha512-GGDNnPWTmWE+DMchq1W8Sd0mUkL+APvJg3b11klSGUDvRXh70JqLAO56tubmq1s2cgpVCSKYywEiKBfju8JztQ==",
117
- "cpu": [
118
- "arm64"
119
- ],
120
- "optional": true,
121
- "os": [
122
- "freebsd"
123
- ],
124
- "engines": {
125
- "node": ">=12"
126
- }
127
- },
128
- "node_modules/@esbuild/freebsd-x64": {
129
- "version": "0.19.5",
130
- "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.5.tgz",
131
- "integrity": "sha512-1CCwDHnSSoA0HNwdfoNY0jLfJpd7ygaLAp5EHFos3VWJCRX9DMwWODf96s9TSse39Br7oOTLryRVmBoFwXbuuQ==",
132
- "cpu": [
133
- "x64"
134
- ],
135
- "optional": true,
136
- "os": [
137
- "freebsd"
138
- ],
139
- "engines": {
140
- "node": ">=12"
141
- }
142
- },
143
- "node_modules/@esbuild/linux-arm": {
144
- "version": "0.19.5",
145
- "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.5.tgz",
146
- "integrity": "sha512-lrWXLY/vJBzCPC51QN0HM71uWgIEpGSjSZZADQhq7DKhPcI6NH1IdzjfHkDQws2oNpJKpR13kv7/pFHBbDQDwQ==",
147
- "cpu": [
148
- "arm"
149
- ],
150
- "optional": true,
151
- "os": [
152
- "linux"
153
- ],
154
- "engines": {
155
- "node": ">=12"
156
- }
157
- },
158
- "node_modules/@esbuild/linux-arm64": {
159
- "version": "0.19.5",
160
- "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.5.tgz",
161
- "integrity": "sha512-o3vYippBmSrjjQUCEEiTZ2l+4yC0pVJD/Dl57WfPwwlvFkrxoSO7rmBZFii6kQB3Wrn/6GwJUPLU5t52eq2meA==",
162
- "cpu": [
163
- "arm64"
164
- ],
165
- "optional": true,
166
- "os": [
167
- "linux"
168
- ],
169
- "engines": {
170
- "node": ">=12"
171
- }
172
- },
173
- "node_modules/@esbuild/linux-ia32": {
174
- "version": "0.19.5",
175
- "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.5.tgz",
176
- "integrity": "sha512-MkjHXS03AXAkNp1KKkhSKPOCYztRtK+KXDNkBa6P78F8Bw0ynknCSClO/ztGszILZtyO/lVKpa7MolbBZ6oJtQ==",
177
- "cpu": [
178
- "ia32"
179
- ],
180
- "optional": true,
181
- "os": [
182
- "linux"
183
- ],
184
- "engines": {
185
- "node": ">=12"
186
- }
187
- },
188
- "node_modules/@esbuild/linux-loong64": {
189
- "version": "0.19.5",
190
- "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.5.tgz",
191
- "integrity": "sha512-42GwZMm5oYOD/JHqHska3Jg0r+XFb/fdZRX+WjADm3nLWLcIsN27YKtqxzQmGNJgu0AyXg4HtcSK9HuOk3v1Dw==",
192
- "cpu": [
193
- "loong64"
194
- ],
195
- "optional": true,
196
- "os": [
197
- "linux"
198
- ],
199
- "engines": {
200
- "node": ">=12"
201
- }
202
- },
203
- "node_modules/@esbuild/linux-mips64el": {
204
- "version": "0.19.5",
205
- "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.5.tgz",
206
- "integrity": "sha512-kcjndCSMitUuPJobWCnwQ9lLjiLZUR3QLQmlgaBfMX23UEa7ZOrtufnRds+6WZtIS9HdTXqND4yH8NLoVVIkcg==",
207
- "cpu": [
208
- "mips64el"
209
- ],
210
- "optional": true,
211
- "os": [
212
- "linux"
213
- ],
214
- "engines": {
215
- "node": ">=12"
216
- }
217
- },
218
- "node_modules/@esbuild/linux-ppc64": {
219
- "version": "0.19.5",
220
- "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.5.tgz",
221
- "integrity": "sha512-yJAxJfHVm0ZbsiljbtFFP1BQKLc8kUF6+17tjQ78QjqjAQDnhULWiTA6u0FCDmYT1oOKS9PzZ2z0aBI+Mcyj7Q==",
222
- "cpu": [
223
- "ppc64"
224
- ],
225
- "optional": true,
226
- "os": [
227
- "linux"
228
- ],
229
- "engines": {
230
- "node": ">=12"
231
- }
232
- },
233
- "node_modules/@esbuild/linux-riscv64": {
234
- "version": "0.19.5",
235
- "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.5.tgz",
236
- "integrity": "sha512-5u8cIR/t3gaD6ad3wNt1MNRstAZO+aNyBxu2We8X31bA8XUNyamTVQwLDA1SLoPCUehNCymhBhK3Qim1433Zag==",
237
- "cpu": [
238
- "riscv64"
239
- ],
240
- "optional": true,
241
- "os": [
242
- "linux"
243
- ],
244
- "engines": {
245
- "node": ">=12"
246
- }
247
- },
248
- "node_modules/@esbuild/linux-s390x": {
249
- "version": "0.19.5",
250
- "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.5.tgz",
251
- "integrity": "sha512-Z6JrMyEw/EmZBD/OFEFpb+gao9xJ59ATsoTNlj39jVBbXqoZm4Xntu6wVmGPB/OATi1uk/DB+yeDPv2E8PqZGw==",
252
- "cpu": [
253
- "s390x"
254
- ],
255
- "optional": true,
256
- "os": [
257
- "linux"
258
- ],
259
- "engines": {
260
- "node": ">=12"
261
- }
262
- },
263
- "node_modules/@esbuild/linux-x64": {
264
- "version": "0.19.5",
265
- "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.5.tgz",
266
- "integrity": "sha512-psagl+2RlK1z8zWZOmVdImisMtrUxvwereIdyJTmtmHahJTKb64pAcqoPlx6CewPdvGvUKe2Jw+0Z/0qhSbG1A==",
267
- "cpu": [
268
- "x64"
269
- ],
270
- "optional": true,
271
- "os": [
272
- "linux"
273
- ],
274
- "engines": {
275
- "node": ">=12"
276
- }
277
- },
278
- "node_modules/@esbuild/netbsd-x64": {
279
- "version": "0.19.5",
280
- "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.5.tgz",
281
- "integrity": "sha512-kL2l+xScnAy/E/3119OggX8SrWyBEcqAh8aOY1gr4gPvw76la2GlD4Ymf832UCVbmuWeTf2adkZDK+h0Z/fB4g==",
282
- "cpu": [
283
- "x64"
284
- ],
285
- "optional": true,
286
- "os": [
287
- "netbsd"
288
- ],
289
- "engines": {
290
- "node": ">=12"
291
- }
292
- },
293
- "node_modules/@esbuild/openbsd-x64": {
294
- "version": "0.19.5",
295
- "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.5.tgz",
296
- "integrity": "sha512-sPOfhtzFufQfTBgRnE1DIJjzsXukKSvZxloZbkJDG383q0awVAq600pc1nfqBcl0ice/WN9p4qLc39WhBShRTA==",
297
- "cpu": [
298
- "x64"
299
- ],
300
- "optional": true,
301
- "os": [
302
- "openbsd"
303
- ],
304
- "engines": {
305
- "node": ">=12"
306
- }
307
- },
308
- "node_modules/@esbuild/sunos-x64": {
309
- "version": "0.19.5",
310
- "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.5.tgz",
311
- "integrity": "sha512-dGZkBXaafuKLpDSjKcB0ax0FL36YXCvJNnztjKV+6CO82tTYVDSH2lifitJ29jxRMoUhgkg9a+VA/B03WK5lcg==",
312
- "cpu": [
313
- "x64"
314
- ],
315
- "optional": true,
316
- "os": [
317
- "sunos"
318
- ],
319
- "engines": {
320
- "node": ">=12"
321
- }
322
- },
323
- "node_modules/@esbuild/win32-arm64": {
324
- "version": "0.19.5",
325
- "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.5.tgz",
326
- "integrity": "sha512-dWVjD9y03ilhdRQ6Xig1NWNgfLtf2o/STKTS+eZuF90fI2BhbwD6WlaiCGKptlqXlURVB5AUOxUj09LuwKGDTg==",
327
- "cpu": [
328
- "arm64"
329
- ],
330
- "optional": true,
331
- "os": [
332
- "win32"
333
- ],
334
- "engines": {
335
- "node": ">=12"
336
- }
337
- },
338
- "node_modules/@esbuild/win32-ia32": {
339
- "version": "0.19.5",
340
- "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.5.tgz",
341
- "integrity": "sha512-4liggWIA4oDgUxqpZwrDhmEfAH4d0iljanDOK7AnVU89T6CzHon/ony8C5LeOdfgx60x5cnQJFZwEydVlYx4iw==",
342
- "cpu": [
343
- "ia32"
344
- ],
345
- "optional": true,
346
- "os": [
347
- "win32"
348
- ],
349
- "engines": {
350
- "node": ">=12"
351
- }
352
- },
353
- "node_modules/@esbuild/win32-x64": {
354
- "version": "0.19.5",
355
- "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.5.tgz",
356
- "integrity": "sha512-czTrygUsB/jlM8qEW5MD8bgYU2Xg14lo6kBDXW6HdxKjh8M5PzETGiSHaz9MtbXBYDloHNUAUW2tMiKW4KM9Mw==",
357
- "cpu": [
358
- "x64"
359
- ],
360
- "optional": true,
361
- "os": [
362
- "win32"
363
- ],
364
- "engines": {
365
- "node": ">=12"
366
- }
367
- },
368
- "node_modules/@formatjs/ecma402-abstract": {
369
- "version": "1.11.4",
370
- "resolved": "https://registry.npmjs.org/@formatjs/ecma402-abstract/-/ecma402-abstract-1.11.4.tgz",
371
- "integrity": "sha512-EBikYFp2JCdIfGEb5G9dyCkTGDmC57KSHhRQOC3aYxoPWVZvfWCDjZwkGYHN7Lis/fmuWl906bnNTJifDQ3sXw==",
372
- "dependencies": {
373
- "@formatjs/intl-localematcher": "0.2.25",
374
- "tslib": "^2.1.0"
375
- }
376
- },
377
- "node_modules/@formatjs/fast-memoize": {
378
- "version": "1.2.1",
379
- "resolved": "https://registry.npmjs.org/@formatjs/fast-memoize/-/fast-memoize-1.2.1.tgz",
380
- "integrity": "sha512-Rg0e76nomkz3vF9IPlKeV+Qynok0r7YZjL6syLz4/urSg0IbjPZCB/iYUMNsYA643gh4mgrX3T7KEIFIxJBQeg==",
381
- "dependencies": {
382
- "tslib": "^2.1.0"
383
- }
384
- },
385
- "node_modules/@formatjs/icu-messageformat-parser": {
386
- "version": "2.1.0",
387
- "resolved": "https://registry.npmjs.org/@formatjs/icu-messageformat-parser/-/icu-messageformat-parser-2.1.0.tgz",
388
- "integrity": "sha512-Qxv/lmCN6hKpBSss2uQ8IROVnta2r9jd3ymUEIjm2UyIkUCHVcbUVRGL/KS/wv7876edvsPe+hjHVJ4z8YuVaw==",
389
- "dependencies": {
390
- "@formatjs/ecma402-abstract": "1.11.4",
391
- "@formatjs/icu-skeleton-parser": "1.3.6",
392
- "tslib": "^2.1.0"
393
- }
394
- },
395
- "node_modules/@formatjs/icu-skeleton-parser": {
396
- "version": "1.3.6",
397
- "resolved": "https://registry.npmjs.org/@formatjs/icu-skeleton-parser/-/icu-skeleton-parser-1.3.6.tgz",
398
- "integrity": "sha512-I96mOxvml/YLrwU2Txnd4klA7V8fRhb6JG/4hm3VMNmeJo1F03IpV2L3wWt7EweqNLES59SZ4d6hVOPCSf80Bg==",
399
- "dependencies": {
400
- "@formatjs/ecma402-abstract": "1.11.4",
401
- "tslib": "^2.1.0"
402
- }
403
- },
404
- "node_modules/@formatjs/intl-localematcher": {
405
- "version": "0.2.25",
406
- "resolved": "https://registry.npmjs.org/@formatjs/intl-localematcher/-/intl-localematcher-0.2.25.tgz",
407
- "integrity": "sha512-YmLcX70BxoSopLFdLr1Ds99NdlTI2oWoLbaUW2M406lxOIPzE1KQhRz2fPUkq34xVZQaihCoU29h0KK7An3bhA==",
408
- "dependencies": {
409
- "tslib": "^2.1.0"
410
- }
411
- },
412
- "node_modules/@gradio/atoms": {
413
- "version": "0.2.0",
414
- "resolved": "https://registry.npmjs.org/@gradio/atoms/-/atoms-0.2.0.tgz",
415
- "integrity": "sha512-7pTXJTZv+KECtTG9vqeq9j7vz5OKkp+TRvh+O4yMbtkvxFEbhYaaUngkWFX26btGiveD+V4RG4qrP17jqpSdGA==",
416
- "dependencies": {
417
- "@gradio/icons": "^0.2.0",
418
- "@gradio/utils": "^0.2.0"
419
- }
420
- },
421
- "node_modules/@gradio/button": {
422
- "version": "0.2.3",
423
- "resolved": "https://registry.npmjs.org/@gradio/button/-/button-0.2.3.tgz",
424
- "integrity": "sha512-vbSMcRNrtBKycnAgpCpepKaC4NNAg36I9qbEaz8wKqHqU02oTOaUeyelEitHLWULqLf3+sy6BM+JxxFjtELgXQ==",
425
- "dependencies": {
426
- "@gradio/client": "^0.7.2",
427
- "@gradio/upload": "^0.3.3",
428
- "@gradio/utils": "^0.2.0"
429
- }
430
- },
431
- "node_modules/@gradio/button/node_modules/@gradio/atoms": {
432
- "version": "0.2.1",
433
- "resolved": "https://registry.npmjs.org/@gradio/atoms/-/atoms-0.2.1.tgz",
434
- "integrity": "sha512-di3kKSbjxKGngvTAaqUaA6whOVs5BFlQULlWDPq1m37VRgUD7Oq2MkIE+T+YiNAhByN93pqA0hGrWwAUUuxy5Q==",
435
- "dependencies": {
436
- "@gradio/icons": "^0.2.0",
437
- "@gradio/utils": "^0.2.0"
438
- }
439
- },
440
- "node_modules/@gradio/button/node_modules/@gradio/client": {
441
- "version": "0.7.2",
442
- "resolved": "https://registry.npmjs.org/@gradio/client/-/client-0.7.2.tgz",
443
- "integrity": "sha512-YkT3c0u38ZYPKvOCmT0xLu3Gau4SwMe1Yo0PNvqTLwHfI4++dp5MJIWH97820MUqgQhYy6V3GmVAliHRmnfPbw==",
444
- "dependencies": {
445
- "bufferutil": "^4.0.7",
446
- "semiver": "^1.1.0",
447
- "ws": "^8.13.0"
448
- },
449
- "engines": {
450
- "node": ">=18.0.0"
451
- }
452
- },
453
- "node_modules/@gradio/button/node_modules/@gradio/upload": {
454
- "version": "0.3.3",
455
- "resolved": "https://registry.npmjs.org/@gradio/upload/-/upload-0.3.3.tgz",
456
- "integrity": "sha512-KWRtH9UTe20u1/14KezuZDEwecLZzjDHdSPDUCrk27SrE6ptV8/qLtefOkg9zE+W51iATxDtQAvi0afLQ8XGrw==",
457
- "dependencies": {
458
- "@gradio/atoms": "^0.2.1",
459
- "@gradio/client": "^0.7.2",
460
- "@gradio/icons": "^0.2.0",
461
- "@gradio/upload": "^0.3.3",
462
- "@gradio/utils": "^0.2.0"
463
- }
464
- },
465
- "node_modules/@gradio/client": {
466
- "version": "0.7.1",
467
- "resolved": "https://registry.npmjs.org/@gradio/client/-/client-0.7.1.tgz",
468
- "integrity": "sha512-capRFmuk0EDI7oIGmRiSGZwcvsXEO9qnwUHBcSmawXPTPnuuZlBOMVERancuO8RO8PtUAozTgBCaLXP9TFhypQ==",
469
- "dependencies": {
470
- "bufferutil": "^4.0.7",
471
- "semiver": "^1.1.0",
472
- "ws": "^8.13.0"
473
- },
474
- "engines": {
475
- "node": ">=18.0.0"
476
- }
477
- },
478
- "node_modules/@gradio/column": {
479
- "version": "0.1.0",
480
- "resolved": "https://registry.npmjs.org/@gradio/column/-/column-0.1.0.tgz",
481
- "integrity": "sha512-P24nqqVnMXBaDA1f/zSN5HZRho4PxP8Dq+7VltPHlmxIEiZYik2AJ4J0LeuIha34FDO0guu/16evdrpvGIUAfw=="
482
- },
483
- "node_modules/@gradio/icons": {
484
- "version": "0.2.0",
485
- "resolved": "https://registry.npmjs.org/@gradio/icons/-/icons-0.2.0.tgz",
486
- "integrity": "sha512-rfCSmOF+ALqBOjTWL1ICasyA8JuO0MPwFrtlVMyAWp7R14AN8YChC/gbz5fZ0kNBiGGEYOOfqpKxyvC95jGGlg=="
487
- },
488
- "node_modules/@gradio/statustracker": {
489
- "version": "0.3.0",
490
- "resolved": "https://registry.npmjs.org/@gradio/statustracker/-/statustracker-0.3.0.tgz",
491
- "integrity": "sha512-8F3ezqPoGpq7B0EFYGVJkiYOrXCJLMEBcjLTOk2NeM2tXUoOCTieSvJEOstLzM0KkHwY7FvVrc3Dn5iqfIq2lQ==",
492
- "dependencies": {
493
- "@gradio/atoms": "^0.2.0",
494
- "@gradio/column": "^0.1.0",
495
- "@gradio/icons": "^0.2.0",
496
- "@gradio/utils": "^0.2.0"
497
- }
498
- },
499
- "node_modules/@gradio/theme": {
500
- "version": "0.2.0",
501
- "resolved": "https://registry.npmjs.org/@gradio/theme/-/theme-0.2.0.tgz",
502
- "integrity": "sha512-33c68Nk7oRXLn08OxPfjcPm7S4tXGOUV1I1bVgzdM2YV5o1QBOS1GEnXPZPu/CEYPePLMB6bsDwffrLEyLGWVQ=="
503
- },
504
- "node_modules/@gradio/upload": {
505
- "version": "0.3.2",
506
- "resolved": "https://registry.npmjs.org/@gradio/upload/-/upload-0.3.2.tgz",
507
- "integrity": "sha512-Yc5w8VZxLOVYhH1Kd3QsSUQM2SoKLom7tOn/xgY09/GnR47/AaEwPINJEHnm3DsV8FYj/dd5ggSEGTEBbR3Q2g==",
508
- "dependencies": {
509
- "@gradio/atoms": "^0.2.0",
510
- "@gradio/client": "^0.7.1",
511
- "@gradio/icons": "^0.2.0",
512
- "@gradio/upload": "^0.3.2",
513
- "@gradio/utils": "^0.2.0"
514
- }
515
- },
516
- "node_modules/@gradio/utils": {
517
- "version": "0.2.0",
518
- "resolved": "https://registry.npmjs.org/@gradio/utils/-/utils-0.2.0.tgz",
519
- "integrity": "sha512-YkwzXufi6IxQrlMW+1sFo8Yn6F9NLL69ZoBsbo7QEhms0v5L7pmOTw+dfd7M3dwbRP2lgjrb52i1kAIN3n6aqQ==",
520
- "dependencies": {
521
- "@gradio/theme": "^0.2.0",
522
- "svelte-i18n": "^3.6.0"
523
- }
524
- },
525
- "node_modules/@jridgewell/gen-mapping": {
526
- "version": "0.3.3",
527
- "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz",
528
- "integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==",
529
- "peer": true,
530
- "dependencies": {
531
- "@jridgewell/set-array": "^1.0.1",
532
- "@jridgewell/sourcemap-codec": "^1.4.10",
533
- "@jridgewell/trace-mapping": "^0.3.9"
534
- },
535
- "engines": {
536
- "node": ">=6.0.0"
537
- }
538
- },
539
- "node_modules/@jridgewell/resolve-uri": {
540
- "version": "3.1.1",
541
- "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz",
542
- "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==",
543
- "peer": true,
544
- "engines": {
545
- "node": ">=6.0.0"
546
- }
547
- },
548
- "node_modules/@jridgewell/set-array": {
549
- "version": "1.1.2",
550
- "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz",
551
- "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==",
552
- "peer": true,
553
- "engines": {
554
- "node": ">=6.0.0"
555
- }
556
- },
557
- "node_modules/@jridgewell/sourcemap-codec": {
558
- "version": "1.4.15",
559
- "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz",
560
- "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==",
561
- "peer": true
562
- },
563
- "node_modules/@jridgewell/trace-mapping": {
564
- "version": "0.3.20",
565
- "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz",
566
- "integrity": "sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==",
567
- "peer": true,
568
- "dependencies": {
569
- "@jridgewell/resolve-uri": "^3.1.0",
570
- "@jridgewell/sourcemap-codec": "^1.4.14"
571
- }
572
- },
573
- "node_modules/@mapbox/node-pre-gyp": {
574
- "version": "1.0.11",
575
- "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz",
576
- "integrity": "sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==",
577
- "dev": true,
578
- "optional": true,
579
- "dependencies": {
580
- "detect-libc": "^2.0.0",
581
- "https-proxy-agent": "^5.0.0",
582
- "make-dir": "^3.1.0",
583
- "node-fetch": "^2.6.7",
584
- "nopt": "^5.0.0",
585
- "npmlog": "^5.0.1",
586
- "rimraf": "^3.0.2",
587
- "semver": "^7.3.5",
588
- "tar": "^6.1.11"
589
- },
590
- "bin": {
591
- "node-pre-gyp": "bin/node-pre-gyp"
592
- }
593
- },
594
- "node_modules/@types/estree": {
595
- "version": "1.0.5",
596
- "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
597
- "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==",
598
- "peer": true
599
- },
600
- "node_modules/abbrev": {
601
- "version": "1.1.1",
602
- "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
603
- "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
604
- "dev": true,
605
- "optional": true
606
- },
607
- "node_modules/acorn": {
608
- "version": "8.11.2",
609
- "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz",
610
- "integrity": "sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==",
611
- "peer": true,
612
- "bin": {
613
- "acorn": "bin/acorn"
614
- },
615
- "engines": {
616
- "node": ">=0.4.0"
617
- }
618
- },
619
- "node_modules/agent-base": {
620
- "version": "6.0.2",
621
- "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
622
- "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
623
- "dev": true,
624
- "optional": true,
625
- "dependencies": {
626
- "debug": "4"
627
- },
628
- "engines": {
629
- "node": ">= 6.0.0"
630
- }
631
- },
632
- "node_modules/ansi-regex": {
633
- "version": "5.0.1",
634
- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
635
- "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
636
- "dev": true,
637
- "optional": true,
638
- "engines": {
639
- "node": ">=8"
640
- }
641
- },
642
- "node_modules/aproba": {
643
- "version": "2.0.0",
644
- "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz",
645
- "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==",
646
- "dev": true,
647
- "optional": true
648
- },
649
- "node_modules/are-we-there-yet": {
650
- "version": "2.0.0",
651
- "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz",
652
- "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==",
653
- "dev": true,
654
- "optional": true,
655
- "dependencies": {
656
- "delegates": "^1.0.0",
657
- "readable-stream": "^3.6.0"
658
- },
659
- "engines": {
660
- "node": ">=10"
661
- }
662
- },
663
- "node_modules/aria-query": {
664
- "version": "5.3.0",
665
- "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz",
666
- "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==",
667
- "peer": true,
668
- "dependencies": {
669
- "dequal": "^2.0.3"
670
- }
671
- },
672
- "node_modules/axobject-query": {
673
- "version": "3.2.1",
674
- "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz",
675
- "integrity": "sha512-jsyHu61e6N4Vbz/v18DHwWYKK0bSWLqn47eeDSKPB7m8tqMHF9YJ+mhIk2lVteyZrY8tnSj/jHOv4YiTCuCJgg==",
676
- "peer": true,
677
- "dependencies": {
678
- "dequal": "^2.0.3"
679
- }
680
- },
681
- "node_modules/balanced-match": {
682
- "version": "1.0.2",
683
- "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
684
- "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
685
- "dev": true,
686
- "optional": true
687
- },
688
- "node_modules/brace-expansion": {
689
- "version": "1.1.11",
690
- "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
691
- "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
692
- "dev": true,
693
- "optional": true,
694
- "dependencies": {
695
- "balanced-match": "^1.0.0",
696
- "concat-map": "0.0.1"
697
- }
698
- },
699
- "node_modules/bufferutil": {
700
- "version": "4.0.8",
701
- "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz",
702
- "integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==",
703
- "hasInstallScript": true,
704
- "dependencies": {
705
- "node-gyp-build": "^4.3.0"
706
- },
707
- "engines": {
708
- "node": ">=6.14.2"
709
- }
710
- },
711
- "node_modules/canvas": {
712
- "version": "2.11.2",
713
- "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.11.2.tgz",
714
- "integrity": "sha512-ItanGBMrmRV7Py2Z+Xhs7cT+FNt5K0vPL4p9EZ/UX/Mu7hFbkxSjKF2KVtPwX7UYWp7dRKnrTvReflgrItJbdw==",
715
- "dev": true,
716
- "hasInstallScript": true,
717
- "optional": true,
718
- "dependencies": {
719
- "@mapbox/node-pre-gyp": "^1.0.0",
720
- "nan": "^2.17.0",
721
- "simple-get": "^3.0.3"
722
- },
723
- "engines": {
724
- "node": ">=6"
725
- }
726
- },
727
- "node_modules/chownr": {
728
- "version": "2.0.0",
729
- "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
730
- "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
731
- "dev": true,
732
- "optional": true,
733
- "engines": {
734
- "node": ">=10"
735
- }
736
- },
737
- "node_modules/cli-color": {
738
- "version": "2.0.3",
739
- "resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.3.tgz",
740
- "integrity": "sha512-OkoZnxyC4ERN3zLzZaY9Emb7f/MhBOIpePv0Ycok0fJYT+Ouo00UBEIwsVsr0yoow++n5YWlSUgST9GKhNHiRQ==",
741
- "dependencies": {
742
- "d": "^1.0.1",
743
- "es5-ext": "^0.10.61",
744
- "es6-iterator": "^2.0.3",
745
- "memoizee": "^0.4.15",
746
- "timers-ext": "^0.1.7"
747
- },
748
- "engines": {
749
- "node": ">=0.10"
750
- }
751
- },
752
- "node_modules/code-red": {
753
- "version": "1.0.4",
754
- "resolved": "https://registry.npmjs.org/code-red/-/code-red-1.0.4.tgz",
755
- "integrity": "sha512-7qJWqItLA8/VPVlKJlFXU+NBlo/qyfs39aJcuMT/2ere32ZqvF5OSxgdM5xOfJJ7O429gg2HM47y8v9P+9wrNw==",
756
- "peer": true,
757
- "dependencies": {
758
- "@jridgewell/sourcemap-codec": "^1.4.15",
759
- "@types/estree": "^1.0.1",
760
- "acorn": "^8.10.0",
761
- "estree-walker": "^3.0.3",
762
- "periscopic": "^3.1.0"
763
- }
764
- },
765
- "node_modules/color-support": {
766
- "version": "1.1.3",
767
- "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
768
- "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==",
769
- "dev": true,
770
- "optional": true,
771
- "bin": {
772
- "color-support": "bin.js"
773
- }
774
- },
775
- "node_modules/concat-map": {
776
- "version": "0.0.1",
777
- "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
778
- "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
779
- "dev": true,
780
- "optional": true
781
- },
782
- "node_modules/console-control-strings": {
783
- "version": "1.1.0",
784
- "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
785
- "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==",
786
- "dev": true,
787
- "optional": true
788
- },
789
- "node_modules/css-tree": {
790
- "version": "2.3.1",
791
- "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz",
792
- "integrity": "sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==",
793
- "peer": true,
794
- "dependencies": {
795
- "mdn-data": "2.0.30",
796
- "source-map-js": "^1.0.1"
797
- },
798
- "engines": {
799
- "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0"
800
- }
801
- },
802
- "node_modules/d": {
803
- "version": "1.0.1",
804
- "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz",
805
- "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==",
806
- "dependencies": {
807
- "es5-ext": "^0.10.50",
808
- "type": "^1.0.1"
809
- }
810
- },
811
- "node_modules/debug": {
812
- "version": "4.3.4",
813
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
814
- "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
815
- "dev": true,
816
- "optional": true,
817
- "dependencies": {
818
- "ms": "2.1.2"
819
- },
820
- "engines": {
821
- "node": ">=6.0"
822
- },
823
- "peerDependenciesMeta": {
824
- "supports-color": {
825
- "optional": true
826
- }
827
- }
828
- },
829
- "node_modules/decompress-response": {
830
- "version": "4.2.1",
831
- "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz",
832
- "integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==",
833
- "dev": true,
834
- "optional": true,
835
- "dependencies": {
836
- "mimic-response": "^2.0.0"
837
- },
838
- "engines": {
839
- "node": ">=8"
840
- }
841
- },
842
- "node_modules/deepmerge": {
843
- "version": "4.3.1",
844
- "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",
845
- "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==",
846
- "engines": {
847
- "node": ">=0.10.0"
848
- }
849
- },
850
- "node_modules/delegates": {
851
- "version": "1.0.0",
852
- "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
853
- "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==",
854
- "dev": true,
855
- "optional": true
856
- },
857
- "node_modules/dequal": {
858
- "version": "2.0.3",
859
- "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz",
860
- "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==",
861
- "peer": true,
862
- "engines": {
863
- "node": ">=6"
864
- }
865
- },
866
- "node_modules/detect-libc": {
867
- "version": "2.0.2",
868
- "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz",
869
- "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==",
870
- "dev": true,
871
- "optional": true,
872
- "engines": {
873
- "node": ">=8"
874
- }
875
- },
876
- "node_modules/emoji-regex": {
877
- "version": "8.0.0",
878
- "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
879
- "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
880
- "dev": true,
881
- "optional": true
882
- },
883
- "node_modules/es5-ext": {
884
- "version": "0.10.62",
885
- "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.62.tgz",
886
- "integrity": "sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==",
887
- "hasInstallScript": true,
888
- "dependencies": {
889
- "es6-iterator": "^2.0.3",
890
- "es6-symbol": "^3.1.3",
891
- "next-tick": "^1.1.0"
892
- },
893
- "engines": {
894
- "node": ">=0.10"
895
- }
896
- },
897
- "node_modules/es6-iterator": {
898
- "version": "2.0.3",
899
- "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
900
- "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==",
901
- "dependencies": {
902
- "d": "1",
903
- "es5-ext": "^0.10.35",
904
- "es6-symbol": "^3.1.1"
905
- }
906
- },
907
- "node_modules/es6-symbol": {
908
- "version": "3.1.3",
909
- "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz",
910
- "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==",
911
- "dependencies": {
912
- "d": "^1.0.1",
913
- "ext": "^1.1.2"
914
- }
915
- },
916
- "node_modules/es6-weak-map": {
917
- "version": "2.0.3",
918
- "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz",
919
- "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==",
920
- "dependencies": {
921
- "d": "1",
922
- "es5-ext": "^0.10.46",
923
- "es6-iterator": "^2.0.3",
924
- "es6-symbol": "^3.1.1"
925
- }
926
- },
927
- "node_modules/esbuild": {
928
- "version": "0.19.5",
929
- "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.5.tgz",
930
- "integrity": "sha512-bUxalY7b1g8vNhQKdB24QDmHeY4V4tw/s6Ak5z+jJX9laP5MoQseTOMemAr0gxssjNcH0MCViG8ONI2kksvfFQ==",
931
- "hasInstallScript": true,
932
- "bin": {
933
- "esbuild": "bin/esbuild"
934
- },
935
- "engines": {
936
- "node": ">=12"
937
- },
938
- "optionalDependencies": {
939
- "@esbuild/android-arm": "0.19.5",
940
- "@esbuild/android-arm64": "0.19.5",
941
- "@esbuild/android-x64": "0.19.5",
942
- "@esbuild/darwin-arm64": "0.19.5",
943
- "@esbuild/darwin-x64": "0.19.5",
944
- "@esbuild/freebsd-arm64": "0.19.5",
945
- "@esbuild/freebsd-x64": "0.19.5",
946
- "@esbuild/linux-arm": "0.19.5",
947
- "@esbuild/linux-arm64": "0.19.5",
948
- "@esbuild/linux-ia32": "0.19.5",
949
- "@esbuild/linux-loong64": "0.19.5",
950
- "@esbuild/linux-mips64el": "0.19.5",
951
- "@esbuild/linux-ppc64": "0.19.5",
952
- "@esbuild/linux-riscv64": "0.19.5",
953
- "@esbuild/linux-s390x": "0.19.5",
954
- "@esbuild/linux-x64": "0.19.5",
955
- "@esbuild/netbsd-x64": "0.19.5",
956
- "@esbuild/openbsd-x64": "0.19.5",
957
- "@esbuild/sunos-x64": "0.19.5",
958
- "@esbuild/win32-arm64": "0.19.5",
959
- "@esbuild/win32-ia32": "0.19.5",
960
- "@esbuild/win32-x64": "0.19.5"
961
- }
962
- },
963
- "node_modules/estree-walker": {
964
- "version": "3.0.3",
965
- "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
966
- "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
967
- "peer": true,
968
- "dependencies": {
969
- "@types/estree": "^1.0.0"
970
- }
971
- },
972
- "node_modules/event-emitter": {
973
- "version": "0.3.5",
974
- "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz",
975
- "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==",
976
- "dependencies": {
977
- "d": "1",
978
- "es5-ext": "~0.10.14"
979
- }
980
- },
981
- "node_modules/ext": {
982
- "version": "1.7.0",
983
- "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz",
984
- "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==",
985
- "dependencies": {
986
- "type": "^2.7.2"
987
- }
988
- },
989
- "node_modules/ext/node_modules/type": {
990
- "version": "2.7.2",
991
- "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz",
992
- "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw=="
993
- },
994
- "node_modules/fs-minipass": {
995
- "version": "2.1.0",
996
- "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
997
- "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==",
998
- "dev": true,
999
- "optional": true,
1000
- "dependencies": {
1001
- "minipass": "^3.0.0"
1002
- },
1003
- "engines": {
1004
- "node": ">= 8"
1005
- }
1006
- },
1007
- "node_modules/fs-minipass/node_modules/minipass": {
1008
- "version": "3.3.6",
1009
- "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz",
1010
- "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==",
1011
- "dev": true,
1012
- "optional": true,
1013
- "dependencies": {
1014
- "yallist": "^4.0.0"
1015
- },
1016
- "engines": {
1017
- "node": ">=8"
1018
- }
1019
- },
1020
- "node_modules/fs.realpath": {
1021
- "version": "1.0.0",
1022
- "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
1023
- "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
1024
- "dev": true,
1025
- "optional": true
1026
- },
1027
- "node_modules/gauge": {
1028
- "version": "3.0.2",
1029
- "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz",
1030
- "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==",
1031
- "dev": true,
1032
- "optional": true,
1033
- "dependencies": {
1034
- "aproba": "^1.0.3 || ^2.0.0",
1035
- "color-support": "^1.1.2",
1036
- "console-control-strings": "^1.0.0",
1037
- "has-unicode": "^2.0.1",
1038
- "object-assign": "^4.1.1",
1039
- "signal-exit": "^3.0.0",
1040
- "string-width": "^4.2.3",
1041
- "strip-ansi": "^6.0.1",
1042
- "wide-align": "^1.1.2"
1043
- },
1044
- "engines": {
1045
- "node": ">=10"
1046
- }
1047
- },
1048
- "node_modules/glob": {
1049
- "version": "7.2.3",
1050
- "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
1051
- "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
1052
- "dev": true,
1053
- "optional": true,
1054
- "dependencies": {
1055
- "fs.realpath": "^1.0.0",
1056
- "inflight": "^1.0.4",
1057
- "inherits": "2",
1058
- "minimatch": "^3.1.1",
1059
- "once": "^1.3.0",
1060
- "path-is-absolute": "^1.0.0"
1061
- },
1062
- "engines": {
1063
- "node": "*"
1064
- },
1065
- "funding": {
1066
- "url": "https://github.com/sponsors/isaacs"
1067
- }
1068
- },
1069
- "node_modules/globalyzer": {
1070
- "version": "0.1.0",
1071
- "resolved": "https://registry.npmjs.org/globalyzer/-/globalyzer-0.1.0.tgz",
1072
- "integrity": "sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q=="
1073
- },
1074
- "node_modules/globrex": {
1075
- "version": "0.1.2",
1076
- "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz",
1077
- "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg=="
1078
- },
1079
- "node_modules/has-unicode": {
1080
- "version": "2.0.1",
1081
- "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
1082
- "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==",
1083
- "dev": true,
1084
- "optional": true
1085
- },
1086
- "node_modules/https-proxy-agent": {
1087
- "version": "5.0.1",
1088
- "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
1089
- "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==",
1090
- "dev": true,
1091
- "optional": true,
1092
- "dependencies": {
1093
- "agent-base": "6",
1094
- "debug": "4"
1095
- },
1096
- "engines": {
1097
- "node": ">= 6"
1098
- }
1099
- },
1100
- "node_modules/inflight": {
1101
- "version": "1.0.6",
1102
- "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
1103
- "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
1104
- "dev": true,
1105
- "optional": true,
1106
- "dependencies": {
1107
- "once": "^1.3.0",
1108
- "wrappy": "1"
1109
- }
1110
- },
1111
- "node_modules/inherits": {
1112
- "version": "2.0.4",
1113
- "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
1114
- "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
1115
- "dev": true,
1116
- "optional": true
1117
- },
1118
- "node_modules/intl-messageformat": {
1119
- "version": "9.13.0",
1120
- "resolved": "https://registry.npmjs.org/intl-messageformat/-/intl-messageformat-9.13.0.tgz",
1121
- "integrity": "sha512-7sGC7QnSQGa5LZP7bXLDhVDtQOeKGeBFGHF2Y8LVBwYZoQZCgWeKoPGTa5GMG8g/TzDgeXuYJQis7Ggiw2xTOw==",
1122
- "dependencies": {
1123
- "@formatjs/ecma402-abstract": "1.11.4",
1124
- "@formatjs/fast-memoize": "1.2.1",
1125
- "@formatjs/icu-messageformat-parser": "2.1.0",
1126
- "tslib": "^2.1.0"
1127
- }
1128
- },
1129
- "node_modules/is-fullwidth-code-point": {
1130
- "version": "3.0.0",
1131
- "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
1132
- "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
1133
- "dev": true,
1134
- "optional": true,
1135
- "engines": {
1136
- "node": ">=8"
1137
- }
1138
- },
1139
- "node_modules/is-promise": {
1140
- "version": "2.2.2",
1141
- "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz",
1142
- "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ=="
1143
- },
1144
- "node_modules/is-reference": {
1145
- "version": "3.0.2",
1146
- "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-3.0.2.tgz",
1147
- "integrity": "sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==",
1148
- "peer": true,
1149
- "dependencies": {
1150
- "@types/estree": "*"
1151
- }
1152
- },
1153
- "node_modules/locate-character": {
1154
- "version": "3.0.0",
1155
- "resolved": "https://registry.npmjs.org/locate-character/-/locate-character-3.0.0.tgz",
1156
- "integrity": "sha512-SW13ws7BjaeJ6p7Q6CO2nchbYEc3X3J6WrmTTDto7yMPqVSZTUyY5Tjbid+Ab8gLnATtygYtiDIJGQRRn2ZOiA==",
1157
- "peer": true
1158
- },
1159
- "node_modules/lru-cache": {
1160
- "version": "6.0.0",
1161
- "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
1162
- "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
1163
- "dev": true,
1164
- "optional": true,
1165
- "dependencies": {
1166
- "yallist": "^4.0.0"
1167
- },
1168
- "engines": {
1169
- "node": ">=10"
1170
- }
1171
- },
1172
- "node_modules/lru-queue": {
1173
- "version": "0.1.0",
1174
- "resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz",
1175
- "integrity": "sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==",
1176
- "dependencies": {
1177
- "es5-ext": "~0.10.2"
1178
- }
1179
- },
1180
- "node_modules/magic-string": {
1181
- "version": "0.30.5",
1182
- "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.5.tgz",
1183
- "integrity": "sha512-7xlpfBaQaP/T6Vh8MO/EqXSW5En6INHEvEXQiuff7Gku0PWjU3uf6w/j9o7O+SpB5fOAkrI5HeoNgwjEO0pFsA==",
1184
- "peer": true,
1185
- "dependencies": {
1186
- "@jridgewell/sourcemap-codec": "^1.4.15"
1187
- },
1188
- "engines": {
1189
- "node": ">=12"
1190
- }
1191
- },
1192
- "node_modules/make-dir": {
1193
- "version": "3.1.0",
1194
- "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
1195
- "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==",
1196
- "dev": true,
1197
- "optional": true,
1198
- "dependencies": {
1199
- "semver": "^6.0.0"
1200
- },
1201
- "engines": {
1202
- "node": ">=8"
1203
- },
1204
- "funding": {
1205
- "url": "https://github.com/sponsors/sindresorhus"
1206
- }
1207
- },
1208
- "node_modules/make-dir/node_modules/semver": {
1209
- "version": "6.3.1",
1210
- "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
1211
- "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
1212
- "dev": true,
1213
- "optional": true,
1214
- "bin": {
1215
- "semver": "bin/semver.js"
1216
- }
1217
- },
1218
- "node_modules/mdn-data": {
1219
- "version": "2.0.30",
1220
- "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz",
1221
- "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==",
1222
- "peer": true
1223
- },
1224
- "node_modules/memoizee": {
1225
- "version": "0.4.15",
1226
- "resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.15.tgz",
1227
- "integrity": "sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==",
1228
- "dependencies": {
1229
- "d": "^1.0.1",
1230
- "es5-ext": "^0.10.53",
1231
- "es6-weak-map": "^2.0.3",
1232
- "event-emitter": "^0.3.5",
1233
- "is-promise": "^2.2.2",
1234
- "lru-queue": "^0.1.0",
1235
- "next-tick": "^1.1.0",
1236
- "timers-ext": "^0.1.7"
1237
- }
1238
- },
1239
- "node_modules/mimic-response": {
1240
- "version": "2.1.0",
1241
- "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz",
1242
- "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==",
1243
- "dev": true,
1244
- "optional": true,
1245
- "engines": {
1246
- "node": ">=8"
1247
- },
1248
- "funding": {
1249
- "url": "https://github.com/sponsors/sindresorhus"
1250
- }
1251
- },
1252
- "node_modules/minimatch": {
1253
- "version": "3.1.2",
1254
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
1255
- "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
1256
- "dev": true,
1257
- "optional": true,
1258
- "dependencies": {
1259
- "brace-expansion": "^1.1.7"
1260
- },
1261
- "engines": {
1262
- "node": "*"
1263
- }
1264
- },
1265
- "node_modules/minipass": {
1266
- "version": "5.0.0",
1267
- "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz",
1268
- "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==",
1269
- "dev": true,
1270
- "optional": true,
1271
- "engines": {
1272
- "node": ">=8"
1273
- }
1274
- },
1275
- "node_modules/minizlib": {
1276
- "version": "2.1.2",
1277
- "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz",
1278
- "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==",
1279
- "dev": true,
1280
- "optional": true,
1281
- "dependencies": {
1282
- "minipass": "^3.0.0",
1283
- "yallist": "^4.0.0"
1284
- },
1285
- "engines": {
1286
- "node": ">= 8"
1287
- }
1288
- },
1289
- "node_modules/minizlib/node_modules/minipass": {
1290
- "version": "3.3.6",
1291
- "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz",
1292
- "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==",
1293
- "dev": true,
1294
- "optional": true,
1295
- "dependencies": {
1296
- "yallist": "^4.0.0"
1297
- },
1298
- "engines": {
1299
- "node": ">=8"
1300
- }
1301
- },
1302
- "node_modules/mkdirp": {
1303
- "version": "1.0.4",
1304
- "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
1305
- "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
1306
- "dev": true,
1307
- "optional": true,
1308
- "bin": {
1309
- "mkdirp": "bin/cmd.js"
1310
- },
1311
- "engines": {
1312
- "node": ">=10"
1313
- }
1314
- },
1315
- "node_modules/mri": {
1316
- "version": "1.2.0",
1317
- "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
1318
- "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==",
1319
- "engines": {
1320
- "node": ">=4"
1321
- }
1322
- },
1323
- "node_modules/ms": {
1324
- "version": "2.1.2",
1325
- "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
1326
- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
1327
- "dev": true,
1328
- "optional": true
1329
- },
1330
- "node_modules/nan": {
1331
- "version": "2.18.0",
1332
- "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz",
1333
- "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==",
1334
- "dev": true,
1335
- "optional": true
1336
- },
1337
- "node_modules/next-tick": {
1338
- "version": "1.1.0",
1339
- "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
1340
- "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ=="
1341
- },
1342
- "node_modules/node-fetch": {
1343
- "version": "2.7.0",
1344
- "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
1345
- "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
1346
- "dev": true,
1347
- "optional": true,
1348
- "dependencies": {
1349
- "whatwg-url": "^5.0.0"
1350
- },
1351
- "engines": {
1352
- "node": "4.x || >=6.0.0"
1353
- },
1354
- "peerDependencies": {
1355
- "encoding": "^0.1.0"
1356
- },
1357
- "peerDependenciesMeta": {
1358
- "encoding": {
1359
- "optional": true
1360
- }
1361
- }
1362
- },
1363
- "node_modules/node-gyp-build": {
1364
- "version": "4.6.1",
1365
- "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.1.tgz",
1366
- "integrity": "sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ==",
1367
- "bin": {
1368
- "node-gyp-build": "bin.js",
1369
- "node-gyp-build-optional": "optional.js",
1370
- "node-gyp-build-test": "build-test.js"
1371
- }
1372
- },
1373
- "node_modules/nopt": {
1374
- "version": "5.0.0",
1375
- "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
1376
- "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==",
1377
- "dev": true,
1378
- "optional": true,
1379
- "dependencies": {
1380
- "abbrev": "1"
1381
- },
1382
- "bin": {
1383
- "nopt": "bin/nopt.js"
1384
- },
1385
- "engines": {
1386
- "node": ">=6"
1387
- }
1388
- },
1389
- "node_modules/npmlog": {
1390
- "version": "5.0.1",
1391
- "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz",
1392
- "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==",
1393
- "dev": true,
1394
- "optional": true,
1395
- "dependencies": {
1396
- "are-we-there-yet": "^2.0.0",
1397
- "console-control-strings": "^1.1.0",
1398
- "gauge": "^3.0.0",
1399
- "set-blocking": "^2.0.0"
1400
- }
1401
- },
1402
- "node_modules/object-assign": {
1403
- "version": "4.1.1",
1404
- "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
1405
- "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
1406
- "dev": true,
1407
- "optional": true,
1408
- "engines": {
1409
- "node": ">=0.10.0"
1410
- }
1411
- },
1412
- "node_modules/once": {
1413
- "version": "1.4.0",
1414
- "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
1415
- "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
1416
- "dev": true,
1417
- "optional": true,
1418
- "dependencies": {
1419
- "wrappy": "1"
1420
- }
1421
- },
1422
- "node_modules/path-is-absolute": {
1423
- "version": "1.0.1",
1424
- "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
1425
- "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
1426
- "dev": true,
1427
- "optional": true,
1428
- "engines": {
1429
- "node": ">=0.10.0"
1430
- }
1431
- },
1432
- "node_modules/path2d-polyfill": {
1433
- "version": "2.0.1",
1434
- "resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.0.1.tgz",
1435
- "integrity": "sha512-ad/3bsalbbWhmBo0D6FZ4RNMwsLsPpL6gnvhuSaU5Vm7b06Kr5ubSltQQ0T7YKsiJQO+g22zJ4dJKNTXIyOXtA==",
1436
- "dev": true,
1437
- "optional": true,
1438
- "engines": {
1439
- "node": ">=8"
1440
- }
1441
- },
1442
- "node_modules/pdfjs-dist": {
1443
- "version": "3.11.174",
1444
- "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-3.11.174.tgz",
1445
- "integrity": "sha512-TdTZPf1trZ8/UFu5Cx/GXB7GZM30LT+wWUNfsi6Bq8ePLnb+woNKtDymI2mxZYBpMbonNFqKmiz684DIfnd8dA==",
1446
- "dev": true,
1447
- "engines": {
1448
- "node": ">=18"
1449
- },
1450
- "optionalDependencies": {
1451
- "canvas": "^2.11.2",
1452
- "path2d-polyfill": "^2.0.1"
1453
- }
1454
- },
1455
- "node_modules/periscopic": {
1456
- "version": "3.1.0",
1457
- "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-3.1.0.tgz",
1458
- "integrity": "sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw==",
1459
- "peer": true,
1460
- "dependencies": {
1461
- "@types/estree": "^1.0.0",
1462
- "estree-walker": "^3.0.0",
1463
- "is-reference": "^3.0.0"
1464
- }
1465
- },
1466
- "node_modules/readable-stream": {
1467
- "version": "3.6.2",
1468
- "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
1469
- "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
1470
- "dev": true,
1471
- "optional": true,
1472
- "dependencies": {
1473
- "inherits": "^2.0.3",
1474
- "string_decoder": "^1.1.1",
1475
- "util-deprecate": "^1.0.1"
1476
- },
1477
- "engines": {
1478
- "node": ">= 6"
1479
- }
1480
- },
1481
- "node_modules/rimraf": {
1482
- "version": "3.0.2",
1483
- "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
1484
- "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
1485
- "dev": true,
1486
- "optional": true,
1487
- "dependencies": {
1488
- "glob": "^7.1.3"
1489
- },
1490
- "bin": {
1491
- "rimraf": "bin.js"
1492
- },
1493
- "funding": {
1494
- "url": "https://github.com/sponsors/isaacs"
1495
- }
1496
- },
1497
- "node_modules/sade": {
1498
- "version": "1.8.1",
1499
- "resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz",
1500
- "integrity": "sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==",
1501
- "dependencies": {
1502
- "mri": "^1.1.0"
1503
- },
1504
- "engines": {
1505
- "node": ">=6"
1506
- }
1507
- },
1508
- "node_modules/safe-buffer": {
1509
- "version": "5.2.1",
1510
- "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
1511
- "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
1512
- "dev": true,
1513
- "funding": [
1514
- {
1515
- "type": "github",
1516
- "url": "https://github.com/sponsors/feross"
1517
- },
1518
- {
1519
- "type": "patreon",
1520
- "url": "https://www.patreon.com/feross"
1521
- },
1522
- {
1523
- "type": "consulting",
1524
- "url": "https://feross.org/support"
1525
- }
1526
- ],
1527
- "optional": true
1528
- },
1529
- "node_modules/semiver": {
1530
- "version": "1.1.0",
1531
- "resolved": "https://registry.npmjs.org/semiver/-/semiver-1.1.0.tgz",
1532
- "integrity": "sha512-QNI2ChmuioGC1/xjyYwyZYADILWyW6AmS1UH6gDj/SFUUUS4MBAWs/7mxnkRPc/F4iHezDP+O8t0dO8WHiEOdg==",
1533
- "engines": {
1534
- "node": ">=6"
1535
- }
1536
- },
1537
- "node_modules/semver": {
1538
- "version": "7.5.4",
1539
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
1540
- "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
1541
- "dev": true,
1542
- "optional": true,
1543
- "dependencies": {
1544
- "lru-cache": "^6.0.0"
1545
- },
1546
- "bin": {
1547
- "semver": "bin/semver.js"
1548
- },
1549
- "engines": {
1550
- "node": ">=10"
1551
- }
1552
- },
1553
- "node_modules/set-blocking": {
1554
- "version": "2.0.0",
1555
- "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
1556
- "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==",
1557
- "dev": true,
1558
- "optional": true
1559
- },
1560
- "node_modules/signal-exit": {
1561
- "version": "3.0.7",
1562
- "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
1563
- "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
1564
- "dev": true,
1565
- "optional": true
1566
- },
1567
- "node_modules/simple-concat": {
1568
- "version": "1.0.1",
1569
- "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
1570
- "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==",
1571
- "dev": true,
1572
- "funding": [
1573
- {
1574
- "type": "github",
1575
- "url": "https://github.com/sponsors/feross"
1576
- },
1577
- {
1578
- "type": "patreon",
1579
- "url": "https://www.patreon.com/feross"
1580
- },
1581
- {
1582
- "type": "consulting",
1583
- "url": "https://feross.org/support"
1584
- }
1585
- ],
1586
- "optional": true
1587
- },
1588
- "node_modules/simple-get": {
1589
- "version": "3.1.1",
1590
- "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.1.tgz",
1591
- "integrity": "sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==",
1592
- "dev": true,
1593
- "optional": true,
1594
- "dependencies": {
1595
- "decompress-response": "^4.2.0",
1596
- "once": "^1.3.1",
1597
- "simple-concat": "^1.0.0"
1598
- }
1599
- },
1600
- "node_modules/source-map-js": {
1601
- "version": "1.0.2",
1602
- "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
1603
- "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==",
1604
- "peer": true,
1605
- "engines": {
1606
- "node": ">=0.10.0"
1607
- }
1608
- },
1609
- "node_modules/string_decoder": {
1610
- "version": "1.3.0",
1611
- "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
1612
- "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
1613
- "dev": true,
1614
- "optional": true,
1615
- "dependencies": {
1616
- "safe-buffer": "~5.2.0"
1617
- }
1618
- },
1619
- "node_modules/string-width": {
1620
- "version": "4.2.3",
1621
- "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
1622
- "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
1623
- "dev": true,
1624
- "optional": true,
1625
- "dependencies": {
1626
- "emoji-regex": "^8.0.0",
1627
- "is-fullwidth-code-point": "^3.0.0",
1628
- "strip-ansi": "^6.0.1"
1629
- },
1630
- "engines": {
1631
- "node": ">=8"
1632
- }
1633
- },
1634
- "node_modules/strip-ansi": {
1635
- "version": "6.0.1",
1636
- "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
1637
- "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
1638
- "dev": true,
1639
- "optional": true,
1640
- "dependencies": {
1641
- "ansi-regex": "^5.0.1"
1642
- },
1643
- "engines": {
1644
- "node": ">=8"
1645
- }
1646
- },
1647
- "node_modules/svelte": {
1648
- "version": "4.2.2",
1649
- "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.2.tgz",
1650
- "integrity": "sha512-My2tytF2e2NnHSpn2M7/3VdXT4JdTglYVUuSuK/mXL2XtulPYbeBfl8Dm1QiaKRn0zoULRnL+EtfZHHP0k4H3A==",
1651
- "peer": true,
1652
- "dependencies": {
1653
- "@ampproject/remapping": "^2.2.1",
1654
- "@jridgewell/sourcemap-codec": "^1.4.15",
1655
- "@jridgewell/trace-mapping": "^0.3.18",
1656
- "acorn": "^8.9.0",
1657
- "aria-query": "^5.3.0",
1658
- "axobject-query": "^3.2.1",
1659
- "code-red": "^1.0.3",
1660
- "css-tree": "^2.3.1",
1661
- "estree-walker": "^3.0.3",
1662
- "is-reference": "^3.0.1",
1663
- "locate-character": "^3.0.0",
1664
- "magic-string": "^0.30.4",
1665
- "periscopic": "^3.1.0"
1666
- },
1667
- "engines": {
1668
- "node": ">=16"
1669
- }
1670
- },
1671
- "node_modules/svelte-i18n": {
1672
- "version": "3.7.4",
1673
- "resolved": "https://registry.npmjs.org/svelte-i18n/-/svelte-i18n-3.7.4.tgz",
1674
- "integrity": "sha512-yGRCNo+eBT4cPuU7IVsYTYjxB7I2V8qgUZPlHnNctJj5IgbJgV78flsRzpjZ/8iUYZrS49oCt7uxlU3AZv/N5Q==",
1675
- "dependencies": {
1676
- "cli-color": "^2.0.3",
1677
- "deepmerge": "^4.2.2",
1678
- "esbuild": "^0.19.2",
1679
- "estree-walker": "^2",
1680
- "intl-messageformat": "^9.13.0",
1681
- "sade": "^1.8.1",
1682
- "tiny-glob": "^0.2.9"
1683
- },
1684
- "bin": {
1685
- "svelte-i18n": "dist/cli.js"
1686
- },
1687
- "engines": {
1688
- "node": ">= 16"
1689
- },
1690
- "peerDependencies": {
1691
- "svelte": "^3 || ^4"
1692
- }
1693
- },
1694
- "node_modules/svelte-i18n/node_modules/estree-walker": {
1695
- "version": "2.0.2",
1696
- "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
1697
- "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w=="
1698
- },
1699
- "node_modules/tar": {
1700
- "version": "6.2.0",
1701
- "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz",
1702
- "integrity": "sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==",
1703
- "dev": true,
1704
- "optional": true,
1705
- "dependencies": {
1706
- "chownr": "^2.0.0",
1707
- "fs-minipass": "^2.0.0",
1708
- "minipass": "^5.0.0",
1709
- "minizlib": "^2.1.1",
1710
- "mkdirp": "^1.0.3",
1711
- "yallist": "^4.0.0"
1712
- },
1713
- "engines": {
1714
- "node": ">=10"
1715
- }
1716
- },
1717
- "node_modules/timers-ext": {
1718
- "version": "0.1.7",
1719
- "resolved": "https://registry.npmjs.org/timers-ext/-/timers-ext-0.1.7.tgz",
1720
- "integrity": "sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==",
1721
- "dependencies": {
1722
- "es5-ext": "~0.10.46",
1723
- "next-tick": "1"
1724
- }
1725
- },
1726
- "node_modules/tiny-glob": {
1727
- "version": "0.2.9",
1728
- "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz",
1729
- "integrity": "sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==",
1730
- "dependencies": {
1731
- "globalyzer": "0.1.0",
1732
- "globrex": "^0.1.2"
1733
- }
1734
- },
1735
- "node_modules/tr46": {
1736
- "version": "0.0.3",
1737
- "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
1738
- "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
1739
- "dev": true,
1740
- "optional": true
1741
- },
1742
- "node_modules/tslib": {
1743
- "version": "2.6.2",
1744
- "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
1745
- "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
1746
- },
1747
- "node_modules/type": {
1748
- "version": "1.2.0",
1749
- "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz",
1750
- "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg=="
1751
- },
1752
- "node_modules/util-deprecate": {
1753
- "version": "1.0.2",
1754
- "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
1755
- "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
1756
- "dev": true,
1757
- "optional": true
1758
- },
1759
- "node_modules/webidl-conversions": {
1760
- "version": "3.0.1",
1761
- "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
1762
- "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
1763
- "dev": true,
1764
- "optional": true
1765
- },
1766
- "node_modules/whatwg-url": {
1767
- "version": "5.0.0",
1768
- "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
1769
- "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
1770
- "dev": true,
1771
- "optional": true,
1772
- "dependencies": {
1773
- "tr46": "~0.0.3",
1774
- "webidl-conversions": "^3.0.0"
1775
- }
1776
- },
1777
- "node_modules/wide-align": {
1778
- "version": "1.1.5",
1779
- "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz",
1780
- "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==",
1781
- "dev": true,
1782
- "optional": true,
1783
- "dependencies": {
1784
- "string-width": "^1.0.2 || 2 || 3 || 4"
1785
- }
1786
- },
1787
- "node_modules/wrappy": {
1788
- "version": "1.0.2",
1789
- "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
1790
- "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
1791
- "dev": true,
1792
- "optional": true
1793
- },
1794
- "node_modules/ws": {
1795
- "version": "8.14.2",
1796
- "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz",
1797
- "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==",
1798
- "engines": {
1799
- "node": ">=10.0.0"
1800
- },
1801
- "peerDependencies": {
1802
- "bufferutil": "^4.0.1",
1803
- "utf-8-validate": ">=5.0.2"
1804
- },
1805
- "peerDependenciesMeta": {
1806
- "bufferutil": {
1807
- "optional": true
1808
- },
1809
- "utf-8-validate": {
1810
- "optional": true
1811
- }
1812
- }
1813
- },
1814
- "node_modules/yallist": {
1815
- "version": "4.0.0",
1816
- "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
1817
- "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
1818
- "dev": true,
1819
- "optional": true
1820
- }
1821
- }
1822
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/frontend/package.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "name": "gradio_pdf",
3
- "version": "0.2.0",
4
- "description": "Gradio UI packages",
5
- "type": "module",
6
- "author": "",
7
- "license": "ISC",
8
- "private": false,
9
- "main_changeset": true,
10
- "exports": {
11
- ".": "./Index.svelte",
12
- "./example": "./Example.svelte",
13
- "./package.json": "./package.json"
14
- },
15
- "devDependencies": {
16
- "pdfjs-dist": "3.11.174"
17
- },
18
- "dependencies": {
19
- "@gradio/atoms": "0.2.0",
20
- "@gradio/statustracker": "0.3.0",
21
- "@gradio/utils": "0.2.0",
22
- "@gradio/client": "0.7.1",
23
- "@gradio/upload": "0.3.2",
24
- "@gradio/icons": "0.2.0",
25
- "@gradio/button": "0.2.3",
26
- "pdfjs-dist": "3.11.174"
27
- }
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/pyproject.toml DELETED
@@ -1,53 +0,0 @@
1
- [build-system]
2
- requires = [
3
- "hatchling",
4
- "hatch-requirements-txt",
5
- "hatch-fancy-pypi-readme>=22.5.0",
6
- ]
7
- build-backend = "hatchling.build"
8
-
9
- [project]
10
- name = "gradio_pdf"
11
- version = "0.0.4"
12
- description = "Easily display PDFs in Gradio"
13
- readme = "README.md"
14
- license = "Apache-2.0"
15
- requires-python = ">=3.8"
16
- authors = [{ name = "Freddy Boulton", email = "[email protected]" }]
17
- keywords = [
18
- "Documents",
19
- "PDF",
20
- "Document QA",
21
- "gradio",
22
- "gradio custom component",
23
- "gradio-template-Fallback"
24
- ]
25
- # Add dependencies here
26
- dependencies = ["gradio>=4.0,<5.0"]
27
- classifiers = [
28
- 'Development Status :: 3 - Alpha',
29
- 'License :: OSI Approved :: Apache Software License',
30
- 'Operating System :: OS Independent',
31
- 'Programming Language :: Python :: 3',
32
- 'Programming Language :: Python :: 3 :: Only',
33
- 'Programming Language :: Python :: 3.8',
34
- 'Programming Language :: Python :: 3.9',
35
- 'Programming Language :: Python :: 3.10',
36
- 'Programming Language :: Python :: 3.11',
37
- 'Topic :: Scientific/Engineering',
38
- 'Topic :: Scientific/Engineering :: Artificial Intelligence',
39
- 'Topic :: Scientific/Engineering :: Visualization',
40
- ]
41
-
42
- [project.optional-dependencies]
43
- dev = ["build", "twine"]
44
-
45
- [project.urls]
46
- repository = "https://github.com/freddyaboulton/gradio-pdf"
47
- space = "https://huggingface.co/spaces/freddyaboulton/gradio_pdf"
48
-
49
- [tool.hatch.build]
50
- artifacts = ["/backend/gradio_pdf/templates", "*.pyi", "backend/gradio_pdf/templates", "backend/gradio_pdf/templates"]
51
-
52
- [tool.hatch.build.targets.wheel]
53
- packages = ["/backend/gradio_pdf"]