@mlightcad/cad-pdf-plugin 1.5.8 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +164 -164
- package/dist/cad-pdf-plugin.js +1 -1
- package/dist/cad-pdf-plugin.umd.cjs +1 -1
- package/package.json +7 -7
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 mlightcad
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mlightcad
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
# @mlightcad/cad-pdf-plugin
|
|
2
|
-
|
|
3
|
-
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](https://www.npmjs.com/package/@mlightcad/cad-pdf-plugin)
|
|
5
|
-
|
|
6
|
-
PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers two system commands:
|
|
7
|
-
|
|
8
|
-
| Command | Description |
|
|
9
|
-
|---------|-------------|
|
|
10
|
-
| `cpdf` | Export the current drawing to a vector PDF (SVG pipeline → jsPDF) |
|
|
11
|
-
| `ipdf` | Import vector geometry from a PDF file into model space |
|
|
12
|
-
|
|
13
|
-
The plugin is designed for **lazy loading** so PDF libraries (`jspdf`, `pdfjs-dist`, `svg2pdf.js`) are only downloaded when a user runs `cpdf` or `ipdf`.
|
|
14
|
-
|
|
15
|
-
## Key features
|
|
16
|
-
|
|
17
|
-
- **Vector PDF export** — renders model-space entities via `@mlightcad/cad-svg-plugin`, then converts SVG to PDF with `svg2pdf.js`
|
|
18
|
-
- **PDF import** — parses vector paths from the first page of a PDF (lines, polylines, Bézier curves) and appends CAD entities
|
|
19
|
-
- **Plugin API** — implements `AcApPlugin`; register once with `registerLazyPdfPlugin`
|
|
20
|
-
- **Framework-agnostic** — no Vue/React dependency; works anywhere `cad-simple-viewer` runs
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
pnpm add @mlightcad/cad-pdf-plugin
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Peer dependencies:
|
|
29
|
-
|
|
30
|
-
- `@mlightcad/cad-simple-viewer`
|
|
31
|
-
- `@mlightcad/data-model`
|
|
32
|
-
- `@mlightcad/cad-svg-plugin`
|
|
33
|
-
|
|
34
|
-
Runtime dependencies (bundled with this package):
|
|
35
|
-
|
|
36
|
-
- `jspdf`
|
|
37
|
-
- `pdfjs-dist`
|
|
38
|
-
- `svg2pdf.js`
|
|
39
|
-
|
|
40
|
-
## Build
|
|
41
|
-
|
|
42
|
-
Produces `dist/index.js` (main library) and `dist/register.js` (lazy-registration entry).
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
pnpm --filter @mlightcad/cad-pdf-plugin build
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Usage
|
|
49
|
-
|
|
50
|
-
### Lazy registration (recommended)
|
|
51
|
-
|
|
52
|
-
Register the plugin with the document manager's plugin manager. Import from the `/register` subpath so only the registration stub enters your initial bundle; the main plugin chunk loads on first use of `cpdf` or `ipdf`:
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
import { AcApDocManager } from '@mlightcad/cad-simple-viewer'
|
|
56
|
-
import { registerLazyPdfPlugin } from '@mlightcad/cad-pdf-plugin/register'
|
|
57
|
-
|
|
58
|
-
registerLazyPdfPlugin(AcApDocManager.instance.pluginManager)
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Do **not** import `registerLazyPdfPlugin` from the package root in application code — that resolves to the full library build and defeats lazy loading.
|
|
62
|
-
|
|
63
|
-
Equivalent manual registration:
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
import {
|
|
67
|
-
createPdfPlugin,
|
|
68
|
-
PDF_PLUGIN_NAME,
|
|
69
|
-
PDF_PLUGIN_TRIGGERS
|
|
70
|
-
} from '@mlightcad/cad-pdf-plugin'
|
|
71
|
-
|
|
72
|
-
AcApDocManager.instance.pluginManager.registerLazyPlugin({
|
|
73
|
-
name: PDF_PLUGIN_NAME,
|
|
74
|
-
triggers: [...PDF_PLUGIN_TRIGGERS],
|
|
75
|
-
loader: createPdfPlugin
|
|
76
|
-
})
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
After registration, users (or your UI) invoke commands through the editor:
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
// Export current drawing to PDF
|
|
83
|
-
await AcApDocManager.instance.editor.executeCommand('cpdf')
|
|
84
|
-
|
|
85
|
-
// Open file picker and import PDF vectors
|
|
86
|
-
await AcApDocManager.instance.editor.executeCommand('ipdf')
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
`cad-viewer` registers this plugin automatically via `registerLazyPlugins()` in its app bootstrap.
|
|
90
|
-
|
|
91
|
-
### Eager registration
|
|
92
|
-
|
|
93
|
-
If you prefer loading PDF support up front:
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
import { AcApPdfPlugin } from '@mlightcad/cad-pdf-plugin'
|
|
97
|
-
|
|
98
|
-
await AcApDocManager.instance.pluginManager.loadPlugin(new AcApPdfPlugin())
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Programmatic convertors
|
|
102
|
-
|
|
103
|
-
You can bypass the command layer and call the convertors directly:
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
import { AcApContext } from '@mlightcad/cad-simple-viewer'
|
|
107
|
-
import { AcApPdfConvertor, AcApPdfImportConvertor } from '@mlightcad/cad-pdf-plugin'
|
|
108
|
-
|
|
109
|
-
// Export
|
|
110
|
-
const context: AcApContext = /* active context */
|
|
111
|
-
await new AcApPdfConvertor().convert(context)
|
|
112
|
-
|
|
113
|
-
// Import from bytes
|
|
114
|
-
const buffer: ArrayBuffer = /* PDF file */
|
|
115
|
-
await new AcApPdfImportConvertor().convert(context, buffer, 1) // page 1
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
## How it works
|
|
119
|
-
|
|
120
|
-
### Export (`cpdf`)
|
|
121
|
-
|
|
122
|
-
1. Iterate model-space entities and render with `AcSvgRenderer` (respects linetype scale, lineweight display, font mapping, background/foreground colors).
|
|
123
|
-
2. Parse the SVG and pass it to `svg2pdf.js` inside a `jsPDF` document sized to the SVG viewBox.
|
|
124
|
-
3. Trigger a browser download as `drawing.pdf`.
|
|
125
|
-
|
|
126
|
-
### Import (`ipdf`)
|
|
127
|
-
|
|
128
|
-
1. Show a native file picker (`.pdf`).
|
|
129
|
-
2. Use `pdfjs-dist` to read operator lists from the selected page.
|
|
130
|
-
3. Convert path operators (move, line, cubic Bézier, close) into `AcDbLine` / `AcDbPolyline` entities in model space.
|
|
131
|
-
|
|
132
|
-
Import is **vector-only**; raster/scanned PDF pages produce no entities. Only the requested page is processed (default: page 1).
|
|
133
|
-
|
|
134
|
-
## Main exports
|
|
135
|
-
|
|
136
|
-
| Export | Role |
|
|
137
|
-
|--------|------|
|
|
138
|
-
| `createPdfPlugin` | Async factory used by lazy loader |
|
|
139
|
-
| `PDF_PLUGIN_NAME`, `PDF_PLUGIN_TRIGGERS` | Plugin id and command triggers |
|
|
140
|
-
| `@mlightcad/cad-pdf-plugin/register` | `registerLazyPdfPlugin` and registration constants |
|
|
141
|
-
| `AcApPdfPlugin` | `AcApPlugin` implementation |
|
|
142
|
-
| `AcApConvertToPdfCmd` | `cpdf` command class |
|
|
143
|
-
| `AcApImportPdfCmd` | `ipdf` command class |
|
|
144
|
-
| `AcApPdfConvertor` | SVG → PDF export utility |
|
|
145
|
-
| `AcApPdfImportConvertor` | PDF → CAD entities import utility |
|
|
146
|
-
|
|
147
|
-
## Project layout
|
|
148
|
-
|
|
149
|
-
| Path | Role |
|
|
150
|
-
|------|------|
|
|
151
|
-
| `src/register.ts` | Lazy plugin registration (`/register` entry) and `createPdfPlugin` |
|
|
152
|
-
| `src/AcApPdfPlugin.ts` | Plugin lifecycle (`onLoad` / `onUnload`) |
|
|
153
|
-
| `src/AcApConvertToPdfCmd.ts` | `cpdf` command |
|
|
154
|
-
| `src/AcApImportPdfCmd.ts` | `ipdf` command |
|
|
155
|
-
| `src/AcApPdfConvertor.ts` | Export pipeline (SVG renderer + jsPDF) |
|
|
156
|
-
| `src/AcApPdfImportConvertor.ts` | Import pipeline (pdf.js operator parsing) |
|
|
157
|
-
|
|
158
|
-
## Role in MLightCAD
|
|
159
|
-
|
|
160
|
-
This package extends `cad-simple-viewer` with optional PDF I/O. It depends on `cad-svg-plugin` for export quality parity with the existing SVG export command (`csvg`) and keeps heavy PDF dependencies out of the core viewer bundle through lazy loading.
|
|
161
|
-
|
|
162
|
-
## License
|
|
163
|
-
|
|
164
|
-
MIT
|
|
1
|
+
# @mlightcad/cad-pdf-plugin
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://www.npmjs.com/package/@mlightcad/cad-pdf-plugin)
|
|
5
|
+
|
|
6
|
+
PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers two system commands:
|
|
7
|
+
|
|
8
|
+
| Command | Description |
|
|
9
|
+
|---------|-------------|
|
|
10
|
+
| `cpdf` | Export the current drawing to a vector PDF (SVG pipeline → jsPDF) |
|
|
11
|
+
| `ipdf` | Import vector geometry from a PDF file into model space |
|
|
12
|
+
|
|
13
|
+
The plugin is designed for **lazy loading** so PDF libraries (`jspdf`, `pdfjs-dist`, `svg2pdf.js`) are only downloaded when a user runs `cpdf` or `ipdf`.
|
|
14
|
+
|
|
15
|
+
## Key features
|
|
16
|
+
|
|
17
|
+
- **Vector PDF export** — renders model-space entities via `@mlightcad/cad-svg-plugin`, then converts SVG to PDF with `svg2pdf.js`
|
|
18
|
+
- **PDF import** — parses vector paths from the first page of a PDF (lines, polylines, Bézier curves) and appends CAD entities
|
|
19
|
+
- **Plugin API** — implements `AcApPlugin`; register once with `registerLazyPdfPlugin`
|
|
20
|
+
- **Framework-agnostic** — no Vue/React dependency; works anywhere `cad-simple-viewer` runs
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @mlightcad/cad-pdf-plugin
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Peer dependencies:
|
|
29
|
+
|
|
30
|
+
- `@mlightcad/cad-simple-viewer`
|
|
31
|
+
- `@mlightcad/data-model`
|
|
32
|
+
- `@mlightcad/cad-svg-plugin`
|
|
33
|
+
|
|
34
|
+
Runtime dependencies (bundled with this package):
|
|
35
|
+
|
|
36
|
+
- `jspdf`
|
|
37
|
+
- `pdfjs-dist`
|
|
38
|
+
- `svg2pdf.js`
|
|
39
|
+
|
|
40
|
+
## Build
|
|
41
|
+
|
|
42
|
+
Produces `dist/index.js` (main library) and `dist/register.js` (lazy-registration entry).
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pnpm --filter @mlightcad/cad-pdf-plugin build
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
### Lazy registration (recommended)
|
|
51
|
+
|
|
52
|
+
Register the plugin with the document manager's plugin manager. Import from the `/register` subpath so only the registration stub enters your initial bundle; the main plugin chunk loads on first use of `cpdf` or `ipdf`:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { AcApDocManager } from '@mlightcad/cad-simple-viewer'
|
|
56
|
+
import { registerLazyPdfPlugin } from '@mlightcad/cad-pdf-plugin/register'
|
|
57
|
+
|
|
58
|
+
registerLazyPdfPlugin(AcApDocManager.instance.pluginManager)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Do **not** import `registerLazyPdfPlugin` from the package root in application code — that resolves to the full library build and defeats lazy loading.
|
|
62
|
+
|
|
63
|
+
Equivalent manual registration:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import {
|
|
67
|
+
createPdfPlugin,
|
|
68
|
+
PDF_PLUGIN_NAME,
|
|
69
|
+
PDF_PLUGIN_TRIGGERS
|
|
70
|
+
} from '@mlightcad/cad-pdf-plugin'
|
|
71
|
+
|
|
72
|
+
AcApDocManager.instance.pluginManager.registerLazyPlugin({
|
|
73
|
+
name: PDF_PLUGIN_NAME,
|
|
74
|
+
triggers: [...PDF_PLUGIN_TRIGGERS],
|
|
75
|
+
loader: createPdfPlugin
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
After registration, users (or your UI) invoke commands through the editor:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Export current drawing to PDF
|
|
83
|
+
await AcApDocManager.instance.editor.executeCommand('cpdf')
|
|
84
|
+
|
|
85
|
+
// Open file picker and import PDF vectors
|
|
86
|
+
await AcApDocManager.instance.editor.executeCommand('ipdf')
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`cad-viewer` registers this plugin automatically via `registerLazyPlugins()` in its app bootstrap.
|
|
90
|
+
|
|
91
|
+
### Eager registration
|
|
92
|
+
|
|
93
|
+
If you prefer loading PDF support up front:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { AcApPdfPlugin } from '@mlightcad/cad-pdf-plugin'
|
|
97
|
+
|
|
98
|
+
await AcApDocManager.instance.pluginManager.loadPlugin(new AcApPdfPlugin())
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Programmatic convertors
|
|
102
|
+
|
|
103
|
+
You can bypass the command layer and call the convertors directly:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { AcApContext } from '@mlightcad/cad-simple-viewer'
|
|
107
|
+
import { AcApPdfConvertor, AcApPdfImportConvertor } from '@mlightcad/cad-pdf-plugin'
|
|
108
|
+
|
|
109
|
+
// Export
|
|
110
|
+
const context: AcApContext = /* active context */
|
|
111
|
+
await new AcApPdfConvertor().convert(context)
|
|
112
|
+
|
|
113
|
+
// Import from bytes
|
|
114
|
+
const buffer: ArrayBuffer = /* PDF file */
|
|
115
|
+
await new AcApPdfImportConvertor().convert(context, buffer, 1) // page 1
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## How it works
|
|
119
|
+
|
|
120
|
+
### Export (`cpdf`)
|
|
121
|
+
|
|
122
|
+
1. Iterate model-space entities and render with `AcSvgRenderer` (respects linetype scale, lineweight display, font mapping, background/foreground colors).
|
|
123
|
+
2. Parse the SVG and pass it to `svg2pdf.js` inside a `jsPDF` document sized to the SVG viewBox.
|
|
124
|
+
3. Trigger a browser download as `drawing.pdf`.
|
|
125
|
+
|
|
126
|
+
### Import (`ipdf`)
|
|
127
|
+
|
|
128
|
+
1. Show a native file picker (`.pdf`).
|
|
129
|
+
2. Use `pdfjs-dist` to read operator lists from the selected page.
|
|
130
|
+
3. Convert path operators (move, line, cubic Bézier, close) into `AcDbLine` / `AcDbPolyline` entities in model space.
|
|
131
|
+
|
|
132
|
+
Import is **vector-only**; raster/scanned PDF pages produce no entities. Only the requested page is processed (default: page 1).
|
|
133
|
+
|
|
134
|
+
## Main exports
|
|
135
|
+
|
|
136
|
+
| Export | Role |
|
|
137
|
+
|--------|------|
|
|
138
|
+
| `createPdfPlugin` | Async factory used by lazy loader |
|
|
139
|
+
| `PDF_PLUGIN_NAME`, `PDF_PLUGIN_TRIGGERS` | Plugin id and command triggers |
|
|
140
|
+
| `@mlightcad/cad-pdf-plugin/register` | `registerLazyPdfPlugin` and registration constants |
|
|
141
|
+
| `AcApPdfPlugin` | `AcApPlugin` implementation |
|
|
142
|
+
| `AcApConvertToPdfCmd` | `cpdf` command class |
|
|
143
|
+
| `AcApImportPdfCmd` | `ipdf` command class |
|
|
144
|
+
| `AcApPdfConvertor` | SVG → PDF export utility |
|
|
145
|
+
| `AcApPdfImportConvertor` | PDF → CAD entities import utility |
|
|
146
|
+
|
|
147
|
+
## Project layout
|
|
148
|
+
|
|
149
|
+
| Path | Role |
|
|
150
|
+
|------|------|
|
|
151
|
+
| `src/register.ts` | Lazy plugin registration (`/register` entry) and `createPdfPlugin` |
|
|
152
|
+
| `src/AcApPdfPlugin.ts` | Plugin lifecycle (`onLoad` / `onUnload`) |
|
|
153
|
+
| `src/AcApConvertToPdfCmd.ts` | `cpdf` command |
|
|
154
|
+
| `src/AcApImportPdfCmd.ts` | `ipdf` command |
|
|
155
|
+
| `src/AcApPdfConvertor.ts` | Export pipeline (SVG renderer + jsPDF) |
|
|
156
|
+
| `src/AcApPdfImportConvertor.ts` | Import pipeline (pdf.js operator parsing) |
|
|
157
|
+
|
|
158
|
+
## Role in MLightCAD
|
|
159
|
+
|
|
160
|
+
This package extends `cad-simple-viewer` with optional PDF I/O. It depends on `cad-svg-plugin` for export quality parity with the existing SVG export command (`csvg`) and keeps heavy PDF dependencies out of the core viewer bundle through lazy loading.
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT
|
package/dist/cad-pdf-plugin.js
CHANGED
|
@@ -31010,7 +31010,7 @@ class CV extends $P {
|
|
|
31010
31010
|
new BV().importFromFilePicker(t);
|
|
31011
31011
|
}
|
|
31012
31012
|
}
|
|
31013
|
-
const xV = "1.5.
|
|
31013
|
+
const xV = "1.5.10", EV = {
|
|
31014
31014
|
version: xV
|
|
31015
31015
|
};
|
|
31016
31016
|
class SV {
|
|
@@ -269,7 +269,7 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
|
|
|
269
269
|
`),position:C,pageIndex:x-1,rect:c.slice(0),rotation:u,annotationElementId:d,id:d,deleted:!1,popupRef:f,comment:(p==null?void 0:p.str)||null,richText:m,creationDate:y,modificationDate:v}}const A=await super.deserialize(e,r,i);return E(A,vA,e.fontSize),A.color=Mt.makeHexColor(...e.color),E(A,mA,P(a=jr,nc,XS).call(a,e.value)),A._initialData=s,e.comment&&A.setCommentData(e),A}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const r=Rr._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),i=Object.assign(super.serialize(e),{color:r,fontSize:h(this,vA),value:P(this,qi,JO).call(this)});return this.addComment(i),e?(i.isCopy=!0,i):this.annotationElementId&&!P(this,qi,ZO).call(this,i)?null:(i.id=this.annotationElementId,i)}renderAnnotationElement(e){const r=super.renderAnnotationElement(e);if(!r)return null;const{style:i}=r;i.fontSize=`calc(${h(this,vA)}px * var(--total-scale-factor))`,i.color=this.color,r.replaceChildren();for(const s of h(this,mA).split(`
|
|
270
270
|
`)){const A=document.createElement("div");A.append(s?document.createTextNode(s):document.createElement("br")),r.append(A)}return e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:h(this,mA)}}),r}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};mA=new WeakMap,A1=new WeakMap,Qf=new WeakMap,vA=new WeakMap,qi=new WeakSet,XO=function(e){const r=s=>{this.editorDiv.style.fontSize=`calc(${s}px * var(--total-scale-factor))`,this.translate(0,-(s-h(this,vA))*this.parentScale),E(this,vA,s),P(this,qi,Ky).call(this)},i=h(this,vA);this.addCommands({cmd:r.bind(this,e),undo:r.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Qe.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},YO=function(e){const r=s=>{this.color=s,this.onUpdatedColor()},i=this.color;this.addCommands({cmd:r.bind(this,e),undo:r.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Qe.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},$O=function(){var i;const e=[];this.editorDiv.normalize();let r=null;for(const s of this.editorDiv.childNodes)(r==null?void 0:r.nodeType)===Node.TEXT_NODE&&s.nodeName==="BR"||(e.push(P(i=jr,nc,Gy).call(i,s)),r=s);return e.join(`
|
|
271
271
|
`)},Ky=function(){const[e,r]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:s,div:A}=this,a=A.style.display,o=A.classList.contains("hidden");A.classList.remove("hidden"),A.style.display="hidden",s.div.append(this.div),i=A.getBoundingClientRect(),A.remove(),A.style.display=a,A.classList.toggle("hidden",o)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/r):(this.width=i.height/e,this.height=i.width/r),this.fixAndSetPosition()},nc=new WeakSet,Gy=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(kw,"")},jy=function(){if(this.editorDiv.replaceChildren(),!!h(this,mA))for(const e of h(this,mA).split(`
|
|
272
|
-
`)){const r=document.createElement("div");r.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(r)}},JO=function(){return h(this,mA).replaceAll(" "," ")},XS=function(e){return e.replaceAll(" "," ")},ZO=function(e){const{value:r,fontSize:i,color:s,pageIndex:A}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==r||e.fontSize!==i||e.color.some((a,o)=>a!==s[o])||e.pageIndex!==A},T(jr,nc),ht(jr,"_freeTextDefaultContent",""),ht(jr,"_internalPadding",0),ht(jr,"_defaultColor",null),ht(jr,"_defaultFontSize",10),ht(jr,"_type","freetext"),ht(jr,"_editorType",Fe.FREETEXT);let zS=jr;class re{toSVGPath(){ur("Abstract method `toSVGPath` must be implemented.")}get box(){ur("Abstract getter `box` must be implemented.")}serialize(t,e){ur("Abstract method `serialize` must be implemented.")}static _rescale(t,e,r,i,s,A){A||(A=new Float32Array(t.length));for(let a=0,o=t.length;a<o;a+=2)A[a]=e+t[a]*i,A[a+1]=r+t[a+1]*s;return A}static _rescaleAndSwap(t,e,r,i,s,A){A||(A=new Float32Array(t.length));for(let a=0,o=t.length;a<o;a+=2)A[a]=e+t[a+1]*i,A[a+1]=r+t[a]*s;return A}static _translate(t,e,r,i){i||(i=new Float32Array(t.length));for(let s=0,A=t.length;s<A;s+=2)i[s]=e+t[s],i[s+1]=r+t[s+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,r,i,s){switch(s){case 90:return[1-e/r,t/i];case 180:return[1-t/r,1-e/i];case 270:return[e/r,1-t/i];default:return[t/r,e/i]}}static _normalizePagePoint(t,e,r){switch(r){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,r,i,s,A){return[(t+5*r)/6,(e+5*i)/6,(5*r+s)/6,(5*i+A)/6,(r+s)/2,(i+A)/2]}}ht(re,"PRECISION",1e-4);var wA,Ia,xp,Ep,xo,qe,Mf,Of,a1,o1,Sp,Fp,xh,l1,rb,ib,sn,im,tk,ek,rk,ik,nk,sk;const fl=class fl{constructor({x:t,y:e},r,i,s,A,a=0){T(this,sn);T(this,wA);T(this,Ia,[]);T(this,xp);T(this,Ep);T(this,xo,[]);T(this,qe,new Float32Array(18));T(this,Mf);T(this,Of);T(this,a1);T(this,o1);T(this,Sp);T(this,Fp);T(this,xh,[]);E(this,wA,r),E(this,Fp,s*i),E(this,Ep,A),h(this,qe).set([NaN,NaN,NaN,NaN,t,e],6),E(this,xp,a),E(this,o1,h(fl,l1)*i),E(this,a1,h(fl,ib)*i),E(this,Sp,i),h(this,xh).push(t,e)}isEmpty(){return isNaN(h(this,qe)[8])}add({x:t,y:e}){var L;E(this,Mf,t),E(this,Of,e);const[r,i,s,A]=h(this,wA);let[a,o,l,c]=h(this,qe).subarray(8,12);const u=t-l,d=e-c,f=Math.hypot(u,d);if(f<h(this,a1))return!1;const m=f-h(this,o1),p=m/f,y=p*u,v=p*d;let b=a,C=o;a=l,o=c,l+=y,c+=v,(L=h(this,xh))==null||L.push(t,e);const x=-v/m,F=y/m,I=x*h(this,Fp),Q=F*h(this,Fp);return h(this,qe).set(h(this,qe).subarray(2,8),0),h(this,qe).set([l+I,c+Q],4),h(this,qe).set(h(this,qe).subarray(14,18),12),h(this,qe).set([l-I,c-Q],16),isNaN(h(this,qe)[6])?(h(this,xo).length===0&&(h(this,qe).set([a+I,o+Q],2),h(this,xo).push(NaN,NaN,NaN,NaN,(a+I-r)/s,(o+Q-i)/A),h(this,qe).set([a-I,o-Q],14),h(this,Ia).push(NaN,NaN,NaN,NaN,(a-I-r)/s,(o-Q-i)/A)),h(this,qe).set([b,C,a,o,l,c],6),!this.isEmpty()):(h(this,qe).set([b,C,a,o,l,c],6),Math.abs(Math.atan2(C-o,b-a)-Math.atan2(v,y))<Math.PI/2?([a,o,l,c]=h(this,qe).subarray(2,6),h(this,xo).push(NaN,NaN,NaN,NaN,((a+l)/2-r)/s,((o+c)/2-i)/A),[a,o,b,C]=h(this,qe).subarray(14,18),h(this,Ia).push(NaN,NaN,NaN,NaN,((b+a)/2-r)/s,((C+o)/2-i)/A),!0):([b,C,a,o,l,c]=h(this,qe).subarray(0,6),h(this,xo).push(((b+5*a)/6-r)/s,((C+5*o)/6-i)/A,((5*a+l)/6-r)/s,((5*o+c)/6-i)/A,((a+l)/2-r)/s,((o+c)/2-i)/A),[l,c,a,o,b,C]=h(this,qe).subarray(12,18),h(this,Ia).push(((b+5*a)/6-r)/s,((C+5*o)/6-i)/A,((5*a+l)/6-r)/s,((5*o+c)/6-i)/A,((a+l)/2-r)/s,((o+c)/2-i)/A),!0))}toSVGPath(){if(this.isEmpty())return"";const t=h(this,xo),e=h(this,Ia);if(isNaN(h(this,qe)[6])&&!this.isEmpty())return P(this,sn,tk).call(this);const r=[];r.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?r.push(`L${t[i+4]} ${t[i+5]}`):r.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);P(this,sn,rk).call(this,r);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?r.push(`L${e[i+4]} ${e[i+5]}`):r.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return P(this,sn,ek).call(this,r),r.join(" ")}newFreeDrawOutline(t,e,r,i,s,A){return new Ak(t,e,r,i,s,A)}getOutlines(){var u;const t=h(this,xo),e=h(this,Ia),r=h(this,qe),[i,s,A,a]=h(this,wA),o=new Float32Array((((u=h(this,xh))==null?void 0:u.length)??0)+2);for(let d=0,f=o.length-2;d<f;d+=2)o[d]=(h(this,xh)[d]-i)/A,o[d+1]=(h(this,xh)[d+1]-s)/a;if(o[o.length-2]=(h(this,Mf)-i)/A,o[o.length-1]=(h(this,Of)-s)/a,isNaN(r[6])&&!this.isEmpty())return P(this,sn,ik).call(this,o);const l=new Float32Array(h(this,xo).length+24+h(this,Ia).length);let c=t.length;for(let d=0;d<c;d+=2){if(isNaN(t[d])){l[d]=l[d+1]=NaN;continue}l[d]=t[d],l[d+1]=t[d+1]}c=P(this,sn,sk).call(this,l,c);for(let d=e.length-6;d>=6;d-=6)for(let f=0;f<6;f+=2){if(isNaN(e[d+f])){l[c]=l[c+1]=NaN,c+=2;continue}l[c]=e[d+f],l[c+1]=e[d+f+1],c+=2}return P(this,sn,nk).call(this,l,c),this.newFreeDrawOutline(l,o,h(this,wA),h(this,Sp),h(this,xp),h(this,Ep))}};wA=new WeakMap,Ia=new WeakMap,xp=new WeakMap,Ep=new WeakMap,xo=new WeakMap,qe=new WeakMap,Mf=new WeakMap,Of=new WeakMap,a1=new WeakMap,o1=new WeakMap,Sp=new WeakMap,Fp=new WeakMap,xh=new WeakMap,l1=new WeakMap,rb=new WeakMap,ib=new WeakMap,sn=new WeakSet,im=function(){const t=h(this,qe).subarray(4,6),e=h(this,qe).subarray(16,18),[r,i,s,A]=h(this,wA);return[(h(this,Mf)+(t[0]-e[0])/2-r)/s,(h(this,Of)+(t[1]-e[1])/2-i)/A,(h(this,Mf)+(e[0]-t[0])/2-r)/s,(h(this,Of)+(e[1]-t[1])/2-i)/A]},tk=function(){const[t,e,r,i]=h(this,wA),[s,A,a,o]=P(this,sn,im).call(this);return`M${(h(this,qe)[2]-t)/r} ${(h(this,qe)[3]-e)/i} L${(h(this,qe)[4]-t)/r} ${(h(this,qe)[5]-e)/i} L${s} ${A} L${a} ${o} L${(h(this,qe)[16]-t)/r} ${(h(this,qe)[17]-e)/i} L${(h(this,qe)[14]-t)/r} ${(h(this,qe)[15]-e)/i} Z`},ek=function(t){const e=h(this,Ia);t.push(`L${e[4]} ${e[5]} Z`)},rk=function(t){const[e,r,i,s]=h(this,wA),A=h(this,qe).subarray(4,6),a=h(this,qe).subarray(16,18),[o,l,c,u]=P(this,sn,im).call(this);t.push(`L${(A[0]-e)/i} ${(A[1]-r)/s} L${o} ${l} L${c} ${u} L${(a[0]-e)/i} ${(a[1]-r)/s}`)},ik=function(t){const e=h(this,qe),[r,i,s,A]=h(this,wA),[a,o,l,c]=P(this,sn,im).call(this),u=new Float32Array(36);return u.set([NaN,NaN,NaN,NaN,(e[2]-r)/s,(e[3]-i)/A,NaN,NaN,NaN,NaN,(e[4]-r)/s,(e[5]-i)/A,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,(e[16]-r)/s,(e[17]-i)/A,NaN,NaN,NaN,NaN,(e[14]-r)/s,(e[15]-i)/A],0),this.newFreeDrawOutline(u,t,h(this,wA),h(this,Sp),h(this,xp),h(this,Ep))},nk=function(t,e){const r=h(this,Ia);return t.set([NaN,NaN,NaN,NaN,r[4],r[5]],e),e+=6},sk=function(t,e){const r=h(this,qe).subarray(4,6),i=h(this,qe).subarray(16,18),[s,A,a,o]=h(this,wA),[l,c,u,d]=P(this,sn,im).call(this);return t.set([NaN,NaN,NaN,NaN,(r[0]-s)/a,(r[1]-A)/o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(i[0]-s)/a,(i[1]-A)/o],e),e+=24},T(fl,l1,8),T(fl,rb,2),T(fl,ib,h(fl,l1)+h(fl,rb));let w2=fl;var _p,kf,jl,c1,yA,h1,Ii,nb,ak;class Ak extends re{constructor(e,r,i,s,A,a){super();T(this,nb);T(this,_p);T(this,kf,new Float32Array(4));T(this,jl);T(this,c1);T(this,yA);T(this,h1);T(this,Ii);E(this,Ii,e),E(this,yA,r),E(this,_p,i),E(this,h1,s),E(this,jl,A),E(this,c1,a),this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],P(this,nb,ak).call(this,a);const[o,l,c,u]=h(this,kf);for(let d=0,f=e.length;d<f;d+=2)e[d]=(e[d]-o)/c,e[d+1]=(e[d+1]-l)/u;for(let d=0,f=r.length;d<f;d+=2)r[d]=(r[d]-o)/c,r[d+1]=(r[d+1]-l)/u}toSVGPath(){const e=[`M${h(this,Ii)[4]} ${h(this,Ii)[5]}`];for(let r=6,i=h(this,Ii).length;r<i;r+=6){if(isNaN(h(this,Ii)[r])){e.push(`L${h(this,Ii)[r+4]} ${h(this,Ii)[r+5]}`);continue}e.push(`C${h(this,Ii)[r]} ${h(this,Ii)[r+1]} ${h(this,Ii)[r+2]} ${h(this,Ii)[r+3]} ${h(this,Ii)[r+4]} ${h(this,Ii)[r+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,r,i,s],A){const a=i-e,o=s-r;let l,c;switch(A){case 0:l=re._rescale(h(this,Ii),e,s,a,-o),c=re._rescale(h(this,yA),e,s,a,-o);break;case 90:l=re._rescaleAndSwap(h(this,Ii),e,r,a,o),c=re._rescaleAndSwap(h(this,yA),e,r,a,o);break;case 180:l=re._rescale(h(this,Ii),i,r,-a,o),c=re._rescale(h(this,yA),i,r,-a,o);break;case 270:l=re._rescaleAndSwap(h(this,Ii),i,s,-a,-o),c=re._rescaleAndSwap(h(this,yA),i,s,-a,-o);break}return{outline:Array.from(l),points:[Array.from(c)]}}get box(){return h(this,kf)}newOutliner(e,r,i,s,A,a=0){return new w2(e,r,i,s,A,a)}getNewOutline(e,r){const[i,s,A,a]=h(this,kf),[o,l,c,u]=h(this,_p),d=A*c,f=a*u,m=i*c+o,p=s*u+l,y=this.newOutliner({x:h(this,yA)[0]*d+m,y:h(this,yA)[1]*f+p},h(this,_p),h(this,h1),e,h(this,c1),r??h(this,jl));for(let v=2;v<h(this,yA).length;v+=2)y.add({x:h(this,yA)[v]*d+m,y:h(this,yA)[v+1]*f+p});return y.getOutlines()}}_p=new WeakMap,kf=new WeakMap,jl=new WeakMap,c1=new WeakMap,yA=new WeakMap,h1=new WeakMap,Ii=new WeakMap,nb=new WeakSet,ak=function(e){const r=h(this,Ii);let i=r[4],s=r[5];const A=[i,s,i,s];let a=i,o=s,l=i,c=s;const u=e?Math.max:Math.min,d=new Float32Array(4);for(let m=6,p=r.length;m<p;m+=6){const y=r[m+4],v=r[m+5];isNaN(r[m])?(Mt.pointBoundingBox(y,v,A),o>v?(a=y,o=v):o===v&&(a=u(a,y)),c<v?(l=y,c=v):c===v&&(l=u(l,y))):(d.set(Zl,0),Mt.bezierBoundingBox(i,s,...r.slice(m,m+6),d),Mt.rectBoundingBox(...d,A),o>d[1]?(a=d[0],o=d[1]):o===d[1]&&(a=u(a,d[0])),c<d[3]?(l=d[2],c=d[3]):c===d[3]&&(l=u(l,d[2]))),i=y,s=v}const f=h(this,kf);f[0]=A[0]-h(this,jl),f[1]=A[1]-h(this,jl),f[2]=A[2]-A[0]+2*h(this,jl),f[3]=A[3]-A[1]+2*h(this,jl),this.firstPoint=[a,o],this.lastPoint=[l,c]};var u1,f1,d1,Eh,Ua,_s,ok,Vy,lk,ck,$S;class YS{constructor(t,e=0,r=0,i=!0){T(this,_s);T(this,u1);T(this,f1);T(this,d1);T(this,Eh,[]);T(this,Ua,[]);const s=Zl.slice(),A=10**-4;for(const{x:p,y,width:v,height:b}of t){const C=Math.floor((p-e)/A)*A,x=Math.ceil((p+v+e)/A)*A,F=Math.floor((y-e)/A)*A,I=Math.ceil((y+b+e)/A)*A,Q=[C,F,I,!0],R=[x,F,I,!1];h(this,Eh).push(Q,R),Mt.rectBoundingBox(C,F,x,I,s)}const a=s[2]-s[0]+2*r,o=s[3]-s[1]+2*r,l=s[0]-r,c=s[1]-r;let u=i?-1/0:1/0,d=1/0;const f=h(this,Eh).at(i?-1:-2),m=[f[0],f[2]];for(const p of h(this,Eh)){const[y,v,b,C]=p;!C&&i?v<d?(d=v,u=y):v===d&&(u=Math.max(u,y)):C&&!i&&(v<d?(d=v,u=y):v===d&&(u=Math.min(u,y))),p[0]=(y-l)/a,p[1]=(v-c)/o,p[2]=(b-c)/o}E(this,u1,new Float32Array([l,c,a,o])),E(this,f1,[u,d]),E(this,d1,m)}getOutlines(){h(this,Eh).sort((e,r)=>e[0]-r[0]||e[1]-r[1]||e[2]-r[2]);const t=[];for(const e of h(this,Eh))e[3]?(t.push(...P(this,_s,$S).call(this,e)),P(this,_s,lk).call(this,e)):(P(this,_s,ck).call(this,e),t.push(...P(this,_s,$S).call(this,e)));return P(this,_s,ok).call(this,t)}}u1=new WeakMap,f1=new WeakMap,d1=new WeakMap,Eh=new WeakMap,Ua=new WeakMap,_s=new WeakSet,ok=function(t){const e=[],r=new Set;for(const A of t){const[a,o,l]=A;e.push([a,o,A],[a,l,A])}e.sort((A,a)=>A[1]-a[1]||A[0]-a[0]);for(let A=0,a=e.length;A<a;A+=2){const o=e[A][2],l=e[A+1][2];o.push(l),l.push(o),r.add(o),r.add(l)}const i=[];let s;for(;r.size>0;){const A=r.values().next().value;let[a,o,l,c,u]=A;r.delete(A);let d=a,f=o;for(s=[a,l],i.push(s);;){let m;if(r.has(c))m=c;else if(r.has(u))m=u;else break;r.delete(m),[a,o,l,c,u]=m,d!==a&&(s.push(d,f,a,f===o?o:l),d=a),f=f===o?l:o}s.push(d,f)}return new gj(i,h(this,u1),h(this,f1),h(this,d1))},Vy=function(t){const e=h(this,Ua);let r=0,i=e.length-1;for(;r<=i;){const s=r+i>>1,A=e[s][0];if(A===t)return s;A<t?r=s+1:i=s-1}return i+1},lk=function([,t,e]){const r=P(this,_s,Vy).call(this,t);h(this,Ua).splice(r,0,[t,e])},ck=function([,t,e]){const r=P(this,_s,Vy).call(this,t);for(let i=r;i<h(this,Ua).length;i++){const[s,A]=h(this,Ua)[i];if(s!==t)break;if(s===t&&A===e){h(this,Ua).splice(i,1);return}}for(let i=r-1;i>=0;i--){const[s,A]=h(this,Ua)[i];if(s!==t)break;if(s===t&&A===e){h(this,Ua).splice(i,1);return}}},$S=function(t){const[e,r,i]=t,s=[[e,r,i]],A=P(this,_s,Vy).call(this,i);for(let a=0;a<A;a++){const[o,l]=h(this,Ua)[a];for(let c=0,u=s.length;c<u;c++){const[,d,f]=s[c];if(!(l<=d||f<=o)){if(d>=o){if(f>l)s[c][1]=l;else{if(u===1)return[];s.splice(c,1),c--,u--}continue}s[c][2]=o,f>l&&s.push([e,l,f])}}}return s};var g1,Tp;class gj extends re{constructor(e,r,i,s){super();T(this,g1);T(this,Tp);E(this,Tp,e),E(this,g1,r),this.firstPoint=i,this.lastPoint=s}toSVGPath(){const e=[];for(const r of h(this,Tp)){let[i,s]=r;e.push(`M${i} ${s}`);for(let A=2;A<r.length;A+=2){const a=r[A],o=r[A+1];a===i?(e.push(`V${o}`),s=o):o===s&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,r,i,s],A){const a=[],o=i-e,l=s-r;for(const c of h(this,Tp)){const u=new Array(c.length);for(let d=0;d<c.length;d+=2)u[d]=e+c[d]*o,u[d+1]=s-c[d+1]*l;a.push(u)}return a}get box(){return h(this,g1)}get classNamesForOutlining(){return["highlightOutline"]}}g1=new WeakMap,Tp=new WeakMap;class JS extends w2{newFreeDrawOutline(t,e,r,i,s,A){return new pj(t,e,r,i,s,A)}}class pj extends Ak{newOutliner(t,e,r,i,s,A=0){return new JS(t,e,r,i,s,A)}}var Ip,p1,Vl,Rf,m1,Ks,v1,w1,Df,bA,BA,Un,Up,Lp,ss,Pp,$A,y1,Ge,ZS,qy,hk,uk,fk,tF,bu,ta,sg,dk,Wy,zy,gk,pk,mk,vk,wk;const ar=class ar extends Rr{constructor(e){super({...e,name:"highlightEditor"});T(this,Ge);T(this,Ip,null);T(this,p1,0);T(this,Vl);T(this,Rf,null);T(this,m1,null);T(this,Ks,null);T(this,v1,null);T(this,w1,0);T(this,Df,null);T(this,bA,null);T(this,BA,null);T(this,Un,!1);T(this,Up,null);T(this,Lp,null);T(this,ss,null);T(this,Pp,"");T(this,$A);T(this,y1,"");this.color=e.color||ar._defaultColor,E(this,$A,e.thickness||ar._defaultThickness),this.opacity=e.opacity||ar._defaultOpacity,E(this,Vl,e.boxes||null),E(this,y1,e.methodOfCreation||""),E(this,Pp,e.text||""),this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",e.highlightId>-1?(E(this,Un,!0),P(this,Ge,qy).call(this,e),P(this,Ge,bu).call(this)):h(this,Vl)&&(E(this,Ip,e.anchorNode),E(this,p1,e.anchorOffset),E(this,v1,e.focusNode),E(this,w1,e.focusOffset),P(this,Ge,ZS).call(this),P(this,Ge,bu).call(this),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}static get _keyboardManager(){const e=ar.prototype;return Te(this,"_keyboardManager",new M1([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:h(this,Un)?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:h(this,$A),methodOfCreation:h(this,y1)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,r){var i;Rr.initialize(e,r),ar._defaultColor||(ar._defaultColor=((i=r.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,r){switch(e){case Qe.HIGHLIGHT_COLOR:ar._defaultColor=r;break;case Qe.HIGHLIGHT_THICKNESS:ar._defaultThickness=r;break}}translateInPage(e,r){}get toolbarPosition(){return h(this,Lp)}get commentButtonPosition(){return h(this,Up)}updateParams(e,r){switch(e){case Qe.HIGHLIGHT_COLOR:P(this,Ge,hk).call(this,r);break;case Qe.HIGHLIGHT_THICKNESS:P(this,Ge,uk).call(this,r);break}}static get defaultPropertiesToUpdate(){return[[Qe.HIGHLIGHT_COLOR,ar._defaultColor],[Qe.HIGHLIGHT_THICKNESS,ar._defaultThickness]]}get propertiesToUpdate(){return[[Qe.HIGHLIGHT_COLOR,this.color||ar._defaultColor],[Qe.HIGHLIGHT_THICKNESS,h(this,$A)||ar._defaultThickness],[Qe.HIGHLIGHT_FREE,h(this,Un)]]}onUpdatedColor(){var e,r;(e=this.parent)==null||e.drawLayer.updateProperties(h(this,BA),{root:{fill:this.color,"fill-opacity":this.opacity}}),(r=h(this,m1))==null||r.updateColor(this.color),super.onUpdatedColor()}get toolbarButtons(){return this._uiManager.highlightColors?[["colorPicker",E(this,m1,new km({editor:this}))]]:super.toolbarButtons}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(P(this,Ge,zy).call(this))}getBaseTranslation(){return[0,0]}getRect(e,r){return super.getRect(e,r,P(this,Ge,zy).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){P(this,Ge,tF).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(P(this,Ge,bu).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let r=!1;this.parent&&!e?P(this,Ge,tF).call(this):e&&(P(this,Ge,bu).call(this,e),r=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),r&&this.select()}rotate(e){var s,A,a;const{drawLayer:r}=this.parent;let i;h(this,Un)?(e=(e-this.rotation+360)%360,i=P(s=ar,ta,sg).call(s,h(this,bA).box,e)):i=P(A=ar,ta,sg).call(A,[this.x,this.y,this.width,this.height],e),r.updateProperties(h(this,BA),{bbox:i,root:{"data-main-rotation":e}}),r.updateProperties(h(this,ss),{bbox:P(a=ar,ta,sg).call(a,h(this,Ks).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();h(this,Pp)&&(e.setAttribute("aria-label",h(this,Pp)),e.setAttribute("role","mark")),h(this,Un)?e.classList.add("free"):this.div.addEventListener("keydown",P(this,Ge,dk).bind(this),{signal:this._uiManager._signal});const r=E(this,Df,document.createElement("div"));return e.append(r),r.setAttribute("aria-hidden","true"),r.className="internal",r.style.clipPath=h(this,Rf),this.setDims(),SM(this,h(this,Df),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(h(this,ss),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(h(this,ss),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:P(this,Ge,Wy).call(this,!0);break;case 1:case 3:P(this,Ge,Wy).call(this,!1);break}}select(){var e;super.select(),h(this,ss)&&((e=this.parent)==null||e.drawLayer.updateProperties(h(this,ss),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),h(this,ss)&&((e=this.parent)==null||e.drawLayer.updateProperties(h(this,ss),{rootClass:{selected:!1}}),h(this,Un)||P(this,Ge,Wy).call(this,!1))}get _mustFixPosition(){return!h(this,Un)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(h(this,BA),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(h(this,ss),{rootClass:{hidden:!e}}))}static startHighlighting(e,r,{target:i,x:s,y:A}){const{x:a,y:o,width:l,height:c}=i.getBoundingClientRect(),u=new AbortController,d=e.combinedSignal(u),f=m=>{u.abort(),P(this,ta,vk).call(this,e,m)};window.addEventListener("blur",f,{signal:d}),window.addEventListener("pointerup",f,{signal:d}),window.addEventListener("pointerdown",Zr,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",UA,{signal:d}),i.addEventListener("pointermove",P(this,ta,mk).bind(this,e),{signal:d}),this._freeHighlight=new JS({x:s,y:A},[a,o,l,c],e.scale,this._defaultThickness/2,r,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,r,i){var y,v,b,C;let s=null;if(e instanceof WO){const{data:{quadPoints:x,rect:F,rotation:I,id:Q,color:R,opacity:L,popupRef:j,richText:U,contentsObj:k,creationDate:G,modificationDate:D},parent:{page:{pageNumber:rt}}}=e;s=e={annotationType:Fe.HIGHLIGHT,color:Array.from(R),opacity:L,quadPoints:x,boxes:null,pageIndex:rt-1,rect:F.slice(0),rotation:I,annotationElementId:Q,id:Q,deleted:!1,popupRef:j,richText:U,comment:(k==null?void 0:k.str)||null,creationDate:G,modificationDate:D}}else if(e instanceof B4){const{data:{inkLists:x,rect:F,rotation:I,id:Q,color:R,borderStyle:{rawWidth:L},popupRef:j,richText:U,contentsObj:k,creationDate:G,modificationDate:D},parent:{page:{pageNumber:rt}}}=e;s=e={annotationType:Fe.HIGHLIGHT,color:Array.from(R),thickness:L,inkLists:x,boxes:null,pageIndex:rt-1,rect:F.slice(0),rotation:I,annotationElementId:Q,id:Q,deleted:!1,popupRef:j,richText:U,comment:(k==null?void 0:k.str)||null,creationDate:G,modificationDate:D}}const{color:A,quadPoints:a,inkLists:o,outlines:l,opacity:c}=e,u=await super.deserialize(e,r,i);u.color=Mt.makeHexColor(...A),u.opacity=c||1,o&&E(u,$A,e.thickness),u._initialData=s,e.comment&&u.setCommentData(e);const[d,f]=u.pageDimensions,[m,p]=u.pageTranslation;if(a){const x=E(u,Vl,[]);for(let F=0;F<a.length;F+=8)x.push({x:(a[F]-m)/d,y:1-(a[F+1]-p)/f,width:(a[F+2]-a[F])/d,height:(a[F+1]-a[F+5])/f});P(y=u,Ge,ZS).call(y),P(v=u,Ge,bu).call(v),u.rotate(u.rotation)}else if(o||l){E(u,Un,!0);const x=(o||l.points)[0],F={x:x[0]-m,y:f-(x[1]-p)},I=new JS(F,[0,0,d,f],1,h(u,$A)/2,!0,.001);for(let L=0,j=x.length;L<j;L+=2)F.x=x[L]-m,F.y=f-(x[L+1]-p),I.add(F);const{id:Q,clipPathId:R}=r.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:I.toSVGPath()}},!0,!0);P(b=u,Ge,qy).call(b,{highlightOutlines:I.getOutlines(),highlightId:Q,clipPathId:R}),P(C=u,Ge,bu).call(C),u.rotate(u.parentRotation)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const r=Rr._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),i=super.serialize(e);return Object.assign(i,{color:r,opacity:this.opacity,thickness:h(this,$A),quadPoints:P(this,Ge,gk).call(this),outlines:P(this,Ge,pk).call(this,i.rect)}),this.addComment(i),this.annotationElementId&&!P(this,Ge,wk).call(this,i)?null:(i.id=this.annotationElementId,i)}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}};Ip=new WeakMap,p1=new WeakMap,Vl=new WeakMap,Rf=new WeakMap,m1=new WeakMap,Ks=new WeakMap,v1=new WeakMap,w1=new WeakMap,Df=new WeakMap,bA=new WeakMap,BA=new WeakMap,Un=new WeakMap,Up=new WeakMap,Lp=new WeakMap,ss=new WeakMap,Pp=new WeakMap,$A=new WeakMap,y1=new WeakMap,Ge=new WeakSet,ZS=function(){const e=new YS(h(this,Vl),.001);E(this,bA,e.getOutlines()),[this.x,this.y,this.width,this.height]=h(this,bA).box;const r=new YS(h(this,Vl),.0025,.001,this._uiManager.direction==="ltr");E(this,Ks,r.getOutlines());const{firstPoint:i}=h(this,bA);E(this,Up,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height]);const{lastPoint:s}=h(this,Ks);E(this,Lp,[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height])},qy=function({highlightOutlines:e,highlightId:r,clipPathId:i}){var d,f;if(E(this,bA,e),E(this,Ks,e.getNewOutline(h(this,$A)/2+1.5,.0025)),r>=0)E(this,BA,r),E(this,Rf,i),this.parent.drawLayer.finalizeDraw(r,{bbox:e.box,path:{d:e.toSVGPath()}}),E(this,ss,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:h(this,Ks).box,path:{d:h(this,Ks).toSVGPath()}},!0));else if(this.parent){const m=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(h(this,BA),{bbox:P(d=ar,ta,sg).call(d,h(this,bA).box,(m-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(h(this,ss),{bbox:P(f=ar,ta,sg).call(f,h(this,Ks).box,m),path:{d:h(this,Ks).toSVGPath()}})}const[A,a,o,l]=e.box;switch(this.rotation){case 0:this.x=A,this.y=a,this.width=o,this.height=l;break;case 90:{const[m,p]=this.parentDimensions;this.x=a,this.y=1-A,this.width=o*p/m,this.height=l*m/p;break}case 180:this.x=1-A,this.y=1-a,this.width=o,this.height=l;break;case 270:{const[m,p]=this.parentDimensions;this.x=1-a,this.y=A,this.width=o*p/m,this.height=l*m/p;break}}const{firstPoint:c}=e;E(this,Up,[(c[0]-A)/o,(c[1]-a)/l]);const{lastPoint:u}=h(this,Ks);E(this,Lp,[(u[0]-A)/o,(u[1]-a)/l])},hk=function(e){const r=(A,a)=>{this.color=A,this.opacity=a,this.onUpdatedColor()},i=this.color,s=this.opacity;this.addCommands({cmd:r.bind(this,e,ar._defaultOpacity),undo:r.bind(this,i,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Qe.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0)},uk=function(e){const r=h(this,$A),i=s=>{E(this,$A,s),P(this,Ge,fk).call(this,s)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Qe.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},fk=function(e){h(this,Un)&&(P(this,Ge,qy).call(this,{highlightOutlines:h(this,bA).getNewOutline(e/2)}),this.fixAndSetPosition(),this.setDims())},tF=function(){h(this,BA)===null||!this.parent||(this.parent.drawLayer.remove(h(this,BA)),E(this,BA,null),this.parent.drawLayer.remove(h(this,ss)),E(this,ss,null))},bu=function(e=this.parent){h(this,BA)===null&&({id:Di(this,BA)._,clipPathId:Di(this,Rf)._}=e.drawLayer.draw({bbox:h(this,bA).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:h(this,Un)},path:{d:h(this,bA).toSVGPath()}},!1,!0),E(this,ss,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:h(this,Un)},bbox:h(this,Ks).box,path:{d:h(this,Ks).toSVGPath()}},h(this,Un))),h(this,Df)&&(h(this,Df).style.clipPath=h(this,Rf)))},ta=new WeakSet,sg=function([e,r,i,s],A){switch(A){case 90:return[1-r-s,e,s,i];case 180:return[1-e-i,1-r-s,i,s];case 270:return[r,1-e-i,s,i]}return[e,r,i,s]},dk=function(e){ar._keyboardManager.exec(this,e)},Wy=function(e){if(!h(this,Ip))return;const r=window.getSelection();e?r.setPosition(h(this,Ip),h(this,p1)):r.setPosition(h(this,v1),h(this,w1))},zy=function(){return h(this,Un)?this.rotation:0},gk=function(){if(h(this,Un))return null;const[e,r]=this.pageDimensions,[i,s]=this.pageTranslation,A=h(this,Vl),a=new Float32Array(A.length*8);let o=0;for(const{x:l,y:c,width:u,height:d}of A){const f=l*e+i,m=(1-c)*r+s;a[o]=a[o+4]=f,a[o+1]=a[o+3]=m,a[o+2]=a[o+6]=f+u*e,a[o+5]=a[o+7]=m-d*r,o+=8}return a},pk=function(e){return h(this,bA).serialize(e,P(this,Ge,zy).call(this))},mk=function(e,r){this._freeHighlight.add(r)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},vk=function(e,r){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(r,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},wk=function(e){const{color:r}=this._initialData;return this.hasEditedComment||e.color.some((i,s)=>i!==r[s])},T(ar,ta),ht(ar,"_defaultColor",null),ht(ar,"_defaultOpacity",1),ht(ar,"_defaultThickness",12),ht(ar,"_type","highlight"),ht(ar,"_editorType",Fe.HIGHLIGHT),ht(ar,"_freeHighlightId",-1),ht(ar,"_freeHighlight",null),ht(ar,"_freeHighlightClipId","");let y2=ar;var Hf;class yk{constructor(){T(this,Hf,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,r]of Object.entries(t))e.startsWith("_")||this.updateProperty(e,r)}updateSVGProperty(t,e){h(this,Hf)[t]=e}toSVGProperties(){const t=h(this,Hf);return E(this,Hf,Object.create(null)),{root:t}}reset(){E(this,Hf,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){ur("Not implemented")}}Hf=new WeakMap;var bs,Np,fn,Kf,Gf,ir,eF,rF,iF,nm,bk,Xy,sm,Ag;const Xe=class Xe extends Rr{constructor(e){super(e);T(this,ir);T(this,bs,null);T(this,Np);ht(this,"_colorPicker",null);ht(this,"_drawId",null);E(this,Np,e.mustBeCommitted||!1),this._addOutlines(e)}onUpdatedColor(){var e;(e=this._colorPicker)==null||e.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){var e,r;(r=(e=this._colorPicker)==null?void 0:e.updateOpacity)==null||r.call(e,this.opacity)}_addOutlines(e){e.drawOutlines&&(P(this,ir,eF).call(this,e),P(this,ir,nm).call(this))}static _mergeSVGProperties(e,r){const i=new Set(Object.keys(e));for(const[s,A]of Object.entries(r))i.has(s)?Object.assign(e[s],A):e[s]=A;return e}static getDefaultDrawingOptions(e){ur("Not implemented")}static get typesMap(){ur("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,r){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,r),this._currentParent&&(h(Xe,fn).updateProperty(i,r),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,r){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,r)}static get defaultPropertiesToUpdate(){const e=[],r=this._defaultDrawingOptions;for(const[i,s]of this.typesMap)e.push([i,r[s]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:r}=this;for(const[i,s]of this.constructor.typesMap)e.push([i,r[s]]);return e}_updateProperty(e,r,i){const s=this._drawingOptions,A=s[r],a=o=>{var c;s.updateProperty(r,o);const l=h(this,bs).updateProperty(r,o);l&&P(this,ir,sm).call(this,l),(c=this.parent)==null||c.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,i),undo:a.bind(this,A),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,r){const i=this.constructor.typesMap.get(this.colorType),s=this.constructor.typesMap.get(this.opacityType),A=this._drawingOptions,a=A[i],o=A[s],l=(c,u)=>{var d;A.updateProperty(i,c),A.updateProperty(s,u),h(this,bs).updateProperty(i,c),h(this,bs).updateProperty(s,u),(d=this.parent)==null||d.drawLayer.updateProperties(this._drawId,A.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:l.bind(this,e,r),undo:l.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Qe.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Xe._mergeSVGProperties(h(this,bs).getPathResizingSVGProperties(P(this,ir,Xy).call(this)),{bbox:P(this,ir,Ag).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Xe._mergeSVGProperties(h(this,bs).getPathResizedSVGProperties(P(this,ir,Xy).call(this)),{bbox:P(this,ir,Ag).call(this)}))}_onTranslating(e,r){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:P(this,ir,Ag).call(this)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Xe._mergeSVGProperties(h(this,bs).getPathTranslatedSVGProperties(P(this,ir,Xy).call(this),this.parentDimensions),{bbox:P(this,ir,Ag).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,h(this,Np)&&(E(this,Np,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){P(this,ir,iF).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(P(this,ir,nm).call(this),P(this,ir,sm).call(this,h(this,bs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let r=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),P(this,ir,iF).call(this)):e&&(this._uiManager.addShouldRescale(this),P(this,ir,nm).call(this,e),r=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),r&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Xe._mergeSVGProperties({bbox:P(this,ir,Ag).call(this)},h(this,bs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&P(this,ir,sm).call(this,h(this,bs).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,r;this._isCopy&&(e=this.x,r=this.y);const i=super.render();i.classList.add("draw");const s=document.createElement("div");return i.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,r),i}static createDrawerInstance(e,r,i,s,A){ur("Not implemented")}static startDrawing(e,r,i,s){var y;const{target:A,offsetX:a,offsetY:o,pointerId:l,pointerType:c}=s;if(es.isInitializedAndDifferentPointerType(c))return;const{viewport:{rotation:u}}=e,{width:d,height:f}=A.getBoundingClientRect(),m=E(Xe,Kf,new AbortController),p=e.combinedSignal(m);if(es.setPointer(c,l),window.addEventListener("pointerup",v=>{es.isSamePointerIdOrRemove(v.pointerId)&&this._endDraw(v)},{signal:p}),window.addEventListener("pointercancel",v=>{es.isSamePointerIdOrRemove(v.pointerId)&&this._currentParent.endDrawingSession()},{signal:p}),window.addEventListener("pointerdown",v=>{es.isSamePointerType(v.pointerType)&&(es.initializeAndAddPointerId(v.pointerId),h(Xe,fn).isCancellable()&&(h(Xe,fn).removeLastElement(),h(Xe,fn).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:p}),window.addEventListener("contextmenu",UA,{signal:p}),A.addEventListener("pointermove",this._drawMove.bind(this),{signal:p}),A.addEventListener("touchmove",v=>{es.isSameTimeStamp(v.timeStamp)&&Zr(v)},{signal:p}),e.toggleDrawing(),(y=r._editorUndoBar)==null||y.hide(),h(Xe,fn)){e.drawLayer.updateProperties(this._currentDrawId,h(Xe,fn).startNew(a,o,d,f,u));return}r.updateUIForDefaultProperties(this),E(Xe,fn,this.createDrawerInstance(a,o,d,f,u)),E(Xe,Gf,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(h(Xe,Gf).toSVGProperties(),h(Xe,fn).defaultSVGProperties),!0,!1)}static _drawMove(e){if(es.isSameTimeStamp(e.timeStamp),!h(Xe,fn))return;const{offsetX:r,offsetY:i,pointerId:s}=e;if(es.isSamePointerId(s)){if(es.isUsingMultiplePointers()){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,h(Xe,fn).add(r,i)),es.setTimeStamp(e.timeStamp),Zr(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,E(Xe,fn,null),E(Xe,Gf,null),es.clearTimeStamp()),h(Xe,Kf)&&(h(Xe,Kf).abort(),E(Xe,Kf,null),es.clearPointerIds())}static _endDraw(e){const r=this._currentParent;if(r){if(r.toggleDrawing(!0),this._cleanup(!1),(e==null?void 0:e.target)===r.div&&r.drawLayer.updateProperties(this._currentDrawId,h(Xe,fn).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=h(Xe,fn),s=this._currentDrawId,A=i.getLastElement();r.addCommands({cmd:()=>{r.drawLayer.updateProperties(s,i.setLastElement(A))},undo:()=>{r.drawLayer.updateProperties(s,i.removeLastElement())},mustExec:!1,type:Qe.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const r=this._currentParent;if(!r)return null;if(r.toggleDrawing(!0),r.cleanUndoStack(Qe.DRAW_STEP),!h(Xe,fn).isEmpty()){const{pageDimensions:[i,s],scale:A}=r,a=r.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:h(Xe,fn).getOutlines(i*A,s*A,A,this._INNER_MARGIN),drawingOptions:h(Xe,Gf),mustBeCommitted:!e});return this._cleanup(!0),a}return r.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,r,i,s,A,a){ur("Not implemented")}static async deserialize(e,r,i){var u,d;const{rawDims:{pageWidth:s,pageHeight:A,pageX:a,pageY:o}}=r.viewport,l=this.deserializeDraw(a,o,s,A,this._INNER_MARGIN,e),c=await super.deserialize(e,r,i);return c.createDrawingOptions(e),P(u=c,ir,eF).call(u,{drawOutlines:l}),P(d=c,ir,nm).call(d),c.onScaleChanging(),c.rotate(),c}serializeDraw(e){const[r,i]=this.pageTranslation,[s,A]=this.pageDimensions;return h(this,bs).serialize([r,i,s,A],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}};bs=new WeakMap,Np=new WeakMap,fn=new WeakMap,Kf=new WeakMap,Gf=new WeakMap,ir=new WeakSet,eF=function({drawOutlines:e,drawId:r,drawingOptions:i}){E(this,bs,e),this._drawingOptions||(this._drawingOptions=i),this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`),r>=0?(this._drawId=r,this.parent.drawLayer.finalizeDraw(r,e.defaultProperties)):this._drawId=P(this,ir,rF).call(this,e,this.parent),P(this,ir,sm).call(this,e.box)},rF=function(e,r){const{id:i}=r.drawLayer.draw(Xe._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},iF=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},nm=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=P(this,ir,rF).call(this,h(this,bs),e)}},bk=function([e,r,i,s]){const{parentDimensions:[A,a],rotation:o}=this;switch(o){case 90:return[r,1-e,i*(a/A),s*(A/a)];case 180:return[1-e,1-r,i,s];case 270:return[1-r,e,i*(a/A),s*(A/a)];default:return[e,r,i,s]}},Xy=function(){const{x:e,y:r,width:i,height:s,parentDimensions:[A,a],rotation:o}=this;switch(o){case 90:return[1-r,e,i*(A/a),s*(a/A)];case 180:return[1-e,1-r,i,s];case 270:return[r,1-e,i*(A/a),s*(a/A)];default:return[e,r,i,s]}},sm=function(e){[this.x,this.y,this.width,this.height]=P(this,ir,bk).call(this,e),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()},Ag=function(){const{x:e,y:r,width:i,height:s,rotation:A,parentRotation:a,parentDimensions:[o,l]}=this;switch((A*4+a)/90){case 1:return[1-r-s,e,s,i];case 2:return[1-e-i,1-r-s,i,s];case 3:return[r,1-e-i,s,i];case 4:return[e,r-i*(o/l),s*(l/o),i*(o/l)];case 5:return[1-r,e,i*(o/l),s*(l/o)];case 6:return[1-e-s*(l/o),1-r,s*(l/o),i*(o/l)];case 7:return[r-i*(o/l),1-e-s*(l/o),i*(o/l),s*(l/o)];case 8:return[e-i,r-s,i,s];case 9:return[1-r,e-i,s,i];case 10:return[1-e,1-r,i,s];case 11:return[r-s,1-e,s,i];case 12:return[e-s*(l/o),r,s*(l/o),i*(o/l)];case 13:return[1-r-i*(o/l),e-s*(l/o),i*(o/l),s*(l/o)];case 14:return[1-e,1-r-i*(o/l),s*(l/o),i*(o/l)];case 15:return[r,1-e,i*(o/l),s*(l/o)];default:return[e,r,i,s]}},ht(Xe,"_currentDrawId",-1),ht(Xe,"_currentParent",null),T(Xe,fn,null),T(Xe,Kf,null),T(Xe,Gf,null),ht(Xe,"_INNER_MARGIN",3);let b2=Xe;var Eo,dn,gn,jf,Qp,Bs,Ln,JA,Vf,qf,Wf,Mp,Yy;class mj{constructor(t,e,r,i,s,A){T(this,Mp);T(this,Eo,new Float64Array(6));T(this,dn);T(this,gn);T(this,jf);T(this,Qp);T(this,Bs);T(this,Ln,"");T(this,JA,0);T(this,Vf,new O1);T(this,qf);T(this,Wf);E(this,qf,r),E(this,Wf,i),E(this,jf,s),E(this,Qp,A),[t,e]=P(this,Mp,Yy).call(this,t,e);const a=E(this,dn,[NaN,NaN,NaN,NaN,t,e]);E(this,Bs,[t,e]),E(this,gn,[{line:a,points:h(this,Bs)}]),h(this,Eo).set(a,0)}updateProperty(t,e){t==="stroke-width"&&E(this,Qp,e)}isEmpty(){return!h(this,gn)||h(this,gn).length===0}isCancellable(){return h(this,Bs).length<=10}add(t,e){[t,e]=P(this,Mp,Yy).call(this,t,e);const[r,i,s,A]=h(this,Eo).subarray(2,6),a=t-s,o=e-A;return Math.hypot(h(this,qf)*a,h(this,Wf)*o)<=2?null:(h(this,Bs).push(t,e),isNaN(r)?(h(this,Eo).set([s,A,t,e],2),h(this,dn).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(h(this,Eo)[0])&&h(this,dn).splice(6,6),h(this,Eo).set([r,i,s,A,t,e],0),h(this,dn).push(...re.createBezierPoints(r,i,s,A,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const r=this.add(t,e);return r||(h(this,Bs).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,r,i,s){E(this,qf,r),E(this,Wf,i),E(this,jf,s),[t,e]=P(this,Mp,Yy).call(this,t,e);const A=E(this,dn,[NaN,NaN,NaN,NaN,t,e]);E(this,Bs,[t,e]);const a=h(this,gn).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),h(this,gn).push({line:A,points:h(this,Bs)}),h(this,Eo).set(A,0),E(this,JA,0),this.toSVGPath(),null}getLastElement(){return h(this,gn).at(-1)}setLastElement(t){return h(this,gn)?(h(this,gn).push(t),E(this,dn,t.line),E(this,Bs,t.points),E(this,JA,0),{path:{d:this.toSVGPath()}}):h(this,Vf).setLastElement(t)}removeLastElement(){if(!h(this,gn))return h(this,Vf).removeLastElement();h(this,gn).pop(),E(this,Ln,"");for(let t=0,e=h(this,gn).length;t<e;t++){const{line:r,points:i}=h(this,gn)[t];E(this,dn,r),E(this,Bs,i),E(this,JA,0),this.toSVGPath()}return{path:{d:h(this,Ln)}}}toSVGPath(){const t=re.svgRound(h(this,dn)[4]),e=re.svgRound(h(this,dn)[5]);if(h(this,Bs).length===2)return E(this,Ln,`${h(this,Ln)} M ${t} ${e} Z`),h(this,Ln);if(h(this,Bs).length<=6){const i=h(this,Ln).lastIndexOf("M");E(this,Ln,`${h(this,Ln).slice(0,i)} M ${t} ${e}`),E(this,JA,6)}if(h(this,Bs).length===4){const i=re.svgRound(h(this,dn)[10]),s=re.svgRound(h(this,dn)[11]);return E(this,Ln,`${h(this,Ln)} L ${i} ${s}`),E(this,JA,12),h(this,Ln)}const r=[];h(this,JA)===0&&(r.push(`M ${t} ${e}`),E(this,JA,6));for(let i=h(this,JA),s=h(this,dn).length;i<s;i+=6){const[A,a,o,l,c,u]=h(this,dn).slice(i,i+6).map(re.svgRound);r.push(`C${A} ${a} ${o} ${l} ${c} ${u}`)}return E(this,Ln,h(this,Ln)+r.join(" ")),E(this,JA,h(this,dn).length),h(this,Ln)}getOutlines(t,e,r,i){const s=h(this,gn).at(-1);return s.line=new Float32Array(s.line),s.points=new Float32Array(s.points),h(this,Vf).build(h(this,gn),t,e,r,h(this,jf),h(this,Qp),i),E(this,Eo,null),E(this,dn,null),E(this,gn,null),E(this,Ln,null),h(this,Vf)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Eo=new WeakMap,dn=new WeakMap,gn=new WeakMap,jf=new WeakMap,Qp=new WeakMap,Bs=new WeakMap,Ln=new WeakMap,JA=new WeakMap,Vf=new WeakMap,qf=new WeakMap,Wf=new WeakMap,Mp=new WeakSet,Yy=function(t,e){return re._normalizePoint(t,e,h(this,qf),h(this,Wf),h(this,jf))};var Cs,b1,B1,CA,So,Fo,Op,kp,zf,Qn,hl,Bk,Ck,xk;class O1 extends re{constructor(){super(...arguments);T(this,Qn);T(this,Cs);T(this,b1,0);T(this,B1);T(this,CA);T(this,So);T(this,Fo);T(this,Op);T(this,kp);T(this,zf)}build(e,r,i,s,A,a,o){E(this,So,r),E(this,Fo,i),E(this,Op,s),E(this,kp,A),E(this,zf,a),E(this,B1,o??0),E(this,CA,e),P(this,Qn,Ck).call(this)}get thickness(){return h(this,zf)}setLastElement(e){return h(this,CA).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return h(this,CA).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:r}of h(this,CA)){if(e.push(`M${re.svgRound(r[4])} ${re.svgRound(r[5])}`),r.length===6){e.push("Z");continue}if(r.length===12&&isNaN(r[6])){e.push(`L${re.svgRound(r[10])} ${re.svgRound(r[11])}`);continue}for(let i=6,s=r.length;i<s;i+=6){const[A,a,o,l,c,u]=r.subarray(i,i+6).map(re.svgRound);e.push(`C${A} ${a} ${o} ${l} ${c} ${u}`)}}return e.join("")}serialize([e,r,i,s],A){const a=[],o=[],[l,c,u,d]=P(this,Qn,Bk).call(this);let f,m,p,y,v,b,C,x,F;switch(h(this,kp)){case 0:F=re._rescale,f=e,m=r+s,p=i,y=-s,v=e+l*i,b=r+(1-c-d)*s,C=e+(l+u)*i,x=r+(1-c)*s;break;case 90:F=re._rescaleAndSwap,f=e,m=r,p=i,y=s,v=e+c*i,b=r+l*s,C=e+(c+d)*i,x=r+(l+u)*s;break;case 180:F=re._rescale,f=e+i,m=r,p=-i,y=s,v=e+(1-l-u)*i,b=r+c*s,C=e+(1-l)*i,x=r+(c+d)*s;break;case 270:F=re._rescaleAndSwap,f=e+i,m=r+s,p=-i,y=-s,v=e+(1-c-d)*i,b=r+(1-l-u)*s,C=e+(1-c)*i,x=r+(1-l)*s;break}for(const{line:I,points:Q}of h(this,CA))a.push(F(I,f,m,p,y,A?new Array(I.length):null)),o.push(F(Q,f,m,p,y,A?new Array(Q.length):null));return{lines:a,points:o,rect:[v,b,C,x]}}static deserialize(e,r,i,s,A,{paths:{lines:a,points:o},rotation:l,thickness:c}){const u=[];let d,f,m,p,y;switch(l){case 0:y=re._rescale,d=-e/i,f=r/s+1,m=1/i,p=-1/s;break;case 90:y=re._rescaleAndSwap,d=-r/s,f=-e/i,m=1/s,p=1/i;break;case 180:y=re._rescale,d=e/i+1,f=-r/s,m=-1/i,p=1/s;break;case 270:y=re._rescaleAndSwap,d=r/s+1,f=e/i+1,m=-1/s,p=-1/i;break}if(!a){a=[];for(const b of o){const C=b.length;if(C===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1]]));continue}if(C===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1],NaN,NaN,NaN,NaN,b[2],b[3]]));continue}const x=new Float32Array(3*(C-2));a.push(x);let[F,I,Q,R]=b.subarray(0,4);x.set([NaN,NaN,NaN,NaN,F,I],0);for(let L=4;L<C;L+=2){const j=b[L],U=b[L+1];x.set(re.createBezierPoints(F,I,Q,R,j,U),(L-2)*3),[F,I,Q,R]=[Q,R,j,U]}}}for(let b=0,C=a.length;b<C;b++)u.push({line:y(a[b].map(x=>x??NaN),d,f,m,p),points:y(o[b].map(x=>x??NaN),d,f,m,p)});const v=new this.prototype.constructor;return v.build(u,i,s,1,l,c,A),v}get box(){return h(this,Cs)}updateProperty(e,r){return e==="stroke-width"?P(this,Qn,xk).call(this,r):null}updateParentDimensions([e,r],i){const[s,A]=P(this,Qn,hl).call(this);E(this,So,e),E(this,Fo,r),E(this,Op,i);const[a,o]=P(this,Qn,hl).call(this),l=a-s,c=o-A,u=h(this,Cs);return u[0]-=l,u[1]-=c,u[2]+=2*l,u[3]+=2*c,u}updateRotation(e){return E(this,b1,e),{path:{transform:this.rotationTransform}}}get viewBox(){return h(this,Cs).map(re.svgRound).join(" ")}get defaultProperties(){const[e,r]=h(this,Cs);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`}}}get rotationTransform(){const[,,e,r]=h(this,Cs);let i=0,s=0,A=0,a=0,o=0,l=0;switch(h(this,b1)){case 90:s=r/e,A=-e/r,o=e;break;case 180:i=-1,a=-1,o=e,l=r;break;case 270:s=-r/e,A=e/r,l=r;break;default:return""}return`matrix(${i} ${s} ${A} ${a} ${re.svgRound(o)} ${re.svgRound(l)})`}getPathResizingSVGProperties([e,r,i,s]){const[A,a]=P(this,Qn,hl).call(this),[o,l,c,u]=h(this,Cs);if(Math.abs(c-A)<=re.PRECISION||Math.abs(u-a)<=re.PRECISION){const y=e+i/2-(o+c/2),v=r+s/2-(l+u/2);return{path:{"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`,transform:`${this.rotationTransform} translate(${y} ${v})`}}}const d=(i-2*A)/(c-2*A),f=(s-2*a)/(u-2*a),m=c/i,p=u/s;return{path:{"transform-origin":`${re.svgRound(o)} ${re.svgRound(l)}`,transform:`${this.rotationTransform} scale(${m} ${p}) translate(${re.svgRound(A)} ${re.svgRound(a)}) scale(${d} ${f}) translate(${re.svgRound(-A)} ${re.svgRound(-a)})`}}}getPathResizedSVGProperties([e,r,i,s]){const[A,a]=P(this,Qn,hl).call(this),o=h(this,Cs),[l,c,u,d]=o;if(o[0]=e,o[1]=r,o[2]=i,o[3]=s,Math.abs(u-A)<=re.PRECISION||Math.abs(d-a)<=re.PRECISION){const v=e+i/2-(l+u/2),b=r+s/2-(c+d/2);for(const{line:C,points:x}of h(this,CA))re._translate(C,v,b,C),re._translate(x,v,b,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const f=(i-2*A)/(u-2*A),m=(s-2*a)/(d-2*a),p=-f*(l+A)+e+A,y=-m*(c+a)+r+a;if(f!==1||m!==1||p!==0||y!==0)for(const{line:v,points:b}of h(this,CA))re._rescale(v,p,y,f,m,v),re._rescale(b,p,y,f,m,b);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,r],i){const[s,A]=i,a=h(this,Cs),o=e-a[0],l=r-a[1];if(h(this,So)===s&&h(this,Fo)===A)for(const{line:c,points:u}of h(this,CA))re._translate(c,o,l,c),re._translate(u,o,l,u);else{const c=h(this,So)/s,u=h(this,Fo)/A;E(this,So,s),E(this,Fo,A);for(const{line:d,points:f}of h(this,CA))re._rescale(d,o,l,c,u,d),re._rescale(f,o,l,c,u,f);a[2]*=c,a[3]*=u}return a[0]=e,a[1]=r,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`}}}get defaultSVGProperties(){const e=h(this,Cs);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${re.svgRound(e[0])} ${re.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}Cs=new WeakMap,b1=new WeakMap,B1=new WeakMap,CA=new WeakMap,So=new WeakMap,Fo=new WeakMap,Op=new WeakMap,kp=new WeakMap,zf=new WeakMap,Qn=new WeakSet,hl=function(e=h(this,zf)){const r=h(this,B1)+e/2*h(this,Op);return h(this,kp)%180===0?[r/h(this,So),r/h(this,Fo)]:[r/h(this,Fo),r/h(this,So)]},Bk=function(){const[e,r,i,s]=h(this,Cs),[A,a]=P(this,Qn,hl).call(this,0);return[e+A,r+a,i-2*A,s-2*a]},Ck=function(){const e=E(this,Cs,_u.slice());for(const{line:s}of h(this,CA)){if(s.length<=12){for(let o=4,l=s.length;o<l;o+=6)Mt.pointBoundingBox(s[o],s[o+1],e);continue}let A=s[4],a=s[5];for(let o=6,l=s.length;o<l;o+=6){const[c,u,d,f,m,p]=s.subarray(o,o+6);Mt.bezierBoundingBox(A,a,c,u,d,f,m,p,e),A=m,a=p}}const[r,i]=P(this,Qn,hl).call(this);e[0]=Wr(e[0]-r,0,1),e[1]=Wr(e[1]-i,0,1),e[2]=Wr(e[2]+r,0,1),e[3]=Wr(e[3]+i,0,1),e[2]-=e[0],e[3]-=e[1]},xk=function(e){const[r,i]=P(this,Qn,hl).call(this);E(this,zf,e);const[s,A]=P(this,Qn,hl).call(this),[a,o]=[s-r,A-i],l=h(this,Cs);return l[0]-=a,l[1]-=o,l[2]+=2*a,l[3]+=2*o,l};class Ib extends yk{constructor(t){super(),this._viewParameters=t,super.updateProperties({fill:"none",stroke:Rr._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??(e=this["stroke-width"]),e*=this._viewParameters.realScale),super.updateSVGProperty(t,e)}clone(){const t=new Ib(this._viewParameters);return t.updateAll(this),t}}var sb,Ek;const fg=class fg extends b2{constructor(e){super({...e,name:"inkEditor"});T(this,sb);this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(e,r){Rr.initialize(e,r),this._defaultDrawingOptions=new Ib(r.viewParameters)}static getDefaultDrawingOptions(e){const r=this._defaultDrawingOptions.clone();return r.updateProperties(e),r}static get supportMultipleDrawings(){return!0}static get typesMap(){return Te(this,"typesMap",new Map([[Qe.INK_THICKNESS,"stroke-width"],[Qe.INK_COLOR,"stroke"],[Qe.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,r,i,s,A){return new mj(e,r,i,s,A,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,r,i,s,A,a){return O1.deserialize(e,r,i,s,A,a)}static async deserialize(e,r,i){let s=null;if(e instanceof B4){const{data:{inkLists:a,rect:o,rotation:l,id:c,color:u,opacity:d,borderStyle:{rawWidth:f},popupRef:m,richText:p,contentsObj:y,creationDate:v,modificationDate:b},parent:{page:{pageNumber:C}}}=e;s=e={annotationType:Fe.INK,color:Array.from(u),thickness:f,opacity:d,paths:{points:a},boxes:null,pageIndex:C-1,rect:o.slice(0),rotation:l,annotationElementId:c,id:c,deleted:!1,popupRef:m,richText:p,comment:(y==null?void 0:y.str)||null,creationDate:v,modificationDate:b}}const A=await super.deserialize(e,r,i);return A._initialData=s,e.comment&&A.setCommentData(e),A}get toolbarButtons(){return this._colorPicker||(this._colorPicker=new m2(this)),[["colorPicker",this._colorPicker]]}get colorType(){return Qe.INK_COLOR}get colorAndOpacityType(){return Qe.INK_COLOR_AND_OPACITY}get opacityType(){return Qe.INK_OPACITY}updateParams(e,r){if(e===Qe.INK_COLOR_AND_OPACITY){this._updateColorAndOpacity(r.color,r.opacity);return}super.updateParams(e,r)}static updateDefaultParams(e,r){if(e===Qe.INK_COLOR_AND_OPACITY){super.updateDefaultParams(Qe.INK_COLOR,r.color),super.updateDefaultParams(Qe.INK_OPACITY,r.opacity);return}super.updateDefaultParams(e,r)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:r,parent:i}=this;r.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,r.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:r,opacity:i}){this._drawingOptions=fg.getDefaultDrawingOptions({stroke:Mt.makeHexColor(...e),"stroke-width":r,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:r,points:i}=this.serializeDraw(e),{_drawingOptions:{stroke:s,"stroke-opacity":A,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:Rr._colorManager.convert(s),opacity:A,thickness:a,paths:{lines:r,points:i}});return this.addComment(o),e?(o.isCopy=!0,o):this.annotationElementId&&!P(this,sb,Ek).call(this,o)?null:(o.id=this.annotationElementId,o)}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;const{points:r,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:r,popup:this.comment}),null}};sb=new WeakSet,Ek=function(e){const{color:r,thickness:i,opacity:s,pageIndex:A}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((a,o)=>a!==r[o])||e.thickness!==i||e.opacity!==s||e.pageIndex!==A},ht(fg,"_type","ink"),ht(fg,"_editorType",Fe.INK),ht(fg,"_defaultDrawingOptions",null);let nF=fg;class sF extends O1{toSVGPath(){let t=super.toSVGPath();return t.endsWith("Z")||(t+="Z"),t}}const Rw=8,I0=3;var Xf,fr,AF,La,Sk,Fk,aF,$y,_k,Tk,Ik,oF,lF,Uk;class No{static extractContoursFromText(t,{fontFamily:e,fontStyle:r,fontWeight:i},s,A,a,o){let l=new OffscreenCanvas(1,1),c=l.getContext("2d",{alpha:!1});const u=200,d=c.font=`${r} ${i} ${u}px ${e}`,{actualBoundingBoxLeft:f,actualBoundingBoxRight:m,actualBoundingBoxAscent:p,actualBoundingBoxDescent:y,fontBoundingBoxAscent:v,fontBoundingBoxDescent:b,width:C}=c.measureText(t),x=1.5,F=Math.ceil(Math.max(Math.abs(f)+Math.abs(m)||0,C)*x),I=Math.ceil(Math.max(Math.abs(p)+Math.abs(y)||u,Math.abs(v)+Math.abs(b)||u)*x);l=new OffscreenCanvas(F,I),c=l.getContext("2d",{alpha:!0,willReadFrequently:!0}),c.font=d,c.filter="grayscale(1)",c.fillStyle="white",c.fillRect(0,0,F,I),c.fillStyle="black",c.fillText(t,F*(x-1)/2,I*(3-x)/2);const Q=P(this,fr,oF).call(this,c.getImageData(0,0,F,I).data),R=P(this,fr,Ik).call(this,Q),L=P(this,fr,lF).call(this,R),j=P(this,fr,aF).call(this,Q,F,I,L);return this.processDrawnLines({lines:{curves:j,width:F,height:I},pageWidth:s,pageHeight:A,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,r,i,s){const[A,a,o]=P(this,fr,Uk).call(this,t),[l,c]=P(this,fr,Tk).call(this,A,a,o,Math.hypot(a,o)*h(this,Xf).sigmaSFactor,h(this,Xf).sigmaR,h(this,Xf).kernelSize),u=P(this,fr,lF).call(this,c),d=P(this,fr,aF).call(this,l,a,o,u);return this.processDrawnLines({lines:{curves:d,width:a,height:o},pageWidth:e,pageHeight:r,rotation:i,innerMargin:s,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:r,rotation:i,innerMargin:s,mustSmooth:A,areContours:a}){i%180!==0&&([e,r]=[r,e]);const{curves:o,width:l,height:c}=t,u=t.thickness??0,d=[],f=Math.min(e/l,r/c),m=f/e,p=f/r,y=[];for(const{points:b}of o){const C=A?P(this,fr,_k).call(this,b):b;if(!C)continue;y.push(C);const x=C.length,F=new Float32Array(x),I=new Float32Array(3*(x===2?2:x-2));if(d.push({line:I,points:F}),x===2){F[0]=C[0]*m,F[1]=C[1]*p,I.set([NaN,NaN,NaN,NaN,F[0],F[1]],0);continue}let[Q,R,L,j]=C;Q*=m,R*=p,L*=m,j*=p,F.set([Q,R,L,j],0),I.set([NaN,NaN,NaN,NaN,Q,R],0);for(let U=4;U<x;U+=2){const k=F[U]=C[U]*m,G=F[U+1]=C[U+1]*p;I.set(re.createBezierPoints(Q,R,L,j,k,G),(U-2)*3),[Q,R,L,j]=[L,j,k,G]}}if(d.length===0)return null;const v=a?new sF:new O1;return v.build(d,e,r,1,i,a?0:u,s),{outline:v,newCurves:y,areContours:a,thickness:u,width:l,height:c}}static async compressSignature({outlines:t,areContours:e,thickness:r,width:i,height:s}){let A=1/0,a=-1/0,o=0;for(const b of t){o+=b.length;for(let C=2,x=b.length;C<x;C++){const F=b[C]-b[C-2];A=Math.min(A,F),a=Math.max(a,F)}}let l;A>=-128&&a<=127?l=Int8Array:A>=-32768&&a<=32767?l=Int16Array:l=Int32Array;const c=t.length,u=Rw+I0*c,d=new Uint32Array(u);let f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(o-2*c)*l.BYTES_PER_ELEMENT,d[f++]=0,d[f++]=i,d[f++]=s,d[f++]=e?0:1,d[f++]=Math.max(0,Math.floor(r??0)),d[f++]=c,d[f++]=l.BYTES_PER_ELEMENT;for(const b of t)d[f++]=b.length-2,d[f++]=b[0],d[f++]=b[1];const m=new CompressionStream("deflate-raw"),p=m.writable.getWriter();await p.ready,p.write(d);const y=l.prototype.constructor;for(const b of t){const C=new y(b.length-2);for(let x=2,F=b.length;x<F;x++)C[x-2]=b[x]-b[x-2];p.write(C)}return p.close(),(await new Response(m.readable).bytes()).toBase64()}static async decompressSignature(t){try{const e=Uint8Array.fromBase64(t),{readable:r,writable:i}=new DecompressionStream("deflate-raw"),s=i.getWriter();await s.ready,s.write(e).then(async()=>{await s.ready,await s.close()}).catch(()=>{});let A=null,a=0;for await(const C of r)A||(A=new Uint8Array(new Uint32Array(C.buffer,0,4)[0])),A.set(C,a),a+=C.length;const o=new Uint32Array(A.buffer,0,A.length>>2),l=o[1];if(l!==0)throw new Error(`Invalid version: ${l}`);const c=o[2],u=o[3],d=o[4]===0,f=o[5],m=o[6],p=o[7],y=[],v=(Rw+I0*m)*Uint32Array.BYTES_PER_ELEMENT;let b;switch(p){case Int8Array.BYTES_PER_ELEMENT:b=new Int8Array(A.buffer,v);break;case Int16Array.BYTES_PER_ELEMENT:b=new Int16Array(A.buffer,v);break;case Int32Array.BYTES_PER_ELEMENT:b=new Int32Array(A.buffer,v);break}a=0;for(let C=0;C<m;C++){const x=o[I0*C+Rw],F=new Float32Array(x+2);y.push(F);for(let I=0;I<I0-1;I++)F[I]=o[I0*C+Rw+I+1];for(let I=0;I<x;I++)F[I+2]=F[I]+b[a++]}return{areContours:d,thickness:f,outlines:y,width:c,height:u}}catch(e){return Me(`decompressSignature: ${e}`),null}}}Xf=new WeakMap,fr=new WeakSet,AF=function(t,e,r,i){return r-=t,i-=e,r===0?i>0?0:4:r===1?i+6:2-i},La=new WeakMap,Sk=function(t,e,r,i,s,A,a){const o=P(this,fr,AF).call(this,r,i,s,A);for(let l=0;l<8;l++){const c=(-l+o-a+16)%8,u=h(this,La)[2*c],d=h(this,La)[2*c+1];if(t[(r+u)*e+(i+d)]!==0)return c}return-1},Fk=function(t,e,r,i,s,A,a){const o=P(this,fr,AF).call(this,r,i,s,A);for(let l=0;l<8;l++){const c=(l+o+a+16)%8,u=h(this,La)[2*c],d=h(this,La)[2*c+1];if(t[(r+u)*e+(i+d)]!==0)return c}return-1},aF=function(t,e,r,i){const s=t.length,A=new Int32Array(s);for(let c=0;c<s;c++)A[c]=t[c]<=i?1:0;for(let c=1;c<r-1;c++)A[c*e]=A[c*e+e-1]=0;for(let c=0;c<e;c++)A[c]=A[e*r-1-c]=0;let a=1,o;const l=[];for(let c=1;c<r-1;c++){o=1;for(let u=1;u<e-1;u++){const d=c*e+u,f=A[d];if(f===0)continue;let m=c,p=u;if(f===1&&A[d-1]===0)a+=1,p-=1;else if(f>=1&&A[d+1]===0)a+=1,p+=1,f>1&&(o=f);else{f!==1&&(o=Math.abs(f));continue}const y=[u,c],v=p===u+1,b={isHole:v,points:y,id:a,parent:0};l.push(b);let C;for(const U of l)if(U.id===o){C=U;break}C?C.isHole?b.parent=v?C.parent:o:b.parent=v?o:C.parent:b.parent=v?o:0;const x=P(this,fr,Sk).call(this,A,e,c,u,m,p,0);if(x===-1){A[d]=-a,A[d]!==1&&(o=Math.abs(A[d]));continue}let F=h(this,La)[2*x],I=h(this,La)[2*x+1];const Q=c+F,R=u+I;m=Q,p=R;let L=c,j=u;for(;;){const U=P(this,fr,Fk).call(this,A,e,L,j,m,p,1);F=h(this,La)[2*U],I=h(this,La)[2*U+1];const k=L+F,G=j+I;y.push(G,k);const D=L*e+j;if(A[D+1]===0?A[D]=-a:A[D]===1&&(A[D]=a),k===c&&G===u&&L===Q&&j===R){A[d]!==1&&(o=Math.abs(A[d]));break}else m=L,p=j,L=k,j=G}}}return l},$y=function(t,e,r,i){if(r-e<=4){for(let Q=e;Q<r-2;Q+=2)i.push(t[Q],t[Q+1]);return}const s=t[e],A=t[e+1],a=t[r-4]-s,o=t[r-3]-A,l=Math.hypot(a,o),c=a/l,u=o/l,d=c*A-u*s,f=o/a,m=1/l,p=Math.atan(f),y=Math.cos(p),v=Math.sin(p),b=m*(Math.abs(y)+Math.abs(v)),C=m*(1-b+b**2),x=Math.max(Math.atan(Math.abs(v+y)*C),Math.atan(Math.abs(v-y)*C));let F=0,I=e;for(let Q=e+2;Q<r-2;Q+=2){const R=Math.abs(d-c*t[Q+1]+u*t[Q]);R>F&&(I=Q,F=R)}F>(l*x)**2?(P(this,fr,$y).call(this,t,e,I+2,i),P(this,fr,$y).call(this,t,I,r,i)):i.push(s,A)},_k=function(t){const e=[],r=t.length;return P(this,fr,$y).call(this,t,0,r,e),e.push(t[r-2],t[r-1]),e.length<=4?null:e},Tk=function(t,e,r,i,s,A){const a=new Float32Array(A**2),o=-2*i**2,l=A>>1;for(let p=0;p<A;p++){const y=(p-l)**2;for(let v=0;v<A;v++)a[p*A+v]=Math.exp((y+(v-l)**2)/o)}const c=new Float32Array(256),u=-2*s**2;for(let p=0;p<256;p++)c[p]=Math.exp(p**2/u);const d=t.length,f=new Uint8Array(d),m=new Uint32Array(256);for(let p=0;p<r;p++)for(let y=0;y<e;y++){const v=p*e+y,b=t[v];let C=0,x=0;for(let I=0;I<A;I++){const Q=p+I-l;if(!(Q<0||Q>=r))for(let R=0;R<A;R++){const L=y+R-l;if(L<0||L>=e)continue;const j=t[Q*e+L],U=a[I*A+R]*c[Math.abs(j-b)];C+=j*U,x+=U}}const F=f[v]=Math.round(C/x);m[F]++}return[f,m]},Ik=function(t){const e=new Uint32Array(256);for(const r of t)e[r]++;return e},oF=function(t){const e=t.length,r=new Uint8ClampedArray(e>>2);let i=-1/0,s=1/0;for(let a=0,o=r.length;a<o;a++){const l=r[a]=t[a<<2];i=Math.max(i,l),s=Math.min(s,l)}const A=255/(i-s);for(let a=0,o=r.length;a<o;a++)r[a]=(r[a]-s)*A;return r},lF=function(t){let e,r=-1/0,i=-1/0;const s=t.findIndex(o=>o!==0);let A=s,a=s;for(e=s;e<256;e++){const o=t[e];o>r&&(e-A>i&&(i=e-A,a=e-1),r=o,A=e)}for(e=a-1;e>=0&&!(t[e]>t[e+1]);e--);return e},Uk=function(t){const e=t,{width:r,height:i}=t,{maxDim:s}=h(this,Xf);let A=r,a=i;if(r>s||i>s){let d=r,f=i,m=Math.log2(Math.max(r,i)/s);const p=Math.floor(m);m=m===p?p-1:p;for(let v=0;v<m;v++){A=Math.ceil(d/2),a=Math.ceil(f/2);const b=new OffscreenCanvas(A,a);b.getContext("2d").drawImage(t,0,0,d,f,0,0,A,a),d=A,f=a,t!==e&&t.close(),t=b.transferToImageBitmap()}const y=Math.min(s/A,s/a);A=Math.round(A*y),a=Math.round(a*y)}const l=new OffscreenCanvas(A,a).getContext("2d",{willReadFrequently:!0});l.fillStyle="white",l.fillRect(0,0,A,a),l.filter="grayscale(1)",l.drawImage(t,0,0,t.width,t.height,0,0,A,a);const c=l.getImageData(0,0,A,a).data;return[P(this,fr,oF).call(this,c),A,a]},T(No,fr),T(No,Xf,{maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16}),T(No,La,new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]));class C4 extends yk{constructor(){super(),super.updateProperties({fill:Rr._defaultLineColor,"stroke-width":0})}clone(){const t=new C4;return t.updateAll(this),t}}class x4 extends Ib{constructor(t){super(t),super.updateProperties({stroke:Rr._defaultLineColor,"stroke-width":1})}clone(){const t=new x4(this._viewParameters);return t.updateAll(this),t}}var Sh,_o,Fh,Yf;const aA=class aA extends b2{constructor(e){super({...e,mustBeCommitted:!0,name:"signatureEditor"});T(this,Sh,!1);T(this,_o,null);T(this,Fh,null);T(this,Yf,null);this._willKeepAspectRatio=!0,E(this,Fh,e.signatureData||null),E(this,_o,null),this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(e,r){Rr.initialize(e,r),this._defaultDrawingOptions=new C4,this._defaultDrawnSignatureOptions=new x4(r.viewParameters)}static getDefaultDrawingOptions(e){const r=this._defaultDrawingOptions.clone();return r.updateProperties(e),r}static get supportMultipleDrawings(){return!1}static get typesMap(){return Te(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!h(this,_o)}}static computeTelemetryFinalData(e){const r=e.get("hasDescription");return{hasAltText:r.get(!0)??0,hasNoAltText:r.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,r;const{_isCopy:i}=this;if(i&&(this._isCopy=!1,e=this.x,r=this.y),super.render(),this._drawId===null)if(h(this,Fh)){const{lines:s,mustSmooth:A,areContours:a,description:o,uuid:l,heightInPage:c}=h(this,Fh),{rawDims:{pageWidth:u,pageHeight:d},rotation:f}=this.parent.viewport,m=No.processDrawnLines({lines:s,pageWidth:u,pageHeight:d,rotation:f,innerMargin:aA._INNER_MARGIN,mustSmooth:A,areContours:a});this.addSignature(m,c,o,l)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:h(this,_o)||""}));return i&&(this._isCopy=!0,this._moveAfterPaste(e,r)),this.div}setUuid(e){E(this,Yf,e),this.addEditToolbar()}getUuid(){return h(this,Yf)}get description(){return h(this,_o)}set description(e){E(this,_o,e),this.div&&(this.div.setAttribute("data-l10n-args",JSON.stringify({description:e})),super.addEditToolbar().then(r=>{r==null||r.updateEditSignatureButton(e)}))}getSignaturePreview(){const{newCurves:e,areContours:r,thickness:i,width:s,height:A}=h(this,Fh),a=Math.max(s,A),o=No.processDrawnLines({lines:{curves:e.map(l=>({points:l})),thickness:i,width:s,height:A},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:r});return{areContours:r,outline:o.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,r,i,s){const{x:A,y:a}=this,{outline:o}=E(this,Fh,e);E(this,Sh,o instanceof sF),this.description=i;let l;h(this,Sh)?l=aA.getDefaultDrawingOptions():(l=aA._defaultDrawnSignatureOptions.clone(),l.updateProperties({"stroke-width":o.thickness})),this._addOutlines({drawOutlines:o,drawingOptions:l});const[,c]=this.pageDimensions;let u=r/c;u=u>=1?.5:u,this.width*=u/this.height,this.width>=1&&(u*=.9/this.width,this.width=.9),this.height=u,this.setDims(),this.x=A,this.y=a,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(s),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!s,hasDescription:!!i}}),this.div.hidden=!1}getFromImage(e){const{rawDims:{pageWidth:r,pageHeight:i},rotation:s}=this.parent.viewport;return No.process(e,r,i,s,aA._INNER_MARGIN)}getFromText(e,r){const{rawDims:{pageWidth:i,pageHeight:s},rotation:A}=this.parent.viewport;return No.extractContoursFromText(e,r,i,s,A,aA._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:r,pageHeight:i},rotation:s}=this.parent.viewport;return No.processDrawnLines({lines:e,pageWidth:r,pageHeight:i,rotation:s,innerMargin:aA._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:r}){e?this._drawingOptions=aA.getDefaultDrawingOptions():(this._drawingOptions=aA._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":r}))}serialize(e=!1){if(this.isEmpty())return null;const{lines:r,points:i}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":s}}=this,A=Object.assign(super.serialize(e),{isSignature:!0,areContours:h(this,Sh),color:[0,0,0],thickness:h(this,Sh)?0:s});return this.addComment(A),e?(A.paths={lines:r,points:i},A.uuid=h(this,Yf),A.isCopy=!0):A.lines=r,h(this,_o)&&(A.accessibilityData={type:"Figure",alt:h(this,_o)}),A}static deserializeDraw(e,r,i,s,A,a){return a.areContours?sF.deserialize(e,r,i,s,A,a):O1.deserialize(e,r,i,s,A,a)}static async deserialize(e,r,i){var A;const s=await super.deserialize(e,r,i);return E(s,Sh,e.areContours),s.description=((A=e.accessibilityData)==null?void 0:A.alt)||"",E(s,Yf,e.uuid),s}};Sh=new WeakMap,_o=new WeakMap,Fh=new WeakMap,Yf=new WeakMap,ht(aA,"_type","signature"),ht(aA,"_editorType",Fe.SIGNATURE),ht(aA,"_defaultDrawingOptions",null);let cF=aA;var Jr,pn,_h,ql,Th,Rp,Wl,$f,To,xA,Dp,nr,Am,am,Jy,Zy,t2,uF,e2,Lk;class hF extends Rr{constructor(e){super({...e,name:"stampEditor"});T(this,nr);T(this,Jr,null);T(this,pn,null);T(this,_h,null);T(this,ql,null);T(this,Th,null);T(this,Rp,"");T(this,Wl,null);T(this,$f,!1);T(this,To,null);T(this,xA,!1);T(this,Dp,!1);E(this,ql,e.bitmapUrl),E(this,Th,e.bitmapFile),this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(e,r){Rr.initialize(e,r)}static isHandlingMimeForPasting(e){return g2.includes(e)}static paste(e,r){r.pasteEditor({mode:Fe.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const r=e.get("hasAltText");return{hasAltText:r.get(!0)??0,hasNoAltText:r.get(!1)??0}}async mlGuessAltText(e=null,r=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:s,width:A,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await i.guess({name:"altText",request:{data:s,width:A,height:a,channels:s.length/(A*a)}});if(!o)throw new Error("No response from the AI service.");if(o.error)throw new Error("Error from the AI service.");if(o.cancel)return null;if(!o.output)throw new Error("No valid response from the AI service.");const l=o.output;return await this.setGuessedAltText(l),r&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var e;h(this,pn)&&(E(this,Jr,null),this._uiManager.imageManager.deleteId(h(this,pn)),(e=h(this,Wl))==null||e.remove(),E(this,Wl,null),h(this,To)&&(clearTimeout(h(this,To)),E(this,To,null))),super.remove()}rebuild(){if(!this.parent){h(this,pn)&&P(this,nr,Jy).call(this);return}super.rebuild(),this.div!==null&&(h(this,pn)&&h(this,Wl)===null&&P(this,nr,Jy).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(h(this,_h)||h(this,Jr)||h(this,ql)||h(this,Th)||h(this,pn)||h(this,$f))}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,r;return this._isCopy&&(e=this.x,r=this.y),super.render(),this.div.hidden=!0,this.createAltText(),h(this,$f)||(h(this,Jr)?P(this,nr,Zy).call(this):P(this,nr,Jy).call(this)),this._isCopy&&this._moveAfterPaste(e,r),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,r){const{id:i,bitmap:s}=this._uiManager.imageManager.getFromCanvas(e,r);r.remove(),i&&this._uiManager.imageManager.isValidId(i)&&(E(this,pn,i),s&&E(this,Jr,s),E(this,$f,!1),P(this,nr,Zy).call(this))}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;h(this,To)!==null&&clearTimeout(h(this,To)),E(this,To,setTimeout(()=>{E(this,To,null),P(this,nr,uF).call(this)},200))}copyCanvas(e,r,i=!1){e||(e=224);const{width:s,height:A}=h(this,Jr),a=new Da;let o=h(this,Jr),l=s,c=A,u=null;if(r){if(s>r||A>r){const Q=Math.min(r/s,r/A);l=Math.floor(s*Q),c=Math.floor(A*Q)}u=document.createElement("canvas");const f=u.width=Math.ceil(l*a.sx),m=u.height=Math.ceil(c*a.sy);h(this,xA)||(o=P(this,nr,t2).call(this,f,m));const p=u.getContext("2d");p.filter=this._uiManager.hcmFilter;let y="white",v="#cfcfd8";this._uiManager.hcmFilter!=="none"?v="black":OK.isDarkMode&&(y="#8f8f9d",v="#42414d");const b=15,C=b*a.sx,x=b*a.sy,F=new OffscreenCanvas(C*2,x*2),I=F.getContext("2d");I.fillStyle=y,I.fillRect(0,0,C*2,x*2),I.fillStyle=v,I.fillRect(0,0,C,x),I.fillRect(C,x,C,x),p.fillStyle=p.createPattern(F,"repeat"),p.fillRect(0,0,f,m),p.drawImage(o,0,0,o.width,o.height,0,0,f,m)}let d=null;if(i){let f,m;if(a.symmetric&&o.width<e&&o.height<e)f=o.width,m=o.height;else if(o=h(this,Jr),s>e||A>e){const v=Math.min(e/s,e/A);f=Math.floor(s*v),m=Math.floor(A*v),h(this,xA)||(o=P(this,nr,t2).call(this,f,m))}const y=new OffscreenCanvas(f,m).getContext("2d",{willReadFrequently:!0});y.drawImage(o,0,0,o.width,o.height,0,0,f,m),d={width:f,height:m,data:y.getImageData(0,0,f,m).data}}return{canvas:u,width:l,height:c,imageData:d}}static async deserialize(e,r,i){var y;let s=null,A=!1;if(e instanceof zO){const{data:{rect:v,rotation:b,id:C,structParent:x,popupRef:F,richText:I,contentsObj:Q,creationDate:R,modificationDate:L},container:j,parent:{page:{pageNumber:U}},canvas:k}=e;let G,D;k?(delete e.canvas,{id:G,bitmap:D}=i.imageManager.getFromCanvas(j.id,k),k.remove()):(A=!0,e._hasNoCanvas=!0);const rt=((y=await r._structTree.getAriaAttributes(`${cg}${C}`))==null?void 0:y.get("aria-label"))||"";s=e={annotationType:Fe.STAMP,bitmapId:G,bitmap:D,pageIndex:U-1,rect:v.slice(0),rotation:b,annotationElementId:C,id:C,deleted:!1,accessibilityData:{decorative:!1,altText:rt},isSvg:!1,structParent:x,popupRef:F,richText:I,comment:(Q==null?void 0:Q.str)||null,creationDate:R,modificationDate:L}}const a=await super.deserialize(e,r,i),{rect:o,bitmap:l,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;A?(i.addMissingCanvas(e.id,a),E(a,$f,!0)):u&&i.imageManager.isValidId(u)?(E(a,pn,u),l&&E(a,Jr,l)):E(a,ql,c),E(a,xA,d);const[m,p]=a.pageDimensions;return a.width=(o[2]-o[0])/m,a.height=(o[3]-o[1])/p,f&&(a.altTextData=f),a._initialData=s,e.comment&&a.setCommentData(e),E(a,Dp,!!s),a}serialize(e=!1,r=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i=Object.assign(super.serialize(e),{bitmapId:h(this,pn),isSvg:h(this,xA)});if(this.addComment(i),e)return i.bitmapUrl=P(this,nr,e2).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i.isCopy=!0,i;const{decorative:s,altText:A}=this.serializeAltText(!1);if(!s&&A&&(i.accessibilityData={type:"Figure",alt:A}),this.annotationElementId){const o=P(this,nr,Lk).call(this,i);return o.isSame?null:(o.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1,i.id=this.annotationElementId,delete i.bitmapId,i)}if(r===null)return i;r.stamps||(r.stamps=new Map);const a=h(this,xA)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!r.stamps.has(h(this,pn)))r.stamps.set(h(this,pn),{area:a,serialized:i}),i.bitmap=P(this,nr,e2).call(this,!1);else if(h(this,xA)){const o=r.stamps.get(h(this,pn));a>o.area&&(o.area=a,o.serialized.bitmap.close(),o.serialized.bitmap=P(this,nr,e2).call(this,!1))}return i}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}Jr=new WeakMap,pn=new WeakMap,_h=new WeakMap,ql=new WeakMap,Th=new WeakMap,Rp=new WeakMap,Wl=new WeakMap,$f=new WeakMap,To=new WeakMap,xA=new WeakMap,Dp=new WeakMap,nr=new WeakSet,Am=function(e,r=!1){if(!e){this.remove();return}E(this,Jr,e.bitmap),r||(E(this,pn,e.id),E(this,xA,e.isSvg)),e.file&&E(this,Rp,e.file.name),P(this,nr,Zy).call(this)},am=function(){if(E(this,_h,null),this._uiManager.enableWaiting(!1),!!h(this,Wl)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&h(this,Jr)){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&h(this,Jr)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Jy=function(){if(h(this,pn)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(h(this,pn)).then(i=>P(this,nr,Am).call(this,i,!0)).finally(()=>P(this,nr,am).call(this));return}if(h(this,ql)){const i=h(this,ql);E(this,ql,null),this._uiManager.enableWaiting(!0),E(this,_h,this._uiManager.imageManager.getFromUrl(i).then(s=>P(this,nr,Am).call(this,s)).finally(()=>P(this,nr,am).call(this)));return}if(h(this,Th)){const i=h(this,Th);E(this,Th,null),this._uiManager.enableWaiting(!0),E(this,_h,this._uiManager.imageManager.getFromFile(i).then(s=>P(this,nr,Am).call(this,s)).finally(()=>P(this,nr,am).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=g2.join(",");const r=this._uiManager._signal;E(this,_h,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const s=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),P(this,nr,Am).call(this,s)}i()},{signal:r}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:r})}).finally(()=>P(this,nr,am).call(this))),e.click()},Zy=function(){var l;const{div:e}=this;let{width:r,height:i}=h(this,Jr);const[s,A]=this.pageDimensions,a=.75;if(this.width)r=this.width*s,i=this.height*A;else if(r>a*s||i>a*A){const c=Math.min(a*s/r,a*A/i);r*=c,i*=c}this._uiManager.enableWaiting(!1);const o=E(this,Wl,document.createElement("canvas"));o.setAttribute("role","img"),this.addContainer(o),this.width=r/s,this.height=i/A,this.setDims(),(l=this._initialOptions)!=null&&l.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),P(this,nr,uF).call(this),h(this,Dp)||(this.parent.addUndoableEditor(this),E(this,Dp,!0)),this._reportTelemetry({action:"inserted_image"}),h(this,Rp)&&this.div.setAttribute("aria-description",h(this,Rp)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")},t2=function(e,r){const{width:i,height:s}=h(this,Jr);let A=i,a=s,o=h(this,Jr);for(;A>2*e||a>2*r;){const l=A,c=a;A>2*e&&(A=Math.ceil(A/2)),a>2*r&&(a=Math.ceil(a/2));const u=new OffscreenCanvas(A,a);u.getContext("2d").drawImage(o,0,0,l,c,0,0,A,a),o=u.transferToImageBitmap()}return o},uF=function(){const[e,r]=this.parentDimensions,{width:i,height:s}=this,A=new Da,a=Math.ceil(i*e*A.sx),o=Math.ceil(s*r*A.sy),l=h(this,Wl);if(!l||l.width===a&&l.height===o)return;l.width=a,l.height=o;const c=h(this,xA)?h(this,Jr):P(this,nr,t2).call(this,a,o),u=l.getContext("2d");u.filter=this._uiManager.hcmFilter,u.drawImage(c,0,0,c.width,c.height,0,0,a,o)},e2=function(e){if(e){if(h(this,xA)){const s=this._uiManager.imageManager.getSvgUrl(h(this,pn));if(s)return s}const r=document.createElement("canvas");return{width:r.width,height:r.height}=h(this,Jr),r.getContext("2d").drawImage(h(this,Jr),0,0),r.toDataURL()}if(h(this,xA)){const[r,i]=this.pageDimensions,s=Math.round(this.width*r*Ac.PDF_TO_CSS_UNITS),A=Math.round(this.height*i*Ac.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(s,A);return a.getContext("2d").drawImage(h(this,Jr),0,0,h(this,Jr).width,h(this,Jr).height,0,0,s,A),a.transferToImageBitmap()}return structuredClone(h(this,Jr))},Lk=function(e){var a;const{pageIndex:r,accessibilityData:{altText:i}}=this._initialData,s=e.pageIndex===r,A=(((a=e.accessibilityData)==null?void 0:a.alt)||"")===i;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&s&&A,isSameAltText:A}},ht(hF,"_type","stamp"),ht(hF,"_editorType",Fe.STAMP);var Jf,Hp,Ih,Uh,zl,Gs,Lh,Kp,Gp,Pa,Xl,mn,Yl,Ph,jp,le,Nh,Ur,fF,Pk,ao,dF,gF,r2;const ya=class ya{constructor({uiManager:t,pageIndex:e,div:r,structTreeLayer:i,accessibilityManager:s,annotationLayer:A,drawLayer:a,textLayer:o,viewport:l,l10n:c}){T(this,Ur);T(this,Jf);T(this,Hp,!1);T(this,Ih,null);T(this,Uh,null);T(this,zl,null);T(this,Gs,new Map);T(this,Lh,!1);T(this,Kp,!1);T(this,Gp,!1);T(this,Pa,null);T(this,Xl,null);T(this,mn,null);T(this,Yl,null);T(this,Ph,null);T(this,jp,-1);T(this,le);const u=[...h(ya,Nh).values()];if(!ya._initialized){ya._initialized=!0;for(const d of u)d.initialize(c,t)}t.registerEditorTypes(u),E(this,le,t),this.pageIndex=e,this.div=r,E(this,Jf,s),E(this,Ih,A),this.viewport=l,E(this,mn,o),this.drawLayer=a,this._structTree=i,h(this,le).addLayer(this)}get isEmpty(){return h(this,Gs).size===0}get isInvisible(){return this.isEmpty&&h(this,le).getMode()===Fe.NONE}updateToolbar(t){h(this,le).updateToolbar(t)}updateMode(t=h(this,le).getMode()){switch(P(this,Ur,r2).call(this),t){case Fe.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Fe.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Fe.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;if(e.toggle("nonEditing",!1),t===Fe.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(const r of h(ya,Nh).values())e.toggle(`${r._type}Editing`,t===r._editorType)}this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=h(this,mn))==null?void 0:e.div)}setEditingState(t){h(this,le).setEditingState(t)}addCommands(t){h(this,le).addCommands(t)}cleanUndoStack(t){h(this,le).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=h(this,Ih))==null||e.togglePointerEvents(t)}async enable(){var r;E(this,Gp,!0),this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),(r=h(this,Ph))==null||r.abort(),E(this,Ph,null);const t=new Set;for(const i of h(this,Ur,fF))i.enableEditing(),i.show(!0),i.annotationElementId&&(h(this,le).removeChangedExistingAnnotation(i),t.add(i.annotationElementId));const e=h(this,Ih);if(e)for(const i of e.getEditableAnnotations()){if(i.hide(),h(this,le).isDeletedAnnotationElement(i.data.id)||t.has(i.data.id))continue;const s=await this.deserialize(i);s&&(this.addOrRebuild(s),s.enableEditing())}E(this,Gp,!1),h(this,le)._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){var i;if(E(this,Kp,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),h(this,mn)&&!h(this,Ph)){E(this,Ph,new AbortController);const s=h(this,le).combinedSignal(h(this,Ph));h(this,mn).div.addEventListener("pointerdown",A=>{const{clientX:o,clientY:l,timeStamp:c}=A,u=h(this,jp);if(c-u>500){E(this,jp,c);return}E(this,jp,-1);const{classList:d}=this.div;d.toggle("getElements",!0);const f=document.elementsFromPoint(o,l);if(d.toggle("getElements",!1),!this.div.contains(f[0]))return;let m;const p=new RegExp(`^${Um}[0-9]+$`);for(const v of f)if(p.test(v.id)){m=v.id;break}if(!m)return;const y=h(this,Gs).get(m);(y==null?void 0:y.annotationElementId)===null&&(Zr(A),y.dblclick(A))},{signal:s,capture:!0})}const t=h(this,Ih),e=[];if(t){const s=new Map,A=new Map;for(const a of h(this,Ur,fF)){if(a.disableEditing(),!a.annotationElementId){e.push(a);continue}if(a.serialize()!==null){s.set(a.annotationElementId,a);continue}else A.set(a.annotationElementId,a);(i=this.getEditableAnnotation(a.annotationElementId))==null||i.show(),a.remove()}for(const a of t.getEditableAnnotations()){const{id:o}=a.data;if(h(this,le).isDeletedAnnotationElement(o)){a.updateEdited({deleted:!0});continue}let l=A.get(o);if(l){l.resetAnnotationElement(a),l.show(!1),a.show();continue}l=s.get(o),l&&(h(this,le).addChangedExistingAnnotation(l),l.renderAnnotationElement(a)&&l.show(!1)),a.show()}}P(this,Ur,r2).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:r}=this.div;for(const s of h(ya,Nh).values())r.remove(`${s._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),t==null||t.updateFakeAnnotations(e),E(this,Kp,!1)}getEditableAnnotation(t){var e;return((e=h(this,Ih))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){h(this,le).getActive()!==t&&h(this,le).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=h(this,mn))!=null&&t.div&&!h(this,Yl)){E(this,Yl,new AbortController);const e=h(this,le).combinedSignal(h(this,Yl));h(this,mn).div.addEventListener("pointerdown",P(this,Ur,Pk).bind(this),{signal:e}),h(this,mn).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=h(this,mn))!=null&&t.div&&h(this,Yl)&&(h(this,Yl).abort(),E(this,Yl,null),h(this,mn).div.classList.remove("highlighting"))}enableClick(){if(h(this,Uh))return;E(this,Uh,new AbortController);const t=h(this,le).combinedSignal(h(this,Uh));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=h(this,Uh))==null||t.abort(),E(this,Uh,null)}attach(t){h(this,Gs).set(t.id,t);const{annotationElementId:e}=t;e&&h(this,le).isDeletedAnnotationElement(e)&&h(this,le).removeDeletedAnnotationElement(t)}detach(t){var e;h(this,Gs).delete(t.id),(e=h(this,Jf))==null||e.removePointerInTextLayer(t.contentDiv),!h(this,Kp)&&t.annotationElementId&&h(this,le).addDeletedAnnotationElement(t)}remove(t){this.detach(t),h(this,le).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(h(this,le).addDeletedAnnotationElement(t),Rr.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),h(this,le).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!h(this,Gp)),h(this,le).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var r;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!h(this,zl)&&(t._focusEventsAllowed=!1,E(this,zl,setTimeout(()=>{E(this,zl,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:h(this,le)._signal}),e.focus())},0))),t._structTreeParentId=(r=h(this,Jf))==null?void 0:r.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),r=()=>{t.remove()};this.addCommands({cmd:e,undo:r,mustExec:!1})}getEditorByUID(t){for(const e of h(this,Gs).values())if(e.uid===t)return e;return null}combinedSignal(t){return h(this,le).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=h(this,Ur,ao))==null?void 0:t.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await h(this,le).updateMode(t.mode);const{offsetX:r,offsetY:i}=P(this,Ur,gF).call(this),s=h(this,le).getId(),A=P(this,Ur,dF).call(this,{parent:this,id:s,x:r,y:i,uiManager:h(this,le),isCentered:!0,...e});A&&this.add(A)}async deserialize(t){var e;return await((e=h(ya,Nh).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,h(this,le)))||null}createAndAddNewEditor(t,e,r={}){const i=h(this,le).getId(),s=P(this,Ur,dF).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:h(this,le),isCentered:e,...r});return s&&this.add(s),s}get boundingClientRect(){return this.div.getBoundingClientRect()}addNewEditor(t={}){this.createAndAddNewEditor(P(this,Ur,gF).call(this),!0,t)}setSelected(t){h(this,le).setSelected(t)}toggleSelected(t){h(this,le).toggleSelected(t)}unselect(t){h(this,le).unselect(t)}pointerup(t){var i;const{isMac:e}=Qi.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div||!h(this,Lh)||(E(this,Lh,!1),(i=h(this,Ur,ao))!=null&&i.isDrawer&&h(this,Ur,ao).supportMultipleDrawings))return;if(!h(this,Hp)){E(this,Hp,!0);return}const r=h(this,le).getMode();if(r===Fe.STAMP||r===Fe.POPUP||r===Fe.SIGNATURE){h(this,le).unselectAll();return}this.createAndAddNewEditor(t,!1)}pointerdown(t){var i;if(h(this,le).getMode()===Fe.HIGHLIGHT&&this.enableTextSelection(),h(this,Lh)){E(this,Lh,!1);return}const{isMac:e}=Qi.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(E(this,Lh,!0),(i=h(this,Ur,ao))!=null&&i.isDrawer){this.startDrawingSession(t);return}const r=h(this,le).getActive();E(this,Hp,!r||r.isEmpty())}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),h(this,Pa)){h(this,Ur,ao).startDrawing(this,h(this,le),!1,t);return}h(this,le).setCurrentDrawingSession(this),E(this,Pa,new AbortController);const e=h(this,le).combinedSignal(h(this,Pa));this.div.addEventListener("blur",({relatedTarget:r})=>{r&&!this.div.contains(r)&&(E(this,Xl,null),this.commitOrRemove())},{signal:e}),h(this,Ur,ao).startDrawing(this,h(this,le),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&E(this,Xl,e);return}h(this,Xl)&&setTimeout(()=>{var e;(e=h(this,Xl))==null||e.focus(),E(this,Xl,null)},0)}endDrawingSession(t=!1){return h(this,Pa)?(h(this,le).setCurrentDrawingSession(null),h(this,Pa).abort(),E(this,Pa,null),E(this,Xl,null),h(this,Ur,ao).endDrawing(t)):null}findNewParent(t,e,r){const i=h(this,le).findParent(e,r);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return h(this,Pa)?(this.endDrawingSession(),!0):!1}onScaleChanging(){h(this,Pa)&&h(this,Ur,ao).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=h(this,le).getActive())==null?void 0:t.parent)===this&&(h(this,le).commitOrRemove(),h(this,le).setActiveEditor(null)),h(this,zl)&&(clearTimeout(h(this,zl)),E(this,zl,null));for(const r of h(this,Gs).values())(e=h(this,Jf))==null||e.removePointerInTextLayer(r.contentDiv),r.setParent(null),r.isAttachedToDOM=!1,r.div.remove();this.div=null,h(this,Gs).clear(),h(this,le).removeLayer(this)}async render({viewport:t}){this.viewport=t,Gh(this.div,t);for(const e of h(this,le).getEditors(this.pageIndex))this.add(e),e.rebuild();await h(this,le).findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:t}){h(this,le).commitOrRemove(),P(this,Ur,r2).call(this);const e=this.viewport.rotation,r=t.rotation;if(this.viewport=t,Gh(this.div,{rotation:r}),e!==r)for(const i of h(this,Gs).values())i.rotate(r)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return h(this,le).viewParameters.realScale}};Jf=new WeakMap,Hp=new WeakMap,Ih=new WeakMap,Uh=new WeakMap,zl=new WeakMap,Gs=new WeakMap,Lh=new WeakMap,Kp=new WeakMap,Gp=new WeakMap,Pa=new WeakMap,Xl=new WeakMap,mn=new WeakMap,Yl=new WeakMap,Ph=new WeakMap,jp=new WeakMap,le=new WeakMap,Nh=new WeakMap,Ur=new WeakSet,fF=function(){return h(this,Gs).size!==0?h(this,Gs).values():h(this,le).getEditors(this.pageIndex)},Pk=function(t){h(this,le).unselectAll();const{target:e}=t;if(e===h(this,mn).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent")||e.classList.contains("textLayerImagePlaceholder"))&&h(this,mn).div.contains(e)){const{isMac:r}=Qi.platform;if(t.button!==0||t.ctrlKey&&r)return;h(this,le).showAllEditors("highlight",!0,!0),h(this,mn).div.classList.add("free"),this.toggleDrawing(),y2.startHighlighting(this,h(this,le).direction==="ltr",{target:h(this,mn).div,x:t.x,y:t.y}),h(this,mn).div.addEventListener("pointerup",()=>{h(this,mn).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:h(this,le)._signal}),t.preventDefault()}},ao=function(){return h(ya,Nh).get(h(this,le).getMode())},dF=function(t){const e=h(this,Ur,ao);return e?new e.prototype.constructor(t):null},gF=function(){const{x:t,y:e,width:r,height:i}=this.boundingClientRect,s=Math.max(0,t),A=Math.max(0,e),a=Math.min(window.innerWidth,t+r),o=Math.min(window.innerHeight,e+i),l=(s+a)/2-t,c=(A+o)/2-e,[u,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:u,offsetY:d}},r2=function(){for(const t of h(this,Gs).values())t.isEmpty()&&t.remove()},ht(ya,"_initialized",!1),T(ya,Nh,new Map([zS,nF,hF,y2,cF].map(t=>[t._editorType,t])));let B2=ya;var Na,xs,Zf,C1,Ab,Nk,Oo,pF,Qk,mF;const en=class en{constructor(){T(this,Oo);T(this,Na,null);T(this,xs,new Map);T(this,Zf,new Map)}setParent(t){if(!h(this,Na)){E(this,Na,t);return}if(h(this,Na)!==t){if(h(this,xs).size>0)for(const e of h(this,xs).values())e.remove(),t.append(e);E(this,Na,t)}}static get _svgFactory(){return Te(this,"_svgFactory",new Rm)}draw(t,e=!1,r=!1){const i=Di(en,C1)._++,s=P(this,Oo,pF).call(this),A=en._svgFactory.createElement("defs");s.append(A);const a=en._svgFactory.createElement("path");A.append(a);const o=`path_${i}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&h(this,Zf).set(i,a);const l=r?P(this,Oo,Qk).call(this,A,o):null,c=en._svgFactory.createElement("use");return s.append(c),c.setAttribute("href",`#${o}`),this.updateProperties(s,t),h(this,xs).set(i,s),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){const r=Di(en,C1)._++,i=P(this,Oo,pF).call(this),s=en._svgFactory.createElement("defs");i.append(s);const A=en._svgFactory.createElement("path");s.append(A);const a=`path_${r}`;A.setAttribute("id",a),A.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){const u=en._svgFactory.createElement("mask");s.append(u),o=`mask_${r}`,u.setAttribute("id",o),u.setAttribute("maskUnits","objectBoundingBox");const d=en._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const f=en._svgFactory.createElement("use");u.append(f),f.setAttribute("href",`#${a}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const l=en._svgFactory.createElement("use");i.append(l),l.setAttribute("href",`#${a}`),o&&l.setAttribute("mask",`url(#${o})`);const c=l.cloneNode();return i.append(c),l.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),h(this,xs).set(r,i),r}finalizeDraw(t,e){h(this,Zf).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var o;if(!e)return;const{root:r,bbox:i,rootClass:s,path:A}=e,a=typeof t=="number"?h(this,xs).get(t):t;if(a){if(r&&P(this,Oo,mF).call(this,a,r),i&&P(o=en,Ab,Nk).call(o,a,i),s){const{classList:l}=a;for(const[c,u]of Object.entries(s))l.toggle(c,u)}if(A){const c=a.firstElementChild.firstElementChild;P(this,Oo,mF).call(this,c,A)}}}updateParent(t,e){if(e===this)return;const r=h(this,xs).get(t);r&&(h(e,Na).append(r),h(this,xs).delete(t),h(e,xs).set(t,r))}remove(t){h(this,Zf).delete(t),h(this,Na)!==null&&(h(this,xs).get(t).remove(),h(this,xs).delete(t))}destroy(){E(this,Na,null);for(const t of h(this,xs).values())t.remove();h(this,xs).clear(),h(this,Zf).clear()}};Na=new WeakMap,xs=new WeakMap,Zf=new WeakMap,C1=new WeakMap,Ab=new WeakSet,Nk=function(t,[e,r,i,s]){const{style:A}=t;A.top=`${100*r}%`,A.left=`${100*e}%`,A.width=`${100*i}%`,A.height=`${100*s}%`},Oo=new WeakSet,pF=function(){const t=en._svgFactory.create(1,1,!0);return h(this,Na).append(t),t.setAttribute("aria-hidden",!0),t},Qk=function(t,e){const r=en._svgFactory.createElement("clipPath");t.append(r);const i=`clip_${e}`;r.setAttribute("id",i),r.setAttribute("clipPathUnits","objectBoundingBox");const s=en._svgFactory.createElement("use");return r.append(s),s.setAttribute("href",`#${e}`),s.classList.add("clip"),i},mF=function(t,e){for(const[r,i]of Object.entries(e))i===null?t.removeAttribute(r):t.setAttribute(r,i)},T(en,Ab),T(en,C1,0);let C2=en;function Dw(n){return`${(n*100).toFixed(2)}%`}var Vp,x1,E1,qp,Io,Uo,S1,ab,Mk;const Fm=class Fm{constructor(t,e,r,i){T(this,ab);T(this,Vp,[]);T(this,x1,new Map);T(this,E1,null);T(this,qp,0);T(this,Io,0);T(this,Uo,0);E(this,qp,t),E(this,Vp,e),E(this,Io,r.rawDims.pageWidth),E(this,Uo,r.rawDims.pageHeight),E(this,E1,i)}render(){const t=document.createElement("div");t.className="textLayerImages";for(let e=0;e<h(this,Vp).length;e+=6){const r=P(this,ab,Mk).call(this,h(this,Vp).subarray(e,e+6));r&&t.append(r)}return t.addEventListener("contextmenu",e=>{var v;if(!(e.target instanceof HTMLCanvasElement))return;const r=e.target,i=h(this,x1).get(r);if(!i)return;const s=(v=h(Fm,S1))==null?void 0:v.deref();if(s===r)return;s&&(s.width=0,s.height=0),E(Fm,S1,new WeakRef(r));const{inverseTransform:A,x1:a,y1:o,width:l,height:c}=i,u=h(this,E1).call(this),d=Math.ceil(a*u.width),f=Math.ceil(o*u.height),m=Math.floor((a+l/h(this,Io))*u.width),p=Math.floor((o+c/h(this,Uo))*u.height);r.width=m-d,r.height=p-f;const y=r.getContext("2d");y.setTransform(...A),y.translate(-d,-f),y.drawImage(u,0,0)}),t}};Vp=new WeakMap,x1=new WeakMap,E1=new WeakMap,qp=new WeakMap,Io=new WeakMap,Uo=new WeakMap,S1=new WeakMap,ab=new WeakSet,Mk=function([t,e,r,i,s,A]){const a=Math.hypot((s-t)*h(this,Io),(A-e)*h(this,Uo)),o=Math.hypot((r-t)*h(this,Io),(i-e)*h(this,Uo));if(a<h(this,qp)||o<h(this,qp))return null;const l=[(s-t)*h(this,Io)/a,(A-e)*h(this,Uo)/a,(r-t)*h(this,Io)/o,(i-e)*h(this,Uo)/o,0,0],c=Mt.inverseTransform(l),u=document.createElement("canvas");return u.className="textLayerImagePlaceholder",u.width=0,u.height=0,Object.assign(u.style,{opacity:0,position:"absolute",left:Dw(t),top:Dw(e),width:Dw(a/h(this,Io)),height:Dw(o/h(this,Uo)),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`}),h(this,x1).set(u,{inverseTransform:c,width:a,height:o,x1:t,y1:e}),u},T(Fm,S1,null);let x2=Fm;globalThis._pdfjsTestingUtils={HighlightOutliner:YS};globalThis.pdfjsLib={AbortException:sc,AnnotationEditorLayer:B2,AnnotationEditorParamsType:Qe,AnnotationEditorType:Fe,AnnotationEditorUIManager:jh,AnnotationLayer:v2,AnnotationMode:$l,AnnotationType:Si,applyOpacity:vM,build:MO,ColorPicker:km,createValidAbsoluteUrl:u4,CSSConstants:mM,DOMSVGFactory:Rm,DrawLayer:C2,FeatureTest:Qi,fetchData:vb,findContrastColor:wM,getDocument:w4,getFilenameFromUrl:dM,getPdfFilenameFromUrl:gM,getRGB:t0,getRGBA:bb,getUuid:d4,getXfaPageViewport:pM,GlobalWorkerOptions:Ma,ImageKind:vm,InvalidPDFException:f2,isDataScheme:Q1,isPdfFile:yb,isValidExplicitDest:iO,makeArr:pb,makeMap:mb,makeObj:d2,MathClamp:Wr,noContextMenu:UA,normalizeUnicode:fM,OPS:Po,OutputScale:Da,PasswordResponses:uM,PDFDataRangeTransport:y4,PDFDateString:Nm,PDFWorker:Yp,PermissionFlag:hM,PixelsPerInch:Ac,RenderingCancelledException:wb,renderRichText:p4,ResponseException:Lm,setLayerDimensions:Gh,shadow:Te,SignatureExtractor:No,stopEvent:Zr,SupportedImageMimeTypes:g2,TextLayer:Xp,TextLayerImages:x2,TouchManager:Qm,updateUrlHash:f4,Util:Mt,VerbosityLevel:P1,version:QO,XfaLayer:g4};const vj=Object.freeze(Object.defineProperty({__proto__:null,AbortException:sc,AnnotationEditorLayer:B2,AnnotationEditorParamsType:Qe,AnnotationEditorType:Fe,AnnotationEditorUIManager:jh,AnnotationLayer:v2,AnnotationMode:$l,AnnotationType:Si,CSSConstants:mM,ColorPicker:km,DOMSVGFactory:Rm,DrawLayer:C2,FeatureTest:Qi,GlobalWorkerOptions:Ma,ImageKind:vm,InvalidPDFException:f2,MathClamp:Wr,OPS:Po,OutputScale:Da,PDFDataRangeTransport:y4,PDFDateString:Nm,PDFWorker:Yp,PasswordResponses:uM,PermissionFlag:hM,PixelsPerInch:Ac,RenderingCancelledException:wb,ResponseException:Lm,SignatureExtractor:No,SupportedImageMimeTypes:g2,TextLayer:Xp,TextLayerImages:x2,TouchManager:Qm,Util:Mt,VerbosityLevel:P1,XfaLayer:g4,applyOpacity:vM,build:MO,createValidAbsoluteUrl:u4,fetchData:vb,findContrastColor:wM,getDocument:w4,getFilenameFromUrl:dM,getPdfFilenameFromUrl:gM,getRGB:t0,getRGBA:bb,getUuid:d4,getXfaPageViewport:pM,isDataScheme:Q1,isPdfFile:yb,isValidExplicitDest:iO,makeArr:pb,makeMap:mb,makeObj:d2,noContextMenu:UA,normalizeUnicode:fM,renderRichText:p4,setLayerDimensions:Gh,shadow:Te,stopEvent:Zr,updateUrlHash:f4,version:QO},Symbol.toStringTag,{value:"Module"}));Ma.workerSrc="";const rU=25.4/72,EC=8;class Ok{importFromFilePicker(t){const e=document.createElement("input");e.type="file",e.accept=".pdf",e.style.display="none",document.body.appendChild(e),e.addEventListener("change",async()=>{var s;const r=(s=e.files)==null?void 0:s[0];if(document.body.removeChild(e),!r)return;const i=await r.arrayBuffer();await this.convert(t,i)}),e.click()}async convert(t,e,r=1){try{const s=await(await w4({data:e}).promise).getPage(r),a=s.getViewport({scale:1}).height,o=await s.getOperatorList(),l=this.extractEntities(o,a);if(l.length===0){Ic.log.warn("[PdfImport] No vector paths found in PDF page.");return}const c=t.doc.database.tables.blockTable.modelSpace;for(const u of l)c.appendEntity(u);Ic.log.info(`[PdfImport] Imported ${l.length} entities from PDF.`)}catch(i){Ic.log.error("[PdfImport] Failed to import PDF:",i)}}extractEntities(t,e){const{OPS:r}=vj,{fnArray:i,argsArray:s}=t,A=[];let a=[],o=[],l=0,c=0;const u=()=>{o.length>1&&a.push(o),o=[]},d=()=>{u();for(const p of a){const y=this.subpathToEntity(p);y&&A.push(y)}a=[]},f=(p,y)=>p*rU,m=(p,y)=>(e-y)*rU;for(let p=0;p<i.length;p++){const y=i[p],v=s[p];switch(y){case r.moveTo:{u(),l=v[0],c=v[1],o=[{x:f(l),y:m(l,c)}];break}case r.lineTo:{l=v[0],c=v[1],o.push({x:f(l),y:m(l,c)});break}case r.curveTo:{const[b,C,x,F,I,Q]=v,R=SC({x:l,y:c},{x:b,y:C},{x,y:F},{x:I,y:Q},EC);for(const L of R)o.push({x:f(L.x,L.y),y:m(L.x,L.y)});l=I,c=Q;break}case r.curveTo2:{const[b,C,x,F]=v,I=SC({x:l,y:c},{x:l,y:c},{x:b,y:C},{x,y:F},EC);for(const Q of I)o.push({x:f(Q.x,Q.y),y:m(Q.x,Q.y)});l=x,c=F;break}case r.curveTo3:{const[b,C,x,F]=v,I=SC({x:l,y:c},{x:b,y:C},{x,y:F},{x,y:F},EC);for(const Q of I)o.push({x:f(Q.x,Q.y),y:m(Q.x,Q.y)});l=x,c=F;break}case r.closePath:{o.length>0&&a.length===0&&o.push({...o[0]}),u();break}case r.stroke:case r.fill:case r.eoFill:case r.fillStroke:case r.eoFillStroke:case r.endPath:{d();break}}}return d(),A}subpathToEntity(t){if(t.length<2)return null;if(t.length===2)return new Ic.AcDbLine(new Ic.AcGePoint3d(t[0].x,t[0].y,0),new Ic.AcGePoint3d(t[1].x,t[1].y,0));const e=new Ic.AcDbPolyline;for(let a=0;a<t.length;a++)e.addVertexAt(a,new Ic.AcGePoint2d(t[a].x,t[a].y));const r=t[0],i=t[t.length-1],s=r.x-i.x,A=r.y-i.y;return Math.sqrt(s*s+A*A)<1e-6&&(e.closed=!0),e}}function SC(n,t,e,r,i){const s=[];for(let A=1;A<=i;A++){const a=A/i,o=1-a,l=o*o*o*n.x+3*o*o*a*t.x+3*o*a*a*e.x+a*a*a*r.x,c=o*o*o*n.y+3*o*o*a*t.y+3*o*a*a*e.y+a*a*a*r.y;s.push({x:l,y:c})}return s}class kk extends _m.AcEdCommand{async execute(t){new Ok().importFromFilePicker(t)}}const wj="1.5.8",yj={version:wj};class bj{constructor(){this.name="PdfPlugin",this.version=yj.version,this.description="PDF export (cpdf) and import (ipdf) commands",this.registeredCommands=[]}onLoad(t,e){const r=_m.AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME;e.addCommand(r,"cpdf","cpdf",new cM),e.addCommand(r,"ipdf","ipdf",new kk),this.registeredCommands.push({group:r,name:"cpdf"},{group:r,name:"ipdf"})}onUnload(t,e){for(const r of this.registeredCommands)e.removeCmd(r.group,r.name);this.registeredCommands=[]}}async function Bj(){return new bj}/*!
|
|
272
|
+
`)){const r=document.createElement("div");r.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(r)}},JO=function(){return h(this,mA).replaceAll(" "," ")},XS=function(e){return e.replaceAll(" "," ")},ZO=function(e){const{value:r,fontSize:i,color:s,pageIndex:A}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==r||e.fontSize!==i||e.color.some((a,o)=>a!==s[o])||e.pageIndex!==A},T(jr,nc),ht(jr,"_freeTextDefaultContent",""),ht(jr,"_internalPadding",0),ht(jr,"_defaultColor",null),ht(jr,"_defaultFontSize",10),ht(jr,"_type","freetext"),ht(jr,"_editorType",Fe.FREETEXT);let zS=jr;class re{toSVGPath(){ur("Abstract method `toSVGPath` must be implemented.")}get box(){ur("Abstract getter `box` must be implemented.")}serialize(t,e){ur("Abstract method `serialize` must be implemented.")}static _rescale(t,e,r,i,s,A){A||(A=new Float32Array(t.length));for(let a=0,o=t.length;a<o;a+=2)A[a]=e+t[a]*i,A[a+1]=r+t[a+1]*s;return A}static _rescaleAndSwap(t,e,r,i,s,A){A||(A=new Float32Array(t.length));for(let a=0,o=t.length;a<o;a+=2)A[a]=e+t[a+1]*i,A[a+1]=r+t[a]*s;return A}static _translate(t,e,r,i){i||(i=new Float32Array(t.length));for(let s=0,A=t.length;s<A;s+=2)i[s]=e+t[s],i[s+1]=r+t[s+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,r,i,s){switch(s){case 90:return[1-e/r,t/i];case 180:return[1-t/r,1-e/i];case 270:return[e/r,1-t/i];default:return[t/r,e/i]}}static _normalizePagePoint(t,e,r){switch(r){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,r,i,s,A){return[(t+5*r)/6,(e+5*i)/6,(5*r+s)/6,(5*i+A)/6,(r+s)/2,(i+A)/2]}}ht(re,"PRECISION",1e-4);var wA,Ia,xp,Ep,xo,qe,Mf,Of,a1,o1,Sp,Fp,xh,l1,rb,ib,sn,im,tk,ek,rk,ik,nk,sk;const fl=class fl{constructor({x:t,y:e},r,i,s,A,a=0){T(this,sn);T(this,wA);T(this,Ia,[]);T(this,xp);T(this,Ep);T(this,xo,[]);T(this,qe,new Float32Array(18));T(this,Mf);T(this,Of);T(this,a1);T(this,o1);T(this,Sp);T(this,Fp);T(this,xh,[]);E(this,wA,r),E(this,Fp,s*i),E(this,Ep,A),h(this,qe).set([NaN,NaN,NaN,NaN,t,e],6),E(this,xp,a),E(this,o1,h(fl,l1)*i),E(this,a1,h(fl,ib)*i),E(this,Sp,i),h(this,xh).push(t,e)}isEmpty(){return isNaN(h(this,qe)[8])}add({x:t,y:e}){var L;E(this,Mf,t),E(this,Of,e);const[r,i,s,A]=h(this,wA);let[a,o,l,c]=h(this,qe).subarray(8,12);const u=t-l,d=e-c,f=Math.hypot(u,d);if(f<h(this,a1))return!1;const m=f-h(this,o1),p=m/f,y=p*u,v=p*d;let b=a,C=o;a=l,o=c,l+=y,c+=v,(L=h(this,xh))==null||L.push(t,e);const x=-v/m,F=y/m,I=x*h(this,Fp),Q=F*h(this,Fp);return h(this,qe).set(h(this,qe).subarray(2,8),0),h(this,qe).set([l+I,c+Q],4),h(this,qe).set(h(this,qe).subarray(14,18),12),h(this,qe).set([l-I,c-Q],16),isNaN(h(this,qe)[6])?(h(this,xo).length===0&&(h(this,qe).set([a+I,o+Q],2),h(this,xo).push(NaN,NaN,NaN,NaN,(a+I-r)/s,(o+Q-i)/A),h(this,qe).set([a-I,o-Q],14),h(this,Ia).push(NaN,NaN,NaN,NaN,(a-I-r)/s,(o-Q-i)/A)),h(this,qe).set([b,C,a,o,l,c],6),!this.isEmpty()):(h(this,qe).set([b,C,a,o,l,c],6),Math.abs(Math.atan2(C-o,b-a)-Math.atan2(v,y))<Math.PI/2?([a,o,l,c]=h(this,qe).subarray(2,6),h(this,xo).push(NaN,NaN,NaN,NaN,((a+l)/2-r)/s,((o+c)/2-i)/A),[a,o,b,C]=h(this,qe).subarray(14,18),h(this,Ia).push(NaN,NaN,NaN,NaN,((b+a)/2-r)/s,((C+o)/2-i)/A),!0):([b,C,a,o,l,c]=h(this,qe).subarray(0,6),h(this,xo).push(((b+5*a)/6-r)/s,((C+5*o)/6-i)/A,((5*a+l)/6-r)/s,((5*o+c)/6-i)/A,((a+l)/2-r)/s,((o+c)/2-i)/A),[l,c,a,o,b,C]=h(this,qe).subarray(12,18),h(this,Ia).push(((b+5*a)/6-r)/s,((C+5*o)/6-i)/A,((5*a+l)/6-r)/s,((5*o+c)/6-i)/A,((a+l)/2-r)/s,((o+c)/2-i)/A),!0))}toSVGPath(){if(this.isEmpty())return"";const t=h(this,xo),e=h(this,Ia);if(isNaN(h(this,qe)[6])&&!this.isEmpty())return P(this,sn,tk).call(this);const r=[];r.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?r.push(`L${t[i+4]} ${t[i+5]}`):r.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);P(this,sn,rk).call(this,r);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?r.push(`L${e[i+4]} ${e[i+5]}`):r.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return P(this,sn,ek).call(this,r),r.join(" ")}newFreeDrawOutline(t,e,r,i,s,A){return new Ak(t,e,r,i,s,A)}getOutlines(){var u;const t=h(this,xo),e=h(this,Ia),r=h(this,qe),[i,s,A,a]=h(this,wA),o=new Float32Array((((u=h(this,xh))==null?void 0:u.length)??0)+2);for(let d=0,f=o.length-2;d<f;d+=2)o[d]=(h(this,xh)[d]-i)/A,o[d+1]=(h(this,xh)[d+1]-s)/a;if(o[o.length-2]=(h(this,Mf)-i)/A,o[o.length-1]=(h(this,Of)-s)/a,isNaN(r[6])&&!this.isEmpty())return P(this,sn,ik).call(this,o);const l=new Float32Array(h(this,xo).length+24+h(this,Ia).length);let c=t.length;for(let d=0;d<c;d+=2){if(isNaN(t[d])){l[d]=l[d+1]=NaN;continue}l[d]=t[d],l[d+1]=t[d+1]}c=P(this,sn,sk).call(this,l,c);for(let d=e.length-6;d>=6;d-=6)for(let f=0;f<6;f+=2){if(isNaN(e[d+f])){l[c]=l[c+1]=NaN,c+=2;continue}l[c]=e[d+f],l[c+1]=e[d+f+1],c+=2}return P(this,sn,nk).call(this,l,c),this.newFreeDrawOutline(l,o,h(this,wA),h(this,Sp),h(this,xp),h(this,Ep))}};wA=new WeakMap,Ia=new WeakMap,xp=new WeakMap,Ep=new WeakMap,xo=new WeakMap,qe=new WeakMap,Mf=new WeakMap,Of=new WeakMap,a1=new WeakMap,o1=new WeakMap,Sp=new WeakMap,Fp=new WeakMap,xh=new WeakMap,l1=new WeakMap,rb=new WeakMap,ib=new WeakMap,sn=new WeakSet,im=function(){const t=h(this,qe).subarray(4,6),e=h(this,qe).subarray(16,18),[r,i,s,A]=h(this,wA);return[(h(this,Mf)+(t[0]-e[0])/2-r)/s,(h(this,Of)+(t[1]-e[1])/2-i)/A,(h(this,Mf)+(e[0]-t[0])/2-r)/s,(h(this,Of)+(e[1]-t[1])/2-i)/A]},tk=function(){const[t,e,r,i]=h(this,wA),[s,A,a,o]=P(this,sn,im).call(this);return`M${(h(this,qe)[2]-t)/r} ${(h(this,qe)[3]-e)/i} L${(h(this,qe)[4]-t)/r} ${(h(this,qe)[5]-e)/i} L${s} ${A} L${a} ${o} L${(h(this,qe)[16]-t)/r} ${(h(this,qe)[17]-e)/i} L${(h(this,qe)[14]-t)/r} ${(h(this,qe)[15]-e)/i} Z`},ek=function(t){const e=h(this,Ia);t.push(`L${e[4]} ${e[5]} Z`)},rk=function(t){const[e,r,i,s]=h(this,wA),A=h(this,qe).subarray(4,6),a=h(this,qe).subarray(16,18),[o,l,c,u]=P(this,sn,im).call(this);t.push(`L${(A[0]-e)/i} ${(A[1]-r)/s} L${o} ${l} L${c} ${u} L${(a[0]-e)/i} ${(a[1]-r)/s}`)},ik=function(t){const e=h(this,qe),[r,i,s,A]=h(this,wA),[a,o,l,c]=P(this,sn,im).call(this),u=new Float32Array(36);return u.set([NaN,NaN,NaN,NaN,(e[2]-r)/s,(e[3]-i)/A,NaN,NaN,NaN,NaN,(e[4]-r)/s,(e[5]-i)/A,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,(e[16]-r)/s,(e[17]-i)/A,NaN,NaN,NaN,NaN,(e[14]-r)/s,(e[15]-i)/A],0),this.newFreeDrawOutline(u,t,h(this,wA),h(this,Sp),h(this,xp),h(this,Ep))},nk=function(t,e){const r=h(this,Ia);return t.set([NaN,NaN,NaN,NaN,r[4],r[5]],e),e+=6},sk=function(t,e){const r=h(this,qe).subarray(4,6),i=h(this,qe).subarray(16,18),[s,A,a,o]=h(this,wA),[l,c,u,d]=P(this,sn,im).call(this);return t.set([NaN,NaN,NaN,NaN,(r[0]-s)/a,(r[1]-A)/o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(i[0]-s)/a,(i[1]-A)/o],e),e+=24},T(fl,l1,8),T(fl,rb,2),T(fl,ib,h(fl,l1)+h(fl,rb));let w2=fl;var _p,kf,jl,c1,yA,h1,Ii,nb,ak;class Ak extends re{constructor(e,r,i,s,A,a){super();T(this,nb);T(this,_p);T(this,kf,new Float32Array(4));T(this,jl);T(this,c1);T(this,yA);T(this,h1);T(this,Ii);E(this,Ii,e),E(this,yA,r),E(this,_p,i),E(this,h1,s),E(this,jl,A),E(this,c1,a),this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],P(this,nb,ak).call(this,a);const[o,l,c,u]=h(this,kf);for(let d=0,f=e.length;d<f;d+=2)e[d]=(e[d]-o)/c,e[d+1]=(e[d+1]-l)/u;for(let d=0,f=r.length;d<f;d+=2)r[d]=(r[d]-o)/c,r[d+1]=(r[d+1]-l)/u}toSVGPath(){const e=[`M${h(this,Ii)[4]} ${h(this,Ii)[5]}`];for(let r=6,i=h(this,Ii).length;r<i;r+=6){if(isNaN(h(this,Ii)[r])){e.push(`L${h(this,Ii)[r+4]} ${h(this,Ii)[r+5]}`);continue}e.push(`C${h(this,Ii)[r]} ${h(this,Ii)[r+1]} ${h(this,Ii)[r+2]} ${h(this,Ii)[r+3]} ${h(this,Ii)[r+4]} ${h(this,Ii)[r+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,r,i,s],A){const a=i-e,o=s-r;let l,c;switch(A){case 0:l=re._rescale(h(this,Ii),e,s,a,-o),c=re._rescale(h(this,yA),e,s,a,-o);break;case 90:l=re._rescaleAndSwap(h(this,Ii),e,r,a,o),c=re._rescaleAndSwap(h(this,yA),e,r,a,o);break;case 180:l=re._rescale(h(this,Ii),i,r,-a,o),c=re._rescale(h(this,yA),i,r,-a,o);break;case 270:l=re._rescaleAndSwap(h(this,Ii),i,s,-a,-o),c=re._rescaleAndSwap(h(this,yA),i,s,-a,-o);break}return{outline:Array.from(l),points:[Array.from(c)]}}get box(){return h(this,kf)}newOutliner(e,r,i,s,A,a=0){return new w2(e,r,i,s,A,a)}getNewOutline(e,r){const[i,s,A,a]=h(this,kf),[o,l,c,u]=h(this,_p),d=A*c,f=a*u,m=i*c+o,p=s*u+l,y=this.newOutliner({x:h(this,yA)[0]*d+m,y:h(this,yA)[1]*f+p},h(this,_p),h(this,h1),e,h(this,c1),r??h(this,jl));for(let v=2;v<h(this,yA).length;v+=2)y.add({x:h(this,yA)[v]*d+m,y:h(this,yA)[v+1]*f+p});return y.getOutlines()}}_p=new WeakMap,kf=new WeakMap,jl=new WeakMap,c1=new WeakMap,yA=new WeakMap,h1=new WeakMap,Ii=new WeakMap,nb=new WeakSet,ak=function(e){const r=h(this,Ii);let i=r[4],s=r[5];const A=[i,s,i,s];let a=i,o=s,l=i,c=s;const u=e?Math.max:Math.min,d=new Float32Array(4);for(let m=6,p=r.length;m<p;m+=6){const y=r[m+4],v=r[m+5];isNaN(r[m])?(Mt.pointBoundingBox(y,v,A),o>v?(a=y,o=v):o===v&&(a=u(a,y)),c<v?(l=y,c=v):c===v&&(l=u(l,y))):(d.set(Zl,0),Mt.bezierBoundingBox(i,s,...r.slice(m,m+6),d),Mt.rectBoundingBox(...d,A),o>d[1]?(a=d[0],o=d[1]):o===d[1]&&(a=u(a,d[0])),c<d[3]?(l=d[2],c=d[3]):c===d[3]&&(l=u(l,d[2]))),i=y,s=v}const f=h(this,kf);f[0]=A[0]-h(this,jl),f[1]=A[1]-h(this,jl),f[2]=A[2]-A[0]+2*h(this,jl),f[3]=A[3]-A[1]+2*h(this,jl),this.firstPoint=[a,o],this.lastPoint=[l,c]};var u1,f1,d1,Eh,Ua,_s,ok,Vy,lk,ck,$S;class YS{constructor(t,e=0,r=0,i=!0){T(this,_s);T(this,u1);T(this,f1);T(this,d1);T(this,Eh,[]);T(this,Ua,[]);const s=Zl.slice(),A=10**-4;for(const{x:p,y,width:v,height:b}of t){const C=Math.floor((p-e)/A)*A,x=Math.ceil((p+v+e)/A)*A,F=Math.floor((y-e)/A)*A,I=Math.ceil((y+b+e)/A)*A,Q=[C,F,I,!0],R=[x,F,I,!1];h(this,Eh).push(Q,R),Mt.rectBoundingBox(C,F,x,I,s)}const a=s[2]-s[0]+2*r,o=s[3]-s[1]+2*r,l=s[0]-r,c=s[1]-r;let u=i?-1/0:1/0,d=1/0;const f=h(this,Eh).at(i?-1:-2),m=[f[0],f[2]];for(const p of h(this,Eh)){const[y,v,b,C]=p;!C&&i?v<d?(d=v,u=y):v===d&&(u=Math.max(u,y)):C&&!i&&(v<d?(d=v,u=y):v===d&&(u=Math.min(u,y))),p[0]=(y-l)/a,p[1]=(v-c)/o,p[2]=(b-c)/o}E(this,u1,new Float32Array([l,c,a,o])),E(this,f1,[u,d]),E(this,d1,m)}getOutlines(){h(this,Eh).sort((e,r)=>e[0]-r[0]||e[1]-r[1]||e[2]-r[2]);const t=[];for(const e of h(this,Eh))e[3]?(t.push(...P(this,_s,$S).call(this,e)),P(this,_s,lk).call(this,e)):(P(this,_s,ck).call(this,e),t.push(...P(this,_s,$S).call(this,e)));return P(this,_s,ok).call(this,t)}}u1=new WeakMap,f1=new WeakMap,d1=new WeakMap,Eh=new WeakMap,Ua=new WeakMap,_s=new WeakSet,ok=function(t){const e=[],r=new Set;for(const A of t){const[a,o,l]=A;e.push([a,o,A],[a,l,A])}e.sort((A,a)=>A[1]-a[1]||A[0]-a[0]);for(let A=0,a=e.length;A<a;A+=2){const o=e[A][2],l=e[A+1][2];o.push(l),l.push(o),r.add(o),r.add(l)}const i=[];let s;for(;r.size>0;){const A=r.values().next().value;let[a,o,l,c,u]=A;r.delete(A);let d=a,f=o;for(s=[a,l],i.push(s);;){let m;if(r.has(c))m=c;else if(r.has(u))m=u;else break;r.delete(m),[a,o,l,c,u]=m,d!==a&&(s.push(d,f,a,f===o?o:l),d=a),f=f===o?l:o}s.push(d,f)}return new gj(i,h(this,u1),h(this,f1),h(this,d1))},Vy=function(t){const e=h(this,Ua);let r=0,i=e.length-1;for(;r<=i;){const s=r+i>>1,A=e[s][0];if(A===t)return s;A<t?r=s+1:i=s-1}return i+1},lk=function([,t,e]){const r=P(this,_s,Vy).call(this,t);h(this,Ua).splice(r,0,[t,e])},ck=function([,t,e]){const r=P(this,_s,Vy).call(this,t);for(let i=r;i<h(this,Ua).length;i++){const[s,A]=h(this,Ua)[i];if(s!==t)break;if(s===t&&A===e){h(this,Ua).splice(i,1);return}}for(let i=r-1;i>=0;i--){const[s,A]=h(this,Ua)[i];if(s!==t)break;if(s===t&&A===e){h(this,Ua).splice(i,1);return}}},$S=function(t){const[e,r,i]=t,s=[[e,r,i]],A=P(this,_s,Vy).call(this,i);for(let a=0;a<A;a++){const[o,l]=h(this,Ua)[a];for(let c=0,u=s.length;c<u;c++){const[,d,f]=s[c];if(!(l<=d||f<=o)){if(d>=o){if(f>l)s[c][1]=l;else{if(u===1)return[];s.splice(c,1),c--,u--}continue}s[c][2]=o,f>l&&s.push([e,l,f])}}}return s};var g1,Tp;class gj extends re{constructor(e,r,i,s){super();T(this,g1);T(this,Tp);E(this,Tp,e),E(this,g1,r),this.firstPoint=i,this.lastPoint=s}toSVGPath(){const e=[];for(const r of h(this,Tp)){let[i,s]=r;e.push(`M${i} ${s}`);for(let A=2;A<r.length;A+=2){const a=r[A],o=r[A+1];a===i?(e.push(`V${o}`),s=o):o===s&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,r,i,s],A){const a=[],o=i-e,l=s-r;for(const c of h(this,Tp)){const u=new Array(c.length);for(let d=0;d<c.length;d+=2)u[d]=e+c[d]*o,u[d+1]=s-c[d+1]*l;a.push(u)}return a}get box(){return h(this,g1)}get classNamesForOutlining(){return["highlightOutline"]}}g1=new WeakMap,Tp=new WeakMap;class JS extends w2{newFreeDrawOutline(t,e,r,i,s,A){return new pj(t,e,r,i,s,A)}}class pj extends Ak{newOutliner(t,e,r,i,s,A=0){return new JS(t,e,r,i,s,A)}}var Ip,p1,Vl,Rf,m1,Ks,v1,w1,Df,bA,BA,Un,Up,Lp,ss,Pp,$A,y1,Ge,ZS,qy,hk,uk,fk,tF,bu,ta,sg,dk,Wy,zy,gk,pk,mk,vk,wk;const ar=class ar extends Rr{constructor(e){super({...e,name:"highlightEditor"});T(this,Ge);T(this,Ip,null);T(this,p1,0);T(this,Vl);T(this,Rf,null);T(this,m1,null);T(this,Ks,null);T(this,v1,null);T(this,w1,0);T(this,Df,null);T(this,bA,null);T(this,BA,null);T(this,Un,!1);T(this,Up,null);T(this,Lp,null);T(this,ss,null);T(this,Pp,"");T(this,$A);T(this,y1,"");this.color=e.color||ar._defaultColor,E(this,$A,e.thickness||ar._defaultThickness),this.opacity=e.opacity||ar._defaultOpacity,E(this,Vl,e.boxes||null),E(this,y1,e.methodOfCreation||""),E(this,Pp,e.text||""),this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",e.highlightId>-1?(E(this,Un,!0),P(this,Ge,qy).call(this,e),P(this,Ge,bu).call(this)):h(this,Vl)&&(E(this,Ip,e.anchorNode),E(this,p1,e.anchorOffset),E(this,v1,e.focusNode),E(this,w1,e.focusOffset),P(this,Ge,ZS).call(this),P(this,Ge,bu).call(this),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}static get _keyboardManager(){const e=ar.prototype;return Te(this,"_keyboardManager",new M1([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:h(this,Un)?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:h(this,$A),methodOfCreation:h(this,y1)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,r){var i;Rr.initialize(e,r),ar._defaultColor||(ar._defaultColor=((i=r.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,r){switch(e){case Qe.HIGHLIGHT_COLOR:ar._defaultColor=r;break;case Qe.HIGHLIGHT_THICKNESS:ar._defaultThickness=r;break}}translateInPage(e,r){}get toolbarPosition(){return h(this,Lp)}get commentButtonPosition(){return h(this,Up)}updateParams(e,r){switch(e){case Qe.HIGHLIGHT_COLOR:P(this,Ge,hk).call(this,r);break;case Qe.HIGHLIGHT_THICKNESS:P(this,Ge,uk).call(this,r);break}}static get defaultPropertiesToUpdate(){return[[Qe.HIGHLIGHT_COLOR,ar._defaultColor],[Qe.HIGHLIGHT_THICKNESS,ar._defaultThickness]]}get propertiesToUpdate(){return[[Qe.HIGHLIGHT_COLOR,this.color||ar._defaultColor],[Qe.HIGHLIGHT_THICKNESS,h(this,$A)||ar._defaultThickness],[Qe.HIGHLIGHT_FREE,h(this,Un)]]}onUpdatedColor(){var e,r;(e=this.parent)==null||e.drawLayer.updateProperties(h(this,BA),{root:{fill:this.color,"fill-opacity":this.opacity}}),(r=h(this,m1))==null||r.updateColor(this.color),super.onUpdatedColor()}get toolbarButtons(){return this._uiManager.highlightColors?[["colorPicker",E(this,m1,new km({editor:this}))]]:super.toolbarButtons}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(P(this,Ge,zy).call(this))}getBaseTranslation(){return[0,0]}getRect(e,r){return super.getRect(e,r,P(this,Ge,zy).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){P(this,Ge,tF).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(P(this,Ge,bu).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let r=!1;this.parent&&!e?P(this,Ge,tF).call(this):e&&(P(this,Ge,bu).call(this,e),r=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),r&&this.select()}rotate(e){var s,A,a;const{drawLayer:r}=this.parent;let i;h(this,Un)?(e=(e-this.rotation+360)%360,i=P(s=ar,ta,sg).call(s,h(this,bA).box,e)):i=P(A=ar,ta,sg).call(A,[this.x,this.y,this.width,this.height],e),r.updateProperties(h(this,BA),{bbox:i,root:{"data-main-rotation":e}}),r.updateProperties(h(this,ss),{bbox:P(a=ar,ta,sg).call(a,h(this,Ks).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();h(this,Pp)&&(e.setAttribute("aria-label",h(this,Pp)),e.setAttribute("role","mark")),h(this,Un)?e.classList.add("free"):this.div.addEventListener("keydown",P(this,Ge,dk).bind(this),{signal:this._uiManager._signal});const r=E(this,Df,document.createElement("div"));return e.append(r),r.setAttribute("aria-hidden","true"),r.className="internal",r.style.clipPath=h(this,Rf),this.setDims(),SM(this,h(this,Df),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(h(this,ss),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(h(this,ss),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:P(this,Ge,Wy).call(this,!0);break;case 1:case 3:P(this,Ge,Wy).call(this,!1);break}}select(){var e;super.select(),h(this,ss)&&((e=this.parent)==null||e.drawLayer.updateProperties(h(this,ss),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),h(this,ss)&&((e=this.parent)==null||e.drawLayer.updateProperties(h(this,ss),{rootClass:{selected:!1}}),h(this,Un)||P(this,Ge,Wy).call(this,!1))}get _mustFixPosition(){return!h(this,Un)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(h(this,BA),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(h(this,ss),{rootClass:{hidden:!e}}))}static startHighlighting(e,r,{target:i,x:s,y:A}){const{x:a,y:o,width:l,height:c}=i.getBoundingClientRect(),u=new AbortController,d=e.combinedSignal(u),f=m=>{u.abort(),P(this,ta,vk).call(this,e,m)};window.addEventListener("blur",f,{signal:d}),window.addEventListener("pointerup",f,{signal:d}),window.addEventListener("pointerdown",Zr,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",UA,{signal:d}),i.addEventListener("pointermove",P(this,ta,mk).bind(this,e),{signal:d}),this._freeHighlight=new JS({x:s,y:A},[a,o,l,c],e.scale,this._defaultThickness/2,r,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,r,i){var y,v,b,C;let s=null;if(e instanceof WO){const{data:{quadPoints:x,rect:F,rotation:I,id:Q,color:R,opacity:L,popupRef:j,richText:U,contentsObj:k,creationDate:G,modificationDate:D},parent:{page:{pageNumber:rt}}}=e;s=e={annotationType:Fe.HIGHLIGHT,color:Array.from(R),opacity:L,quadPoints:x,boxes:null,pageIndex:rt-1,rect:F.slice(0),rotation:I,annotationElementId:Q,id:Q,deleted:!1,popupRef:j,richText:U,comment:(k==null?void 0:k.str)||null,creationDate:G,modificationDate:D}}else if(e instanceof B4){const{data:{inkLists:x,rect:F,rotation:I,id:Q,color:R,borderStyle:{rawWidth:L},popupRef:j,richText:U,contentsObj:k,creationDate:G,modificationDate:D},parent:{page:{pageNumber:rt}}}=e;s=e={annotationType:Fe.HIGHLIGHT,color:Array.from(R),thickness:L,inkLists:x,boxes:null,pageIndex:rt-1,rect:F.slice(0),rotation:I,annotationElementId:Q,id:Q,deleted:!1,popupRef:j,richText:U,comment:(k==null?void 0:k.str)||null,creationDate:G,modificationDate:D}}const{color:A,quadPoints:a,inkLists:o,outlines:l,opacity:c}=e,u=await super.deserialize(e,r,i);u.color=Mt.makeHexColor(...A),u.opacity=c||1,o&&E(u,$A,e.thickness),u._initialData=s,e.comment&&u.setCommentData(e);const[d,f]=u.pageDimensions,[m,p]=u.pageTranslation;if(a){const x=E(u,Vl,[]);for(let F=0;F<a.length;F+=8)x.push({x:(a[F]-m)/d,y:1-(a[F+1]-p)/f,width:(a[F+2]-a[F])/d,height:(a[F+1]-a[F+5])/f});P(y=u,Ge,ZS).call(y),P(v=u,Ge,bu).call(v),u.rotate(u.rotation)}else if(o||l){E(u,Un,!0);const x=(o||l.points)[0],F={x:x[0]-m,y:f-(x[1]-p)},I=new JS(F,[0,0,d,f],1,h(u,$A)/2,!0,.001);for(let L=0,j=x.length;L<j;L+=2)F.x=x[L]-m,F.y=f-(x[L+1]-p),I.add(F);const{id:Q,clipPathId:R}=r.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:I.toSVGPath()}},!0,!0);P(b=u,Ge,qy).call(b,{highlightOutlines:I.getOutlines(),highlightId:Q,clipPathId:R}),P(C=u,Ge,bu).call(C),u.rotate(u.parentRotation)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const r=Rr._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),i=super.serialize(e);return Object.assign(i,{color:r,opacity:this.opacity,thickness:h(this,$A),quadPoints:P(this,Ge,gk).call(this),outlines:P(this,Ge,pk).call(this,i.rect)}),this.addComment(i),this.annotationElementId&&!P(this,Ge,wk).call(this,i)?null:(i.id=this.annotationElementId,i)}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}};Ip=new WeakMap,p1=new WeakMap,Vl=new WeakMap,Rf=new WeakMap,m1=new WeakMap,Ks=new WeakMap,v1=new WeakMap,w1=new WeakMap,Df=new WeakMap,bA=new WeakMap,BA=new WeakMap,Un=new WeakMap,Up=new WeakMap,Lp=new WeakMap,ss=new WeakMap,Pp=new WeakMap,$A=new WeakMap,y1=new WeakMap,Ge=new WeakSet,ZS=function(){const e=new YS(h(this,Vl),.001);E(this,bA,e.getOutlines()),[this.x,this.y,this.width,this.height]=h(this,bA).box;const r=new YS(h(this,Vl),.0025,.001,this._uiManager.direction==="ltr");E(this,Ks,r.getOutlines());const{firstPoint:i}=h(this,bA);E(this,Up,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height]);const{lastPoint:s}=h(this,Ks);E(this,Lp,[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height])},qy=function({highlightOutlines:e,highlightId:r,clipPathId:i}){var d,f;if(E(this,bA,e),E(this,Ks,e.getNewOutline(h(this,$A)/2+1.5,.0025)),r>=0)E(this,BA,r),E(this,Rf,i),this.parent.drawLayer.finalizeDraw(r,{bbox:e.box,path:{d:e.toSVGPath()}}),E(this,ss,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:h(this,Ks).box,path:{d:h(this,Ks).toSVGPath()}},!0));else if(this.parent){const m=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(h(this,BA),{bbox:P(d=ar,ta,sg).call(d,h(this,bA).box,(m-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(h(this,ss),{bbox:P(f=ar,ta,sg).call(f,h(this,Ks).box,m),path:{d:h(this,Ks).toSVGPath()}})}const[A,a,o,l]=e.box;switch(this.rotation){case 0:this.x=A,this.y=a,this.width=o,this.height=l;break;case 90:{const[m,p]=this.parentDimensions;this.x=a,this.y=1-A,this.width=o*p/m,this.height=l*m/p;break}case 180:this.x=1-A,this.y=1-a,this.width=o,this.height=l;break;case 270:{const[m,p]=this.parentDimensions;this.x=1-a,this.y=A,this.width=o*p/m,this.height=l*m/p;break}}const{firstPoint:c}=e;E(this,Up,[(c[0]-A)/o,(c[1]-a)/l]);const{lastPoint:u}=h(this,Ks);E(this,Lp,[(u[0]-A)/o,(u[1]-a)/l])},hk=function(e){const r=(A,a)=>{this.color=A,this.opacity=a,this.onUpdatedColor()},i=this.color,s=this.opacity;this.addCommands({cmd:r.bind(this,e,ar._defaultOpacity),undo:r.bind(this,i,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Qe.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0)},uk=function(e){const r=h(this,$A),i=s=>{E(this,$A,s),P(this,Ge,fk).call(this,s)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Qe.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},fk=function(e){h(this,Un)&&(P(this,Ge,qy).call(this,{highlightOutlines:h(this,bA).getNewOutline(e/2)}),this.fixAndSetPosition(),this.setDims())},tF=function(){h(this,BA)===null||!this.parent||(this.parent.drawLayer.remove(h(this,BA)),E(this,BA,null),this.parent.drawLayer.remove(h(this,ss)),E(this,ss,null))},bu=function(e=this.parent){h(this,BA)===null&&({id:Di(this,BA)._,clipPathId:Di(this,Rf)._}=e.drawLayer.draw({bbox:h(this,bA).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:h(this,Un)},path:{d:h(this,bA).toSVGPath()}},!1,!0),E(this,ss,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:h(this,Un)},bbox:h(this,Ks).box,path:{d:h(this,Ks).toSVGPath()}},h(this,Un))),h(this,Df)&&(h(this,Df).style.clipPath=h(this,Rf)))},ta=new WeakSet,sg=function([e,r,i,s],A){switch(A){case 90:return[1-r-s,e,s,i];case 180:return[1-e-i,1-r-s,i,s];case 270:return[r,1-e-i,s,i]}return[e,r,i,s]},dk=function(e){ar._keyboardManager.exec(this,e)},Wy=function(e){if(!h(this,Ip))return;const r=window.getSelection();e?r.setPosition(h(this,Ip),h(this,p1)):r.setPosition(h(this,v1),h(this,w1))},zy=function(){return h(this,Un)?this.rotation:0},gk=function(){if(h(this,Un))return null;const[e,r]=this.pageDimensions,[i,s]=this.pageTranslation,A=h(this,Vl),a=new Float32Array(A.length*8);let o=0;for(const{x:l,y:c,width:u,height:d}of A){const f=l*e+i,m=(1-c)*r+s;a[o]=a[o+4]=f,a[o+1]=a[o+3]=m,a[o+2]=a[o+6]=f+u*e,a[o+5]=a[o+7]=m-d*r,o+=8}return a},pk=function(e){return h(this,bA).serialize(e,P(this,Ge,zy).call(this))},mk=function(e,r){this._freeHighlight.add(r)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},vk=function(e,r){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(r,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},wk=function(e){const{color:r}=this._initialData;return this.hasEditedComment||e.color.some((i,s)=>i!==r[s])},T(ar,ta),ht(ar,"_defaultColor",null),ht(ar,"_defaultOpacity",1),ht(ar,"_defaultThickness",12),ht(ar,"_type","highlight"),ht(ar,"_editorType",Fe.HIGHLIGHT),ht(ar,"_freeHighlightId",-1),ht(ar,"_freeHighlight",null),ht(ar,"_freeHighlightClipId","");let y2=ar;var Hf;class yk{constructor(){T(this,Hf,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,r]of Object.entries(t))e.startsWith("_")||this.updateProperty(e,r)}updateSVGProperty(t,e){h(this,Hf)[t]=e}toSVGProperties(){const t=h(this,Hf);return E(this,Hf,Object.create(null)),{root:t}}reset(){E(this,Hf,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){ur("Not implemented")}}Hf=new WeakMap;var bs,Np,fn,Kf,Gf,ir,eF,rF,iF,nm,bk,Xy,sm,Ag;const Xe=class Xe extends Rr{constructor(e){super(e);T(this,ir);T(this,bs,null);T(this,Np);ht(this,"_colorPicker",null);ht(this,"_drawId",null);E(this,Np,e.mustBeCommitted||!1),this._addOutlines(e)}onUpdatedColor(){var e;(e=this._colorPicker)==null||e.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){var e,r;(r=(e=this._colorPicker)==null?void 0:e.updateOpacity)==null||r.call(e,this.opacity)}_addOutlines(e){e.drawOutlines&&(P(this,ir,eF).call(this,e),P(this,ir,nm).call(this))}static _mergeSVGProperties(e,r){const i=new Set(Object.keys(e));for(const[s,A]of Object.entries(r))i.has(s)?Object.assign(e[s],A):e[s]=A;return e}static getDefaultDrawingOptions(e){ur("Not implemented")}static get typesMap(){ur("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,r){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,r),this._currentParent&&(h(Xe,fn).updateProperty(i,r),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,r){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,r)}static get defaultPropertiesToUpdate(){const e=[],r=this._defaultDrawingOptions;for(const[i,s]of this.typesMap)e.push([i,r[s]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:r}=this;for(const[i,s]of this.constructor.typesMap)e.push([i,r[s]]);return e}_updateProperty(e,r,i){const s=this._drawingOptions,A=s[r],a=o=>{var c;s.updateProperty(r,o);const l=h(this,bs).updateProperty(r,o);l&&P(this,ir,sm).call(this,l),(c=this.parent)==null||c.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,i),undo:a.bind(this,A),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,r){const i=this.constructor.typesMap.get(this.colorType),s=this.constructor.typesMap.get(this.opacityType),A=this._drawingOptions,a=A[i],o=A[s],l=(c,u)=>{var d;A.updateProperty(i,c),A.updateProperty(s,u),h(this,bs).updateProperty(i,c),h(this,bs).updateProperty(s,u),(d=this.parent)==null||d.drawLayer.updateProperties(this._drawId,A.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:l.bind(this,e,r),undo:l.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Qe.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Xe._mergeSVGProperties(h(this,bs).getPathResizingSVGProperties(P(this,ir,Xy).call(this)),{bbox:P(this,ir,Ag).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Xe._mergeSVGProperties(h(this,bs).getPathResizedSVGProperties(P(this,ir,Xy).call(this)),{bbox:P(this,ir,Ag).call(this)}))}_onTranslating(e,r){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:P(this,ir,Ag).call(this)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Xe._mergeSVGProperties(h(this,bs).getPathTranslatedSVGProperties(P(this,ir,Xy).call(this),this.parentDimensions),{bbox:P(this,ir,Ag).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,h(this,Np)&&(E(this,Np,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){P(this,ir,iF).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(P(this,ir,nm).call(this),P(this,ir,sm).call(this,h(this,bs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let r=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),P(this,ir,iF).call(this)):e&&(this._uiManager.addShouldRescale(this),P(this,ir,nm).call(this,e),r=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),r&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Xe._mergeSVGProperties({bbox:P(this,ir,Ag).call(this)},h(this,bs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&P(this,ir,sm).call(this,h(this,bs).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,r;this._isCopy&&(e=this.x,r=this.y);const i=super.render();i.classList.add("draw");const s=document.createElement("div");return i.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,r),i}static createDrawerInstance(e,r,i,s,A){ur("Not implemented")}static startDrawing(e,r,i,s){var y;const{target:A,offsetX:a,offsetY:o,pointerId:l,pointerType:c}=s;if(es.isInitializedAndDifferentPointerType(c))return;const{viewport:{rotation:u}}=e,{width:d,height:f}=A.getBoundingClientRect(),m=E(Xe,Kf,new AbortController),p=e.combinedSignal(m);if(es.setPointer(c,l),window.addEventListener("pointerup",v=>{es.isSamePointerIdOrRemove(v.pointerId)&&this._endDraw(v)},{signal:p}),window.addEventListener("pointercancel",v=>{es.isSamePointerIdOrRemove(v.pointerId)&&this._currentParent.endDrawingSession()},{signal:p}),window.addEventListener("pointerdown",v=>{es.isSamePointerType(v.pointerType)&&(es.initializeAndAddPointerId(v.pointerId),h(Xe,fn).isCancellable()&&(h(Xe,fn).removeLastElement(),h(Xe,fn).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:p}),window.addEventListener("contextmenu",UA,{signal:p}),A.addEventListener("pointermove",this._drawMove.bind(this),{signal:p}),A.addEventListener("touchmove",v=>{es.isSameTimeStamp(v.timeStamp)&&Zr(v)},{signal:p}),e.toggleDrawing(),(y=r._editorUndoBar)==null||y.hide(),h(Xe,fn)){e.drawLayer.updateProperties(this._currentDrawId,h(Xe,fn).startNew(a,o,d,f,u));return}r.updateUIForDefaultProperties(this),E(Xe,fn,this.createDrawerInstance(a,o,d,f,u)),E(Xe,Gf,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(h(Xe,Gf).toSVGProperties(),h(Xe,fn).defaultSVGProperties),!0,!1)}static _drawMove(e){if(es.isSameTimeStamp(e.timeStamp),!h(Xe,fn))return;const{offsetX:r,offsetY:i,pointerId:s}=e;if(es.isSamePointerId(s)){if(es.isUsingMultiplePointers()){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,h(Xe,fn).add(r,i)),es.setTimeStamp(e.timeStamp),Zr(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,E(Xe,fn,null),E(Xe,Gf,null),es.clearTimeStamp()),h(Xe,Kf)&&(h(Xe,Kf).abort(),E(Xe,Kf,null),es.clearPointerIds())}static _endDraw(e){const r=this._currentParent;if(r){if(r.toggleDrawing(!0),this._cleanup(!1),(e==null?void 0:e.target)===r.div&&r.drawLayer.updateProperties(this._currentDrawId,h(Xe,fn).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=h(Xe,fn),s=this._currentDrawId,A=i.getLastElement();r.addCommands({cmd:()=>{r.drawLayer.updateProperties(s,i.setLastElement(A))},undo:()=>{r.drawLayer.updateProperties(s,i.removeLastElement())},mustExec:!1,type:Qe.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const r=this._currentParent;if(!r)return null;if(r.toggleDrawing(!0),r.cleanUndoStack(Qe.DRAW_STEP),!h(Xe,fn).isEmpty()){const{pageDimensions:[i,s],scale:A}=r,a=r.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:h(Xe,fn).getOutlines(i*A,s*A,A,this._INNER_MARGIN),drawingOptions:h(Xe,Gf),mustBeCommitted:!e});return this._cleanup(!0),a}return r.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,r,i,s,A,a){ur("Not implemented")}static async deserialize(e,r,i){var u,d;const{rawDims:{pageWidth:s,pageHeight:A,pageX:a,pageY:o}}=r.viewport,l=this.deserializeDraw(a,o,s,A,this._INNER_MARGIN,e),c=await super.deserialize(e,r,i);return c.createDrawingOptions(e),P(u=c,ir,eF).call(u,{drawOutlines:l}),P(d=c,ir,nm).call(d),c.onScaleChanging(),c.rotate(),c}serializeDraw(e){const[r,i]=this.pageTranslation,[s,A]=this.pageDimensions;return h(this,bs).serialize([r,i,s,A],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}};bs=new WeakMap,Np=new WeakMap,fn=new WeakMap,Kf=new WeakMap,Gf=new WeakMap,ir=new WeakSet,eF=function({drawOutlines:e,drawId:r,drawingOptions:i}){E(this,bs,e),this._drawingOptions||(this._drawingOptions=i),this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`),r>=0?(this._drawId=r,this.parent.drawLayer.finalizeDraw(r,e.defaultProperties)):this._drawId=P(this,ir,rF).call(this,e,this.parent),P(this,ir,sm).call(this,e.box)},rF=function(e,r){const{id:i}=r.drawLayer.draw(Xe._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},iF=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},nm=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=P(this,ir,rF).call(this,h(this,bs),e)}},bk=function([e,r,i,s]){const{parentDimensions:[A,a],rotation:o}=this;switch(o){case 90:return[r,1-e,i*(a/A),s*(A/a)];case 180:return[1-e,1-r,i,s];case 270:return[1-r,e,i*(a/A),s*(A/a)];default:return[e,r,i,s]}},Xy=function(){const{x:e,y:r,width:i,height:s,parentDimensions:[A,a],rotation:o}=this;switch(o){case 90:return[1-r,e,i*(A/a),s*(a/A)];case 180:return[1-e,1-r,i,s];case 270:return[r,1-e,i*(A/a),s*(a/A)];default:return[e,r,i,s]}},sm=function(e){[this.x,this.y,this.width,this.height]=P(this,ir,bk).call(this,e),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()},Ag=function(){const{x:e,y:r,width:i,height:s,rotation:A,parentRotation:a,parentDimensions:[o,l]}=this;switch((A*4+a)/90){case 1:return[1-r-s,e,s,i];case 2:return[1-e-i,1-r-s,i,s];case 3:return[r,1-e-i,s,i];case 4:return[e,r-i*(o/l),s*(l/o),i*(o/l)];case 5:return[1-r,e,i*(o/l),s*(l/o)];case 6:return[1-e-s*(l/o),1-r,s*(l/o),i*(o/l)];case 7:return[r-i*(o/l),1-e-s*(l/o),i*(o/l),s*(l/o)];case 8:return[e-i,r-s,i,s];case 9:return[1-r,e-i,s,i];case 10:return[1-e,1-r,i,s];case 11:return[r-s,1-e,s,i];case 12:return[e-s*(l/o),r,s*(l/o),i*(o/l)];case 13:return[1-r-i*(o/l),e-s*(l/o),i*(o/l),s*(l/o)];case 14:return[1-e,1-r-i*(o/l),s*(l/o),i*(o/l)];case 15:return[r,1-e,i*(o/l),s*(l/o)];default:return[e,r,i,s]}},ht(Xe,"_currentDrawId",-1),ht(Xe,"_currentParent",null),T(Xe,fn,null),T(Xe,Kf,null),T(Xe,Gf,null),ht(Xe,"_INNER_MARGIN",3);let b2=Xe;var Eo,dn,gn,jf,Qp,Bs,Ln,JA,Vf,qf,Wf,Mp,Yy;class mj{constructor(t,e,r,i,s,A){T(this,Mp);T(this,Eo,new Float64Array(6));T(this,dn);T(this,gn);T(this,jf);T(this,Qp);T(this,Bs);T(this,Ln,"");T(this,JA,0);T(this,Vf,new O1);T(this,qf);T(this,Wf);E(this,qf,r),E(this,Wf,i),E(this,jf,s),E(this,Qp,A),[t,e]=P(this,Mp,Yy).call(this,t,e);const a=E(this,dn,[NaN,NaN,NaN,NaN,t,e]);E(this,Bs,[t,e]),E(this,gn,[{line:a,points:h(this,Bs)}]),h(this,Eo).set(a,0)}updateProperty(t,e){t==="stroke-width"&&E(this,Qp,e)}isEmpty(){return!h(this,gn)||h(this,gn).length===0}isCancellable(){return h(this,Bs).length<=10}add(t,e){[t,e]=P(this,Mp,Yy).call(this,t,e);const[r,i,s,A]=h(this,Eo).subarray(2,6),a=t-s,o=e-A;return Math.hypot(h(this,qf)*a,h(this,Wf)*o)<=2?null:(h(this,Bs).push(t,e),isNaN(r)?(h(this,Eo).set([s,A,t,e],2),h(this,dn).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(h(this,Eo)[0])&&h(this,dn).splice(6,6),h(this,Eo).set([r,i,s,A,t,e],0),h(this,dn).push(...re.createBezierPoints(r,i,s,A,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const r=this.add(t,e);return r||(h(this,Bs).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,r,i,s){E(this,qf,r),E(this,Wf,i),E(this,jf,s),[t,e]=P(this,Mp,Yy).call(this,t,e);const A=E(this,dn,[NaN,NaN,NaN,NaN,t,e]);E(this,Bs,[t,e]);const a=h(this,gn).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),h(this,gn).push({line:A,points:h(this,Bs)}),h(this,Eo).set(A,0),E(this,JA,0),this.toSVGPath(),null}getLastElement(){return h(this,gn).at(-1)}setLastElement(t){return h(this,gn)?(h(this,gn).push(t),E(this,dn,t.line),E(this,Bs,t.points),E(this,JA,0),{path:{d:this.toSVGPath()}}):h(this,Vf).setLastElement(t)}removeLastElement(){if(!h(this,gn))return h(this,Vf).removeLastElement();h(this,gn).pop(),E(this,Ln,"");for(let t=0,e=h(this,gn).length;t<e;t++){const{line:r,points:i}=h(this,gn)[t];E(this,dn,r),E(this,Bs,i),E(this,JA,0),this.toSVGPath()}return{path:{d:h(this,Ln)}}}toSVGPath(){const t=re.svgRound(h(this,dn)[4]),e=re.svgRound(h(this,dn)[5]);if(h(this,Bs).length===2)return E(this,Ln,`${h(this,Ln)} M ${t} ${e} Z`),h(this,Ln);if(h(this,Bs).length<=6){const i=h(this,Ln).lastIndexOf("M");E(this,Ln,`${h(this,Ln).slice(0,i)} M ${t} ${e}`),E(this,JA,6)}if(h(this,Bs).length===4){const i=re.svgRound(h(this,dn)[10]),s=re.svgRound(h(this,dn)[11]);return E(this,Ln,`${h(this,Ln)} L ${i} ${s}`),E(this,JA,12),h(this,Ln)}const r=[];h(this,JA)===0&&(r.push(`M ${t} ${e}`),E(this,JA,6));for(let i=h(this,JA),s=h(this,dn).length;i<s;i+=6){const[A,a,o,l,c,u]=h(this,dn).slice(i,i+6).map(re.svgRound);r.push(`C${A} ${a} ${o} ${l} ${c} ${u}`)}return E(this,Ln,h(this,Ln)+r.join(" ")),E(this,JA,h(this,dn).length),h(this,Ln)}getOutlines(t,e,r,i){const s=h(this,gn).at(-1);return s.line=new Float32Array(s.line),s.points=new Float32Array(s.points),h(this,Vf).build(h(this,gn),t,e,r,h(this,jf),h(this,Qp),i),E(this,Eo,null),E(this,dn,null),E(this,gn,null),E(this,Ln,null),h(this,Vf)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Eo=new WeakMap,dn=new WeakMap,gn=new WeakMap,jf=new WeakMap,Qp=new WeakMap,Bs=new WeakMap,Ln=new WeakMap,JA=new WeakMap,Vf=new WeakMap,qf=new WeakMap,Wf=new WeakMap,Mp=new WeakSet,Yy=function(t,e){return re._normalizePoint(t,e,h(this,qf),h(this,Wf),h(this,jf))};var Cs,b1,B1,CA,So,Fo,Op,kp,zf,Qn,hl,Bk,Ck,xk;class O1 extends re{constructor(){super(...arguments);T(this,Qn);T(this,Cs);T(this,b1,0);T(this,B1);T(this,CA);T(this,So);T(this,Fo);T(this,Op);T(this,kp);T(this,zf)}build(e,r,i,s,A,a,o){E(this,So,r),E(this,Fo,i),E(this,Op,s),E(this,kp,A),E(this,zf,a),E(this,B1,o??0),E(this,CA,e),P(this,Qn,Ck).call(this)}get thickness(){return h(this,zf)}setLastElement(e){return h(this,CA).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return h(this,CA).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:r}of h(this,CA)){if(e.push(`M${re.svgRound(r[4])} ${re.svgRound(r[5])}`),r.length===6){e.push("Z");continue}if(r.length===12&&isNaN(r[6])){e.push(`L${re.svgRound(r[10])} ${re.svgRound(r[11])}`);continue}for(let i=6,s=r.length;i<s;i+=6){const[A,a,o,l,c,u]=r.subarray(i,i+6).map(re.svgRound);e.push(`C${A} ${a} ${o} ${l} ${c} ${u}`)}}return e.join("")}serialize([e,r,i,s],A){const a=[],o=[],[l,c,u,d]=P(this,Qn,Bk).call(this);let f,m,p,y,v,b,C,x,F;switch(h(this,kp)){case 0:F=re._rescale,f=e,m=r+s,p=i,y=-s,v=e+l*i,b=r+(1-c-d)*s,C=e+(l+u)*i,x=r+(1-c)*s;break;case 90:F=re._rescaleAndSwap,f=e,m=r,p=i,y=s,v=e+c*i,b=r+l*s,C=e+(c+d)*i,x=r+(l+u)*s;break;case 180:F=re._rescale,f=e+i,m=r,p=-i,y=s,v=e+(1-l-u)*i,b=r+c*s,C=e+(1-l)*i,x=r+(c+d)*s;break;case 270:F=re._rescaleAndSwap,f=e+i,m=r+s,p=-i,y=-s,v=e+(1-c-d)*i,b=r+(1-l-u)*s,C=e+(1-c)*i,x=r+(1-l)*s;break}for(const{line:I,points:Q}of h(this,CA))a.push(F(I,f,m,p,y,A?new Array(I.length):null)),o.push(F(Q,f,m,p,y,A?new Array(Q.length):null));return{lines:a,points:o,rect:[v,b,C,x]}}static deserialize(e,r,i,s,A,{paths:{lines:a,points:o},rotation:l,thickness:c}){const u=[];let d,f,m,p,y;switch(l){case 0:y=re._rescale,d=-e/i,f=r/s+1,m=1/i,p=-1/s;break;case 90:y=re._rescaleAndSwap,d=-r/s,f=-e/i,m=1/s,p=1/i;break;case 180:y=re._rescale,d=e/i+1,f=-r/s,m=-1/i,p=1/s;break;case 270:y=re._rescaleAndSwap,d=r/s+1,f=e/i+1,m=-1/s,p=-1/i;break}if(!a){a=[];for(const b of o){const C=b.length;if(C===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1]]));continue}if(C===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1],NaN,NaN,NaN,NaN,b[2],b[3]]));continue}const x=new Float32Array(3*(C-2));a.push(x);let[F,I,Q,R]=b.subarray(0,4);x.set([NaN,NaN,NaN,NaN,F,I],0);for(let L=4;L<C;L+=2){const j=b[L],U=b[L+1];x.set(re.createBezierPoints(F,I,Q,R,j,U),(L-2)*3),[F,I,Q,R]=[Q,R,j,U]}}}for(let b=0,C=a.length;b<C;b++)u.push({line:y(a[b].map(x=>x??NaN),d,f,m,p),points:y(o[b].map(x=>x??NaN),d,f,m,p)});const v=new this.prototype.constructor;return v.build(u,i,s,1,l,c,A),v}get box(){return h(this,Cs)}updateProperty(e,r){return e==="stroke-width"?P(this,Qn,xk).call(this,r):null}updateParentDimensions([e,r],i){const[s,A]=P(this,Qn,hl).call(this);E(this,So,e),E(this,Fo,r),E(this,Op,i);const[a,o]=P(this,Qn,hl).call(this),l=a-s,c=o-A,u=h(this,Cs);return u[0]-=l,u[1]-=c,u[2]+=2*l,u[3]+=2*c,u}updateRotation(e){return E(this,b1,e),{path:{transform:this.rotationTransform}}}get viewBox(){return h(this,Cs).map(re.svgRound).join(" ")}get defaultProperties(){const[e,r]=h(this,Cs);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`}}}get rotationTransform(){const[,,e,r]=h(this,Cs);let i=0,s=0,A=0,a=0,o=0,l=0;switch(h(this,b1)){case 90:s=r/e,A=-e/r,o=e;break;case 180:i=-1,a=-1,o=e,l=r;break;case 270:s=-r/e,A=e/r,l=r;break;default:return""}return`matrix(${i} ${s} ${A} ${a} ${re.svgRound(o)} ${re.svgRound(l)})`}getPathResizingSVGProperties([e,r,i,s]){const[A,a]=P(this,Qn,hl).call(this),[o,l,c,u]=h(this,Cs);if(Math.abs(c-A)<=re.PRECISION||Math.abs(u-a)<=re.PRECISION){const y=e+i/2-(o+c/2),v=r+s/2-(l+u/2);return{path:{"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`,transform:`${this.rotationTransform} translate(${y} ${v})`}}}const d=(i-2*A)/(c-2*A),f=(s-2*a)/(u-2*a),m=c/i,p=u/s;return{path:{"transform-origin":`${re.svgRound(o)} ${re.svgRound(l)}`,transform:`${this.rotationTransform} scale(${m} ${p}) translate(${re.svgRound(A)} ${re.svgRound(a)}) scale(${d} ${f}) translate(${re.svgRound(-A)} ${re.svgRound(-a)})`}}}getPathResizedSVGProperties([e,r,i,s]){const[A,a]=P(this,Qn,hl).call(this),o=h(this,Cs),[l,c,u,d]=o;if(o[0]=e,o[1]=r,o[2]=i,o[3]=s,Math.abs(u-A)<=re.PRECISION||Math.abs(d-a)<=re.PRECISION){const v=e+i/2-(l+u/2),b=r+s/2-(c+d/2);for(const{line:C,points:x}of h(this,CA))re._translate(C,v,b,C),re._translate(x,v,b,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const f=(i-2*A)/(u-2*A),m=(s-2*a)/(d-2*a),p=-f*(l+A)+e+A,y=-m*(c+a)+r+a;if(f!==1||m!==1||p!==0||y!==0)for(const{line:v,points:b}of h(this,CA))re._rescale(v,p,y,f,m,v),re._rescale(b,p,y,f,m,b);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,r],i){const[s,A]=i,a=h(this,Cs),o=e-a[0],l=r-a[1];if(h(this,So)===s&&h(this,Fo)===A)for(const{line:c,points:u}of h(this,CA))re._translate(c,o,l,c),re._translate(u,o,l,u);else{const c=h(this,So)/s,u=h(this,Fo)/A;E(this,So,s),E(this,Fo,A);for(const{line:d,points:f}of h(this,CA))re._rescale(d,o,l,c,u,d),re._rescale(f,o,l,c,u,f);a[2]*=c,a[3]*=u}return a[0]=e,a[1]=r,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${re.svgRound(e)} ${re.svgRound(r)}`}}}get defaultSVGProperties(){const e=h(this,Cs);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${re.svgRound(e[0])} ${re.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}Cs=new WeakMap,b1=new WeakMap,B1=new WeakMap,CA=new WeakMap,So=new WeakMap,Fo=new WeakMap,Op=new WeakMap,kp=new WeakMap,zf=new WeakMap,Qn=new WeakSet,hl=function(e=h(this,zf)){const r=h(this,B1)+e/2*h(this,Op);return h(this,kp)%180===0?[r/h(this,So),r/h(this,Fo)]:[r/h(this,Fo),r/h(this,So)]},Bk=function(){const[e,r,i,s]=h(this,Cs),[A,a]=P(this,Qn,hl).call(this,0);return[e+A,r+a,i-2*A,s-2*a]},Ck=function(){const e=E(this,Cs,_u.slice());for(const{line:s}of h(this,CA)){if(s.length<=12){for(let o=4,l=s.length;o<l;o+=6)Mt.pointBoundingBox(s[o],s[o+1],e);continue}let A=s[4],a=s[5];for(let o=6,l=s.length;o<l;o+=6){const[c,u,d,f,m,p]=s.subarray(o,o+6);Mt.bezierBoundingBox(A,a,c,u,d,f,m,p,e),A=m,a=p}}const[r,i]=P(this,Qn,hl).call(this);e[0]=Wr(e[0]-r,0,1),e[1]=Wr(e[1]-i,0,1),e[2]=Wr(e[2]+r,0,1),e[3]=Wr(e[3]+i,0,1),e[2]-=e[0],e[3]-=e[1]},xk=function(e){const[r,i]=P(this,Qn,hl).call(this);E(this,zf,e);const[s,A]=P(this,Qn,hl).call(this),[a,o]=[s-r,A-i],l=h(this,Cs);return l[0]-=a,l[1]-=o,l[2]+=2*a,l[3]+=2*o,l};class Ib extends yk{constructor(t){super(),this._viewParameters=t,super.updateProperties({fill:"none",stroke:Rr._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??(e=this["stroke-width"]),e*=this._viewParameters.realScale),super.updateSVGProperty(t,e)}clone(){const t=new Ib(this._viewParameters);return t.updateAll(this),t}}var sb,Ek;const fg=class fg extends b2{constructor(e){super({...e,name:"inkEditor"});T(this,sb);this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(e,r){Rr.initialize(e,r),this._defaultDrawingOptions=new Ib(r.viewParameters)}static getDefaultDrawingOptions(e){const r=this._defaultDrawingOptions.clone();return r.updateProperties(e),r}static get supportMultipleDrawings(){return!0}static get typesMap(){return Te(this,"typesMap",new Map([[Qe.INK_THICKNESS,"stroke-width"],[Qe.INK_COLOR,"stroke"],[Qe.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,r,i,s,A){return new mj(e,r,i,s,A,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,r,i,s,A,a){return O1.deserialize(e,r,i,s,A,a)}static async deserialize(e,r,i){let s=null;if(e instanceof B4){const{data:{inkLists:a,rect:o,rotation:l,id:c,color:u,opacity:d,borderStyle:{rawWidth:f},popupRef:m,richText:p,contentsObj:y,creationDate:v,modificationDate:b},parent:{page:{pageNumber:C}}}=e;s=e={annotationType:Fe.INK,color:Array.from(u),thickness:f,opacity:d,paths:{points:a},boxes:null,pageIndex:C-1,rect:o.slice(0),rotation:l,annotationElementId:c,id:c,deleted:!1,popupRef:m,richText:p,comment:(y==null?void 0:y.str)||null,creationDate:v,modificationDate:b}}const A=await super.deserialize(e,r,i);return A._initialData=s,e.comment&&A.setCommentData(e),A}get toolbarButtons(){return this._colorPicker||(this._colorPicker=new m2(this)),[["colorPicker",this._colorPicker]]}get colorType(){return Qe.INK_COLOR}get colorAndOpacityType(){return Qe.INK_COLOR_AND_OPACITY}get opacityType(){return Qe.INK_OPACITY}updateParams(e,r){if(e===Qe.INK_COLOR_AND_OPACITY){this._updateColorAndOpacity(r.color,r.opacity);return}super.updateParams(e,r)}static updateDefaultParams(e,r){if(e===Qe.INK_COLOR_AND_OPACITY){super.updateDefaultParams(Qe.INK_COLOR,r.color),super.updateDefaultParams(Qe.INK_OPACITY,r.opacity);return}super.updateDefaultParams(e,r)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:r,parent:i}=this;r.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,r.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:r,opacity:i}){this._drawingOptions=fg.getDefaultDrawingOptions({stroke:Mt.makeHexColor(...e),"stroke-width":r,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:r,points:i}=this.serializeDraw(e),{_drawingOptions:{stroke:s,"stroke-opacity":A,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:Rr._colorManager.convert(s),opacity:A,thickness:a,paths:{lines:r,points:i}});return this.addComment(o),e?(o.isCopy=!0,o):this.annotationElementId&&!P(this,sb,Ek).call(this,o)?null:(o.id=this.annotationElementId,o)}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;const{points:r,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:r,popup:this.comment}),null}};sb=new WeakSet,Ek=function(e){const{color:r,thickness:i,opacity:s,pageIndex:A}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((a,o)=>a!==r[o])||e.thickness!==i||e.opacity!==s||e.pageIndex!==A},ht(fg,"_type","ink"),ht(fg,"_editorType",Fe.INK),ht(fg,"_defaultDrawingOptions",null);let nF=fg;class sF extends O1{toSVGPath(){let t=super.toSVGPath();return t.endsWith("Z")||(t+="Z"),t}}const Rw=8,I0=3;var Xf,fr,AF,La,Sk,Fk,aF,$y,_k,Tk,Ik,oF,lF,Uk;class No{static extractContoursFromText(t,{fontFamily:e,fontStyle:r,fontWeight:i},s,A,a,o){let l=new OffscreenCanvas(1,1),c=l.getContext("2d",{alpha:!1});const u=200,d=c.font=`${r} ${i} ${u}px ${e}`,{actualBoundingBoxLeft:f,actualBoundingBoxRight:m,actualBoundingBoxAscent:p,actualBoundingBoxDescent:y,fontBoundingBoxAscent:v,fontBoundingBoxDescent:b,width:C}=c.measureText(t),x=1.5,F=Math.ceil(Math.max(Math.abs(f)+Math.abs(m)||0,C)*x),I=Math.ceil(Math.max(Math.abs(p)+Math.abs(y)||u,Math.abs(v)+Math.abs(b)||u)*x);l=new OffscreenCanvas(F,I),c=l.getContext("2d",{alpha:!0,willReadFrequently:!0}),c.font=d,c.filter="grayscale(1)",c.fillStyle="white",c.fillRect(0,0,F,I),c.fillStyle="black",c.fillText(t,F*(x-1)/2,I*(3-x)/2);const Q=P(this,fr,oF).call(this,c.getImageData(0,0,F,I).data),R=P(this,fr,Ik).call(this,Q),L=P(this,fr,lF).call(this,R),j=P(this,fr,aF).call(this,Q,F,I,L);return this.processDrawnLines({lines:{curves:j,width:F,height:I},pageWidth:s,pageHeight:A,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,r,i,s){const[A,a,o]=P(this,fr,Uk).call(this,t),[l,c]=P(this,fr,Tk).call(this,A,a,o,Math.hypot(a,o)*h(this,Xf).sigmaSFactor,h(this,Xf).sigmaR,h(this,Xf).kernelSize),u=P(this,fr,lF).call(this,c),d=P(this,fr,aF).call(this,l,a,o,u);return this.processDrawnLines({lines:{curves:d,width:a,height:o},pageWidth:e,pageHeight:r,rotation:i,innerMargin:s,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:r,rotation:i,innerMargin:s,mustSmooth:A,areContours:a}){i%180!==0&&([e,r]=[r,e]);const{curves:o,width:l,height:c}=t,u=t.thickness??0,d=[],f=Math.min(e/l,r/c),m=f/e,p=f/r,y=[];for(const{points:b}of o){const C=A?P(this,fr,_k).call(this,b):b;if(!C)continue;y.push(C);const x=C.length,F=new Float32Array(x),I=new Float32Array(3*(x===2?2:x-2));if(d.push({line:I,points:F}),x===2){F[0]=C[0]*m,F[1]=C[1]*p,I.set([NaN,NaN,NaN,NaN,F[0],F[1]],0);continue}let[Q,R,L,j]=C;Q*=m,R*=p,L*=m,j*=p,F.set([Q,R,L,j],0),I.set([NaN,NaN,NaN,NaN,Q,R],0);for(let U=4;U<x;U+=2){const k=F[U]=C[U]*m,G=F[U+1]=C[U+1]*p;I.set(re.createBezierPoints(Q,R,L,j,k,G),(U-2)*3),[Q,R,L,j]=[L,j,k,G]}}if(d.length===0)return null;const v=a?new sF:new O1;return v.build(d,e,r,1,i,a?0:u,s),{outline:v,newCurves:y,areContours:a,thickness:u,width:l,height:c}}static async compressSignature({outlines:t,areContours:e,thickness:r,width:i,height:s}){let A=1/0,a=-1/0,o=0;for(const b of t){o+=b.length;for(let C=2,x=b.length;C<x;C++){const F=b[C]-b[C-2];A=Math.min(A,F),a=Math.max(a,F)}}let l;A>=-128&&a<=127?l=Int8Array:A>=-32768&&a<=32767?l=Int16Array:l=Int32Array;const c=t.length,u=Rw+I0*c,d=new Uint32Array(u);let f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(o-2*c)*l.BYTES_PER_ELEMENT,d[f++]=0,d[f++]=i,d[f++]=s,d[f++]=e?0:1,d[f++]=Math.max(0,Math.floor(r??0)),d[f++]=c,d[f++]=l.BYTES_PER_ELEMENT;for(const b of t)d[f++]=b.length-2,d[f++]=b[0],d[f++]=b[1];const m=new CompressionStream("deflate-raw"),p=m.writable.getWriter();await p.ready,p.write(d);const y=l.prototype.constructor;for(const b of t){const C=new y(b.length-2);for(let x=2,F=b.length;x<F;x++)C[x-2]=b[x]-b[x-2];p.write(C)}return p.close(),(await new Response(m.readable).bytes()).toBase64()}static async decompressSignature(t){try{const e=Uint8Array.fromBase64(t),{readable:r,writable:i}=new DecompressionStream("deflate-raw"),s=i.getWriter();await s.ready,s.write(e).then(async()=>{await s.ready,await s.close()}).catch(()=>{});let A=null,a=0;for await(const C of r)A||(A=new Uint8Array(new Uint32Array(C.buffer,0,4)[0])),A.set(C,a),a+=C.length;const o=new Uint32Array(A.buffer,0,A.length>>2),l=o[1];if(l!==0)throw new Error(`Invalid version: ${l}`);const c=o[2],u=o[3],d=o[4]===0,f=o[5],m=o[6],p=o[7],y=[],v=(Rw+I0*m)*Uint32Array.BYTES_PER_ELEMENT;let b;switch(p){case Int8Array.BYTES_PER_ELEMENT:b=new Int8Array(A.buffer,v);break;case Int16Array.BYTES_PER_ELEMENT:b=new Int16Array(A.buffer,v);break;case Int32Array.BYTES_PER_ELEMENT:b=new Int32Array(A.buffer,v);break}a=0;for(let C=0;C<m;C++){const x=o[I0*C+Rw],F=new Float32Array(x+2);y.push(F);for(let I=0;I<I0-1;I++)F[I]=o[I0*C+Rw+I+1];for(let I=0;I<x;I++)F[I+2]=F[I]+b[a++]}return{areContours:d,thickness:f,outlines:y,width:c,height:u}}catch(e){return Me(`decompressSignature: ${e}`),null}}}Xf=new WeakMap,fr=new WeakSet,AF=function(t,e,r,i){return r-=t,i-=e,r===0?i>0?0:4:r===1?i+6:2-i},La=new WeakMap,Sk=function(t,e,r,i,s,A,a){const o=P(this,fr,AF).call(this,r,i,s,A);for(let l=0;l<8;l++){const c=(-l+o-a+16)%8,u=h(this,La)[2*c],d=h(this,La)[2*c+1];if(t[(r+u)*e+(i+d)]!==0)return c}return-1},Fk=function(t,e,r,i,s,A,a){const o=P(this,fr,AF).call(this,r,i,s,A);for(let l=0;l<8;l++){const c=(l+o+a+16)%8,u=h(this,La)[2*c],d=h(this,La)[2*c+1];if(t[(r+u)*e+(i+d)]!==0)return c}return-1},aF=function(t,e,r,i){const s=t.length,A=new Int32Array(s);for(let c=0;c<s;c++)A[c]=t[c]<=i?1:0;for(let c=1;c<r-1;c++)A[c*e]=A[c*e+e-1]=0;for(let c=0;c<e;c++)A[c]=A[e*r-1-c]=0;let a=1,o;const l=[];for(let c=1;c<r-1;c++){o=1;for(let u=1;u<e-1;u++){const d=c*e+u,f=A[d];if(f===0)continue;let m=c,p=u;if(f===1&&A[d-1]===0)a+=1,p-=1;else if(f>=1&&A[d+1]===0)a+=1,p+=1,f>1&&(o=f);else{f!==1&&(o=Math.abs(f));continue}const y=[u,c],v=p===u+1,b={isHole:v,points:y,id:a,parent:0};l.push(b);let C;for(const U of l)if(U.id===o){C=U;break}C?C.isHole?b.parent=v?C.parent:o:b.parent=v?o:C.parent:b.parent=v?o:0;const x=P(this,fr,Sk).call(this,A,e,c,u,m,p,0);if(x===-1){A[d]=-a,A[d]!==1&&(o=Math.abs(A[d]));continue}let F=h(this,La)[2*x],I=h(this,La)[2*x+1];const Q=c+F,R=u+I;m=Q,p=R;let L=c,j=u;for(;;){const U=P(this,fr,Fk).call(this,A,e,L,j,m,p,1);F=h(this,La)[2*U],I=h(this,La)[2*U+1];const k=L+F,G=j+I;y.push(G,k);const D=L*e+j;if(A[D+1]===0?A[D]=-a:A[D]===1&&(A[D]=a),k===c&&G===u&&L===Q&&j===R){A[d]!==1&&(o=Math.abs(A[d]));break}else m=L,p=j,L=k,j=G}}}return l},$y=function(t,e,r,i){if(r-e<=4){for(let Q=e;Q<r-2;Q+=2)i.push(t[Q],t[Q+1]);return}const s=t[e],A=t[e+1],a=t[r-4]-s,o=t[r-3]-A,l=Math.hypot(a,o),c=a/l,u=o/l,d=c*A-u*s,f=o/a,m=1/l,p=Math.atan(f),y=Math.cos(p),v=Math.sin(p),b=m*(Math.abs(y)+Math.abs(v)),C=m*(1-b+b**2),x=Math.max(Math.atan(Math.abs(v+y)*C),Math.atan(Math.abs(v-y)*C));let F=0,I=e;for(let Q=e+2;Q<r-2;Q+=2){const R=Math.abs(d-c*t[Q+1]+u*t[Q]);R>F&&(I=Q,F=R)}F>(l*x)**2?(P(this,fr,$y).call(this,t,e,I+2,i),P(this,fr,$y).call(this,t,I,r,i)):i.push(s,A)},_k=function(t){const e=[],r=t.length;return P(this,fr,$y).call(this,t,0,r,e),e.push(t[r-2],t[r-1]),e.length<=4?null:e},Tk=function(t,e,r,i,s,A){const a=new Float32Array(A**2),o=-2*i**2,l=A>>1;for(let p=0;p<A;p++){const y=(p-l)**2;for(let v=0;v<A;v++)a[p*A+v]=Math.exp((y+(v-l)**2)/o)}const c=new Float32Array(256),u=-2*s**2;for(let p=0;p<256;p++)c[p]=Math.exp(p**2/u);const d=t.length,f=new Uint8Array(d),m=new Uint32Array(256);for(let p=0;p<r;p++)for(let y=0;y<e;y++){const v=p*e+y,b=t[v];let C=0,x=0;for(let I=0;I<A;I++){const Q=p+I-l;if(!(Q<0||Q>=r))for(let R=0;R<A;R++){const L=y+R-l;if(L<0||L>=e)continue;const j=t[Q*e+L],U=a[I*A+R]*c[Math.abs(j-b)];C+=j*U,x+=U}}const F=f[v]=Math.round(C/x);m[F]++}return[f,m]},Ik=function(t){const e=new Uint32Array(256);for(const r of t)e[r]++;return e},oF=function(t){const e=t.length,r=new Uint8ClampedArray(e>>2);let i=-1/0,s=1/0;for(let a=0,o=r.length;a<o;a++){const l=r[a]=t[a<<2];i=Math.max(i,l),s=Math.min(s,l)}const A=255/(i-s);for(let a=0,o=r.length;a<o;a++)r[a]=(r[a]-s)*A;return r},lF=function(t){let e,r=-1/0,i=-1/0;const s=t.findIndex(o=>o!==0);let A=s,a=s;for(e=s;e<256;e++){const o=t[e];o>r&&(e-A>i&&(i=e-A,a=e-1),r=o,A=e)}for(e=a-1;e>=0&&!(t[e]>t[e+1]);e--);return e},Uk=function(t){const e=t,{width:r,height:i}=t,{maxDim:s}=h(this,Xf);let A=r,a=i;if(r>s||i>s){let d=r,f=i,m=Math.log2(Math.max(r,i)/s);const p=Math.floor(m);m=m===p?p-1:p;for(let v=0;v<m;v++){A=Math.ceil(d/2),a=Math.ceil(f/2);const b=new OffscreenCanvas(A,a);b.getContext("2d").drawImage(t,0,0,d,f,0,0,A,a),d=A,f=a,t!==e&&t.close(),t=b.transferToImageBitmap()}const y=Math.min(s/A,s/a);A=Math.round(A*y),a=Math.round(a*y)}const l=new OffscreenCanvas(A,a).getContext("2d",{willReadFrequently:!0});l.fillStyle="white",l.fillRect(0,0,A,a),l.filter="grayscale(1)",l.drawImage(t,0,0,t.width,t.height,0,0,A,a);const c=l.getImageData(0,0,A,a).data;return[P(this,fr,oF).call(this,c),A,a]},T(No,fr),T(No,Xf,{maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16}),T(No,La,new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]));class C4 extends yk{constructor(){super(),super.updateProperties({fill:Rr._defaultLineColor,"stroke-width":0})}clone(){const t=new C4;return t.updateAll(this),t}}class x4 extends Ib{constructor(t){super(t),super.updateProperties({stroke:Rr._defaultLineColor,"stroke-width":1})}clone(){const t=new x4(this._viewParameters);return t.updateAll(this),t}}var Sh,_o,Fh,Yf;const aA=class aA extends b2{constructor(e){super({...e,mustBeCommitted:!0,name:"signatureEditor"});T(this,Sh,!1);T(this,_o,null);T(this,Fh,null);T(this,Yf,null);this._willKeepAspectRatio=!0,E(this,Fh,e.signatureData||null),E(this,_o,null),this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(e,r){Rr.initialize(e,r),this._defaultDrawingOptions=new C4,this._defaultDrawnSignatureOptions=new x4(r.viewParameters)}static getDefaultDrawingOptions(e){const r=this._defaultDrawingOptions.clone();return r.updateProperties(e),r}static get supportMultipleDrawings(){return!1}static get typesMap(){return Te(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!h(this,_o)}}static computeTelemetryFinalData(e){const r=e.get("hasDescription");return{hasAltText:r.get(!0)??0,hasNoAltText:r.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,r;const{_isCopy:i}=this;if(i&&(this._isCopy=!1,e=this.x,r=this.y),super.render(),this._drawId===null)if(h(this,Fh)){const{lines:s,mustSmooth:A,areContours:a,description:o,uuid:l,heightInPage:c}=h(this,Fh),{rawDims:{pageWidth:u,pageHeight:d},rotation:f}=this.parent.viewport,m=No.processDrawnLines({lines:s,pageWidth:u,pageHeight:d,rotation:f,innerMargin:aA._INNER_MARGIN,mustSmooth:A,areContours:a});this.addSignature(m,c,o,l)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:h(this,_o)||""}));return i&&(this._isCopy=!0,this._moveAfterPaste(e,r)),this.div}setUuid(e){E(this,Yf,e),this.addEditToolbar()}getUuid(){return h(this,Yf)}get description(){return h(this,_o)}set description(e){E(this,_o,e),this.div&&(this.div.setAttribute("data-l10n-args",JSON.stringify({description:e})),super.addEditToolbar().then(r=>{r==null||r.updateEditSignatureButton(e)}))}getSignaturePreview(){const{newCurves:e,areContours:r,thickness:i,width:s,height:A}=h(this,Fh),a=Math.max(s,A),o=No.processDrawnLines({lines:{curves:e.map(l=>({points:l})),thickness:i,width:s,height:A},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:r});return{areContours:r,outline:o.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,r,i,s){const{x:A,y:a}=this,{outline:o}=E(this,Fh,e);E(this,Sh,o instanceof sF),this.description=i;let l;h(this,Sh)?l=aA.getDefaultDrawingOptions():(l=aA._defaultDrawnSignatureOptions.clone(),l.updateProperties({"stroke-width":o.thickness})),this._addOutlines({drawOutlines:o,drawingOptions:l});const[,c]=this.pageDimensions;let u=r/c;u=u>=1?.5:u,this.width*=u/this.height,this.width>=1&&(u*=.9/this.width,this.width=.9),this.height=u,this.setDims(),this.x=A,this.y=a,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(s),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!s,hasDescription:!!i}}),this.div.hidden=!1}getFromImage(e){const{rawDims:{pageWidth:r,pageHeight:i},rotation:s}=this.parent.viewport;return No.process(e,r,i,s,aA._INNER_MARGIN)}getFromText(e,r){const{rawDims:{pageWidth:i,pageHeight:s},rotation:A}=this.parent.viewport;return No.extractContoursFromText(e,r,i,s,A,aA._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:r,pageHeight:i},rotation:s}=this.parent.viewport;return No.processDrawnLines({lines:e,pageWidth:r,pageHeight:i,rotation:s,innerMargin:aA._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:r}){e?this._drawingOptions=aA.getDefaultDrawingOptions():(this._drawingOptions=aA._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":r}))}serialize(e=!1){if(this.isEmpty())return null;const{lines:r,points:i}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":s}}=this,A=Object.assign(super.serialize(e),{isSignature:!0,areContours:h(this,Sh),color:[0,0,0],thickness:h(this,Sh)?0:s});return this.addComment(A),e?(A.paths={lines:r,points:i},A.uuid=h(this,Yf),A.isCopy=!0):A.lines=r,h(this,_o)&&(A.accessibilityData={type:"Figure",alt:h(this,_o)}),A}static deserializeDraw(e,r,i,s,A,a){return a.areContours?sF.deserialize(e,r,i,s,A,a):O1.deserialize(e,r,i,s,A,a)}static async deserialize(e,r,i){var A;const s=await super.deserialize(e,r,i);return E(s,Sh,e.areContours),s.description=((A=e.accessibilityData)==null?void 0:A.alt)||"",E(s,Yf,e.uuid),s}};Sh=new WeakMap,_o=new WeakMap,Fh=new WeakMap,Yf=new WeakMap,ht(aA,"_type","signature"),ht(aA,"_editorType",Fe.SIGNATURE),ht(aA,"_defaultDrawingOptions",null);let cF=aA;var Jr,pn,_h,ql,Th,Rp,Wl,$f,To,xA,Dp,nr,Am,am,Jy,Zy,t2,uF,e2,Lk;class hF extends Rr{constructor(e){super({...e,name:"stampEditor"});T(this,nr);T(this,Jr,null);T(this,pn,null);T(this,_h,null);T(this,ql,null);T(this,Th,null);T(this,Rp,"");T(this,Wl,null);T(this,$f,!1);T(this,To,null);T(this,xA,!1);T(this,Dp,!1);E(this,ql,e.bitmapUrl),E(this,Th,e.bitmapFile),this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(e,r){Rr.initialize(e,r)}static isHandlingMimeForPasting(e){return g2.includes(e)}static paste(e,r){r.pasteEditor({mode:Fe.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const r=e.get("hasAltText");return{hasAltText:r.get(!0)??0,hasNoAltText:r.get(!1)??0}}async mlGuessAltText(e=null,r=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:s,width:A,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await i.guess({name:"altText",request:{data:s,width:A,height:a,channels:s.length/(A*a)}});if(!o)throw new Error("No response from the AI service.");if(o.error)throw new Error("Error from the AI service.");if(o.cancel)return null;if(!o.output)throw new Error("No valid response from the AI service.");const l=o.output;return await this.setGuessedAltText(l),r&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var e;h(this,pn)&&(E(this,Jr,null),this._uiManager.imageManager.deleteId(h(this,pn)),(e=h(this,Wl))==null||e.remove(),E(this,Wl,null),h(this,To)&&(clearTimeout(h(this,To)),E(this,To,null))),super.remove()}rebuild(){if(!this.parent){h(this,pn)&&P(this,nr,Jy).call(this);return}super.rebuild(),this.div!==null&&(h(this,pn)&&h(this,Wl)===null&&P(this,nr,Jy).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(h(this,_h)||h(this,Jr)||h(this,ql)||h(this,Th)||h(this,pn)||h(this,$f))}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,r;return this._isCopy&&(e=this.x,r=this.y),super.render(),this.div.hidden=!0,this.createAltText(),h(this,$f)||(h(this,Jr)?P(this,nr,Zy).call(this):P(this,nr,Jy).call(this)),this._isCopy&&this._moveAfterPaste(e,r),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,r){const{id:i,bitmap:s}=this._uiManager.imageManager.getFromCanvas(e,r);r.remove(),i&&this._uiManager.imageManager.isValidId(i)&&(E(this,pn,i),s&&E(this,Jr,s),E(this,$f,!1),P(this,nr,Zy).call(this))}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;h(this,To)!==null&&clearTimeout(h(this,To)),E(this,To,setTimeout(()=>{E(this,To,null),P(this,nr,uF).call(this)},200))}copyCanvas(e,r,i=!1){e||(e=224);const{width:s,height:A}=h(this,Jr),a=new Da;let o=h(this,Jr),l=s,c=A,u=null;if(r){if(s>r||A>r){const Q=Math.min(r/s,r/A);l=Math.floor(s*Q),c=Math.floor(A*Q)}u=document.createElement("canvas");const f=u.width=Math.ceil(l*a.sx),m=u.height=Math.ceil(c*a.sy);h(this,xA)||(o=P(this,nr,t2).call(this,f,m));const p=u.getContext("2d");p.filter=this._uiManager.hcmFilter;let y="white",v="#cfcfd8";this._uiManager.hcmFilter!=="none"?v="black":OK.isDarkMode&&(y="#8f8f9d",v="#42414d");const b=15,C=b*a.sx,x=b*a.sy,F=new OffscreenCanvas(C*2,x*2),I=F.getContext("2d");I.fillStyle=y,I.fillRect(0,0,C*2,x*2),I.fillStyle=v,I.fillRect(0,0,C,x),I.fillRect(C,x,C,x),p.fillStyle=p.createPattern(F,"repeat"),p.fillRect(0,0,f,m),p.drawImage(o,0,0,o.width,o.height,0,0,f,m)}let d=null;if(i){let f,m;if(a.symmetric&&o.width<e&&o.height<e)f=o.width,m=o.height;else if(o=h(this,Jr),s>e||A>e){const v=Math.min(e/s,e/A);f=Math.floor(s*v),m=Math.floor(A*v),h(this,xA)||(o=P(this,nr,t2).call(this,f,m))}const y=new OffscreenCanvas(f,m).getContext("2d",{willReadFrequently:!0});y.drawImage(o,0,0,o.width,o.height,0,0,f,m),d={width:f,height:m,data:y.getImageData(0,0,f,m).data}}return{canvas:u,width:l,height:c,imageData:d}}static async deserialize(e,r,i){var y;let s=null,A=!1;if(e instanceof zO){const{data:{rect:v,rotation:b,id:C,structParent:x,popupRef:F,richText:I,contentsObj:Q,creationDate:R,modificationDate:L},container:j,parent:{page:{pageNumber:U}},canvas:k}=e;let G,D;k?(delete e.canvas,{id:G,bitmap:D}=i.imageManager.getFromCanvas(j.id,k),k.remove()):(A=!0,e._hasNoCanvas=!0);const rt=((y=await r._structTree.getAriaAttributes(`${cg}${C}`))==null?void 0:y.get("aria-label"))||"";s=e={annotationType:Fe.STAMP,bitmapId:G,bitmap:D,pageIndex:U-1,rect:v.slice(0),rotation:b,annotationElementId:C,id:C,deleted:!1,accessibilityData:{decorative:!1,altText:rt},isSvg:!1,structParent:x,popupRef:F,richText:I,comment:(Q==null?void 0:Q.str)||null,creationDate:R,modificationDate:L}}const a=await super.deserialize(e,r,i),{rect:o,bitmap:l,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;A?(i.addMissingCanvas(e.id,a),E(a,$f,!0)):u&&i.imageManager.isValidId(u)?(E(a,pn,u),l&&E(a,Jr,l)):E(a,ql,c),E(a,xA,d);const[m,p]=a.pageDimensions;return a.width=(o[2]-o[0])/m,a.height=(o[3]-o[1])/p,f&&(a.altTextData=f),a._initialData=s,e.comment&&a.setCommentData(e),E(a,Dp,!!s),a}serialize(e=!1,r=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i=Object.assign(super.serialize(e),{bitmapId:h(this,pn),isSvg:h(this,xA)});if(this.addComment(i),e)return i.bitmapUrl=P(this,nr,e2).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i.isCopy=!0,i;const{decorative:s,altText:A}=this.serializeAltText(!1);if(!s&&A&&(i.accessibilityData={type:"Figure",alt:A}),this.annotationElementId){const o=P(this,nr,Lk).call(this,i);return o.isSame?null:(o.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1,i.id=this.annotationElementId,delete i.bitmapId,i)}if(r===null)return i;r.stamps||(r.stamps=new Map);const a=h(this,xA)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!r.stamps.has(h(this,pn)))r.stamps.set(h(this,pn),{area:a,serialized:i}),i.bitmap=P(this,nr,e2).call(this,!1);else if(h(this,xA)){const o=r.stamps.get(h(this,pn));a>o.area&&(o.area=a,o.serialized.bitmap.close(),o.serialized.bitmap=P(this,nr,e2).call(this,!1))}return i}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}Jr=new WeakMap,pn=new WeakMap,_h=new WeakMap,ql=new WeakMap,Th=new WeakMap,Rp=new WeakMap,Wl=new WeakMap,$f=new WeakMap,To=new WeakMap,xA=new WeakMap,Dp=new WeakMap,nr=new WeakSet,Am=function(e,r=!1){if(!e){this.remove();return}E(this,Jr,e.bitmap),r||(E(this,pn,e.id),E(this,xA,e.isSvg)),e.file&&E(this,Rp,e.file.name),P(this,nr,Zy).call(this)},am=function(){if(E(this,_h,null),this._uiManager.enableWaiting(!1),!!h(this,Wl)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&h(this,Jr)){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&h(this,Jr)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Jy=function(){if(h(this,pn)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(h(this,pn)).then(i=>P(this,nr,Am).call(this,i,!0)).finally(()=>P(this,nr,am).call(this));return}if(h(this,ql)){const i=h(this,ql);E(this,ql,null),this._uiManager.enableWaiting(!0),E(this,_h,this._uiManager.imageManager.getFromUrl(i).then(s=>P(this,nr,Am).call(this,s)).finally(()=>P(this,nr,am).call(this)));return}if(h(this,Th)){const i=h(this,Th);E(this,Th,null),this._uiManager.enableWaiting(!0),E(this,_h,this._uiManager.imageManager.getFromFile(i).then(s=>P(this,nr,Am).call(this,s)).finally(()=>P(this,nr,am).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=g2.join(",");const r=this._uiManager._signal;E(this,_h,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const s=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),P(this,nr,Am).call(this,s)}i()},{signal:r}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:r})}).finally(()=>P(this,nr,am).call(this))),e.click()},Zy=function(){var l;const{div:e}=this;let{width:r,height:i}=h(this,Jr);const[s,A]=this.pageDimensions,a=.75;if(this.width)r=this.width*s,i=this.height*A;else if(r>a*s||i>a*A){const c=Math.min(a*s/r,a*A/i);r*=c,i*=c}this._uiManager.enableWaiting(!1);const o=E(this,Wl,document.createElement("canvas"));o.setAttribute("role","img"),this.addContainer(o),this.width=r/s,this.height=i/A,this.setDims(),(l=this._initialOptions)!=null&&l.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),P(this,nr,uF).call(this),h(this,Dp)||(this.parent.addUndoableEditor(this),E(this,Dp,!0)),this._reportTelemetry({action:"inserted_image"}),h(this,Rp)&&this.div.setAttribute("aria-description",h(this,Rp)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")},t2=function(e,r){const{width:i,height:s}=h(this,Jr);let A=i,a=s,o=h(this,Jr);for(;A>2*e||a>2*r;){const l=A,c=a;A>2*e&&(A=Math.ceil(A/2)),a>2*r&&(a=Math.ceil(a/2));const u=new OffscreenCanvas(A,a);u.getContext("2d").drawImage(o,0,0,l,c,0,0,A,a),o=u.transferToImageBitmap()}return o},uF=function(){const[e,r]=this.parentDimensions,{width:i,height:s}=this,A=new Da,a=Math.ceil(i*e*A.sx),o=Math.ceil(s*r*A.sy),l=h(this,Wl);if(!l||l.width===a&&l.height===o)return;l.width=a,l.height=o;const c=h(this,xA)?h(this,Jr):P(this,nr,t2).call(this,a,o),u=l.getContext("2d");u.filter=this._uiManager.hcmFilter,u.drawImage(c,0,0,c.width,c.height,0,0,a,o)},e2=function(e){if(e){if(h(this,xA)){const s=this._uiManager.imageManager.getSvgUrl(h(this,pn));if(s)return s}const r=document.createElement("canvas");return{width:r.width,height:r.height}=h(this,Jr),r.getContext("2d").drawImage(h(this,Jr),0,0),r.toDataURL()}if(h(this,xA)){const[r,i]=this.pageDimensions,s=Math.round(this.width*r*Ac.PDF_TO_CSS_UNITS),A=Math.round(this.height*i*Ac.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(s,A);return a.getContext("2d").drawImage(h(this,Jr),0,0,h(this,Jr).width,h(this,Jr).height,0,0,s,A),a.transferToImageBitmap()}return structuredClone(h(this,Jr))},Lk=function(e){var a;const{pageIndex:r,accessibilityData:{altText:i}}=this._initialData,s=e.pageIndex===r,A=(((a=e.accessibilityData)==null?void 0:a.alt)||"")===i;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&s&&A,isSameAltText:A}},ht(hF,"_type","stamp"),ht(hF,"_editorType",Fe.STAMP);var Jf,Hp,Ih,Uh,zl,Gs,Lh,Kp,Gp,Pa,Xl,mn,Yl,Ph,jp,le,Nh,Ur,fF,Pk,ao,dF,gF,r2;const ya=class ya{constructor({uiManager:t,pageIndex:e,div:r,structTreeLayer:i,accessibilityManager:s,annotationLayer:A,drawLayer:a,textLayer:o,viewport:l,l10n:c}){T(this,Ur);T(this,Jf);T(this,Hp,!1);T(this,Ih,null);T(this,Uh,null);T(this,zl,null);T(this,Gs,new Map);T(this,Lh,!1);T(this,Kp,!1);T(this,Gp,!1);T(this,Pa,null);T(this,Xl,null);T(this,mn,null);T(this,Yl,null);T(this,Ph,null);T(this,jp,-1);T(this,le);const u=[...h(ya,Nh).values()];if(!ya._initialized){ya._initialized=!0;for(const d of u)d.initialize(c,t)}t.registerEditorTypes(u),E(this,le,t),this.pageIndex=e,this.div=r,E(this,Jf,s),E(this,Ih,A),this.viewport=l,E(this,mn,o),this.drawLayer=a,this._structTree=i,h(this,le).addLayer(this)}get isEmpty(){return h(this,Gs).size===0}get isInvisible(){return this.isEmpty&&h(this,le).getMode()===Fe.NONE}updateToolbar(t){h(this,le).updateToolbar(t)}updateMode(t=h(this,le).getMode()){switch(P(this,Ur,r2).call(this),t){case Fe.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Fe.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Fe.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;if(e.toggle("nonEditing",!1),t===Fe.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(const r of h(ya,Nh).values())e.toggle(`${r._type}Editing`,t===r._editorType)}this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=h(this,mn))==null?void 0:e.div)}setEditingState(t){h(this,le).setEditingState(t)}addCommands(t){h(this,le).addCommands(t)}cleanUndoStack(t){h(this,le).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=h(this,Ih))==null||e.togglePointerEvents(t)}async enable(){var r;E(this,Gp,!0),this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),(r=h(this,Ph))==null||r.abort(),E(this,Ph,null);const t=new Set;for(const i of h(this,Ur,fF))i.enableEditing(),i.show(!0),i.annotationElementId&&(h(this,le).removeChangedExistingAnnotation(i),t.add(i.annotationElementId));const e=h(this,Ih);if(e)for(const i of e.getEditableAnnotations()){if(i.hide(),h(this,le).isDeletedAnnotationElement(i.data.id)||t.has(i.data.id))continue;const s=await this.deserialize(i);s&&(this.addOrRebuild(s),s.enableEditing())}E(this,Gp,!1),h(this,le)._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){var i;if(E(this,Kp,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),h(this,mn)&&!h(this,Ph)){E(this,Ph,new AbortController);const s=h(this,le).combinedSignal(h(this,Ph));h(this,mn).div.addEventListener("pointerdown",A=>{const{clientX:o,clientY:l,timeStamp:c}=A,u=h(this,jp);if(c-u>500){E(this,jp,c);return}E(this,jp,-1);const{classList:d}=this.div;d.toggle("getElements",!0);const f=document.elementsFromPoint(o,l);if(d.toggle("getElements",!1),!this.div.contains(f[0]))return;let m;const p=new RegExp(`^${Um}[0-9]+$`);for(const v of f)if(p.test(v.id)){m=v.id;break}if(!m)return;const y=h(this,Gs).get(m);(y==null?void 0:y.annotationElementId)===null&&(Zr(A),y.dblclick(A))},{signal:s,capture:!0})}const t=h(this,Ih),e=[];if(t){const s=new Map,A=new Map;for(const a of h(this,Ur,fF)){if(a.disableEditing(),!a.annotationElementId){e.push(a);continue}if(a.serialize()!==null){s.set(a.annotationElementId,a);continue}else A.set(a.annotationElementId,a);(i=this.getEditableAnnotation(a.annotationElementId))==null||i.show(),a.remove()}for(const a of t.getEditableAnnotations()){const{id:o}=a.data;if(h(this,le).isDeletedAnnotationElement(o)){a.updateEdited({deleted:!0});continue}let l=A.get(o);if(l){l.resetAnnotationElement(a),l.show(!1),a.show();continue}l=s.get(o),l&&(h(this,le).addChangedExistingAnnotation(l),l.renderAnnotationElement(a)&&l.show(!1)),a.show()}}P(this,Ur,r2).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:r}=this.div;for(const s of h(ya,Nh).values())r.remove(`${s._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),t==null||t.updateFakeAnnotations(e),E(this,Kp,!1)}getEditableAnnotation(t){var e;return((e=h(this,Ih))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){h(this,le).getActive()!==t&&h(this,le).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=h(this,mn))!=null&&t.div&&!h(this,Yl)){E(this,Yl,new AbortController);const e=h(this,le).combinedSignal(h(this,Yl));h(this,mn).div.addEventListener("pointerdown",P(this,Ur,Pk).bind(this),{signal:e}),h(this,mn).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=h(this,mn))!=null&&t.div&&h(this,Yl)&&(h(this,Yl).abort(),E(this,Yl,null),h(this,mn).div.classList.remove("highlighting"))}enableClick(){if(h(this,Uh))return;E(this,Uh,new AbortController);const t=h(this,le).combinedSignal(h(this,Uh));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=h(this,Uh))==null||t.abort(),E(this,Uh,null)}attach(t){h(this,Gs).set(t.id,t);const{annotationElementId:e}=t;e&&h(this,le).isDeletedAnnotationElement(e)&&h(this,le).removeDeletedAnnotationElement(t)}detach(t){var e;h(this,Gs).delete(t.id),(e=h(this,Jf))==null||e.removePointerInTextLayer(t.contentDiv),!h(this,Kp)&&t.annotationElementId&&h(this,le).addDeletedAnnotationElement(t)}remove(t){this.detach(t),h(this,le).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(h(this,le).addDeletedAnnotationElement(t),Rr.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),h(this,le).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!h(this,Gp)),h(this,le).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var r;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!h(this,zl)&&(t._focusEventsAllowed=!1,E(this,zl,setTimeout(()=>{E(this,zl,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:h(this,le)._signal}),e.focus())},0))),t._structTreeParentId=(r=h(this,Jf))==null?void 0:r.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),r=()=>{t.remove()};this.addCommands({cmd:e,undo:r,mustExec:!1})}getEditorByUID(t){for(const e of h(this,Gs).values())if(e.uid===t)return e;return null}combinedSignal(t){return h(this,le).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=h(this,Ur,ao))==null?void 0:t.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await h(this,le).updateMode(t.mode);const{offsetX:r,offsetY:i}=P(this,Ur,gF).call(this),s=h(this,le).getId(),A=P(this,Ur,dF).call(this,{parent:this,id:s,x:r,y:i,uiManager:h(this,le),isCentered:!0,...e});A&&this.add(A)}async deserialize(t){var e;return await((e=h(ya,Nh).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,h(this,le)))||null}createAndAddNewEditor(t,e,r={}){const i=h(this,le).getId(),s=P(this,Ur,dF).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:h(this,le),isCentered:e,...r});return s&&this.add(s),s}get boundingClientRect(){return this.div.getBoundingClientRect()}addNewEditor(t={}){this.createAndAddNewEditor(P(this,Ur,gF).call(this),!0,t)}setSelected(t){h(this,le).setSelected(t)}toggleSelected(t){h(this,le).toggleSelected(t)}unselect(t){h(this,le).unselect(t)}pointerup(t){var i;const{isMac:e}=Qi.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div||!h(this,Lh)||(E(this,Lh,!1),(i=h(this,Ur,ao))!=null&&i.isDrawer&&h(this,Ur,ao).supportMultipleDrawings))return;if(!h(this,Hp)){E(this,Hp,!0);return}const r=h(this,le).getMode();if(r===Fe.STAMP||r===Fe.POPUP||r===Fe.SIGNATURE){h(this,le).unselectAll();return}this.createAndAddNewEditor(t,!1)}pointerdown(t){var i;if(h(this,le).getMode()===Fe.HIGHLIGHT&&this.enableTextSelection(),h(this,Lh)){E(this,Lh,!1);return}const{isMac:e}=Qi.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(E(this,Lh,!0),(i=h(this,Ur,ao))!=null&&i.isDrawer){this.startDrawingSession(t);return}const r=h(this,le).getActive();E(this,Hp,!r||r.isEmpty())}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),h(this,Pa)){h(this,Ur,ao).startDrawing(this,h(this,le),!1,t);return}h(this,le).setCurrentDrawingSession(this),E(this,Pa,new AbortController);const e=h(this,le).combinedSignal(h(this,Pa));this.div.addEventListener("blur",({relatedTarget:r})=>{r&&!this.div.contains(r)&&(E(this,Xl,null),this.commitOrRemove())},{signal:e}),h(this,Ur,ao).startDrawing(this,h(this,le),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&E(this,Xl,e);return}h(this,Xl)&&setTimeout(()=>{var e;(e=h(this,Xl))==null||e.focus(),E(this,Xl,null)},0)}endDrawingSession(t=!1){return h(this,Pa)?(h(this,le).setCurrentDrawingSession(null),h(this,Pa).abort(),E(this,Pa,null),E(this,Xl,null),h(this,Ur,ao).endDrawing(t)):null}findNewParent(t,e,r){const i=h(this,le).findParent(e,r);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return h(this,Pa)?(this.endDrawingSession(),!0):!1}onScaleChanging(){h(this,Pa)&&h(this,Ur,ao).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=h(this,le).getActive())==null?void 0:t.parent)===this&&(h(this,le).commitOrRemove(),h(this,le).setActiveEditor(null)),h(this,zl)&&(clearTimeout(h(this,zl)),E(this,zl,null));for(const r of h(this,Gs).values())(e=h(this,Jf))==null||e.removePointerInTextLayer(r.contentDiv),r.setParent(null),r.isAttachedToDOM=!1,r.div.remove();this.div=null,h(this,Gs).clear(),h(this,le).removeLayer(this)}async render({viewport:t}){this.viewport=t,Gh(this.div,t);for(const e of h(this,le).getEditors(this.pageIndex))this.add(e),e.rebuild();await h(this,le).findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:t}){h(this,le).commitOrRemove(),P(this,Ur,r2).call(this);const e=this.viewport.rotation,r=t.rotation;if(this.viewport=t,Gh(this.div,{rotation:r}),e!==r)for(const i of h(this,Gs).values())i.rotate(r)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return h(this,le).viewParameters.realScale}};Jf=new WeakMap,Hp=new WeakMap,Ih=new WeakMap,Uh=new WeakMap,zl=new WeakMap,Gs=new WeakMap,Lh=new WeakMap,Kp=new WeakMap,Gp=new WeakMap,Pa=new WeakMap,Xl=new WeakMap,mn=new WeakMap,Yl=new WeakMap,Ph=new WeakMap,jp=new WeakMap,le=new WeakMap,Nh=new WeakMap,Ur=new WeakSet,fF=function(){return h(this,Gs).size!==0?h(this,Gs).values():h(this,le).getEditors(this.pageIndex)},Pk=function(t){h(this,le).unselectAll();const{target:e}=t;if(e===h(this,mn).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent")||e.classList.contains("textLayerImagePlaceholder"))&&h(this,mn).div.contains(e)){const{isMac:r}=Qi.platform;if(t.button!==0||t.ctrlKey&&r)return;h(this,le).showAllEditors("highlight",!0,!0),h(this,mn).div.classList.add("free"),this.toggleDrawing(),y2.startHighlighting(this,h(this,le).direction==="ltr",{target:h(this,mn).div,x:t.x,y:t.y}),h(this,mn).div.addEventListener("pointerup",()=>{h(this,mn).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:h(this,le)._signal}),t.preventDefault()}},ao=function(){return h(ya,Nh).get(h(this,le).getMode())},dF=function(t){const e=h(this,Ur,ao);return e?new e.prototype.constructor(t):null},gF=function(){const{x:t,y:e,width:r,height:i}=this.boundingClientRect,s=Math.max(0,t),A=Math.max(0,e),a=Math.min(window.innerWidth,t+r),o=Math.min(window.innerHeight,e+i),l=(s+a)/2-t,c=(A+o)/2-e,[u,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:u,offsetY:d}},r2=function(){for(const t of h(this,Gs).values())t.isEmpty()&&t.remove()},ht(ya,"_initialized",!1),T(ya,Nh,new Map([zS,nF,hF,y2,cF].map(t=>[t._editorType,t])));let B2=ya;var Na,xs,Zf,C1,Ab,Nk,Oo,pF,Qk,mF;const en=class en{constructor(){T(this,Oo);T(this,Na,null);T(this,xs,new Map);T(this,Zf,new Map)}setParent(t){if(!h(this,Na)){E(this,Na,t);return}if(h(this,Na)!==t){if(h(this,xs).size>0)for(const e of h(this,xs).values())e.remove(),t.append(e);E(this,Na,t)}}static get _svgFactory(){return Te(this,"_svgFactory",new Rm)}draw(t,e=!1,r=!1){const i=Di(en,C1)._++,s=P(this,Oo,pF).call(this),A=en._svgFactory.createElement("defs");s.append(A);const a=en._svgFactory.createElement("path");A.append(a);const o=`path_${i}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&h(this,Zf).set(i,a);const l=r?P(this,Oo,Qk).call(this,A,o):null,c=en._svgFactory.createElement("use");return s.append(c),c.setAttribute("href",`#${o}`),this.updateProperties(s,t),h(this,xs).set(i,s),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){const r=Di(en,C1)._++,i=P(this,Oo,pF).call(this),s=en._svgFactory.createElement("defs");i.append(s);const A=en._svgFactory.createElement("path");s.append(A);const a=`path_${r}`;A.setAttribute("id",a),A.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){const u=en._svgFactory.createElement("mask");s.append(u),o=`mask_${r}`,u.setAttribute("id",o),u.setAttribute("maskUnits","objectBoundingBox");const d=en._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const f=en._svgFactory.createElement("use");u.append(f),f.setAttribute("href",`#${a}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const l=en._svgFactory.createElement("use");i.append(l),l.setAttribute("href",`#${a}`),o&&l.setAttribute("mask",`url(#${o})`);const c=l.cloneNode();return i.append(c),l.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),h(this,xs).set(r,i),r}finalizeDraw(t,e){h(this,Zf).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var o;if(!e)return;const{root:r,bbox:i,rootClass:s,path:A}=e,a=typeof t=="number"?h(this,xs).get(t):t;if(a){if(r&&P(this,Oo,mF).call(this,a,r),i&&P(o=en,Ab,Nk).call(o,a,i),s){const{classList:l}=a;for(const[c,u]of Object.entries(s))l.toggle(c,u)}if(A){const c=a.firstElementChild.firstElementChild;P(this,Oo,mF).call(this,c,A)}}}updateParent(t,e){if(e===this)return;const r=h(this,xs).get(t);r&&(h(e,Na).append(r),h(this,xs).delete(t),h(e,xs).set(t,r))}remove(t){h(this,Zf).delete(t),h(this,Na)!==null&&(h(this,xs).get(t).remove(),h(this,xs).delete(t))}destroy(){E(this,Na,null);for(const t of h(this,xs).values())t.remove();h(this,xs).clear(),h(this,Zf).clear()}};Na=new WeakMap,xs=new WeakMap,Zf=new WeakMap,C1=new WeakMap,Ab=new WeakSet,Nk=function(t,[e,r,i,s]){const{style:A}=t;A.top=`${100*r}%`,A.left=`${100*e}%`,A.width=`${100*i}%`,A.height=`${100*s}%`},Oo=new WeakSet,pF=function(){const t=en._svgFactory.create(1,1,!0);return h(this,Na).append(t),t.setAttribute("aria-hidden",!0),t},Qk=function(t,e){const r=en._svgFactory.createElement("clipPath");t.append(r);const i=`clip_${e}`;r.setAttribute("id",i),r.setAttribute("clipPathUnits","objectBoundingBox");const s=en._svgFactory.createElement("use");return r.append(s),s.setAttribute("href",`#${e}`),s.classList.add("clip"),i},mF=function(t,e){for(const[r,i]of Object.entries(e))i===null?t.removeAttribute(r):t.setAttribute(r,i)},T(en,Ab),T(en,C1,0);let C2=en;function Dw(n){return`${(n*100).toFixed(2)}%`}var Vp,x1,E1,qp,Io,Uo,S1,ab,Mk;const Fm=class Fm{constructor(t,e,r,i){T(this,ab);T(this,Vp,[]);T(this,x1,new Map);T(this,E1,null);T(this,qp,0);T(this,Io,0);T(this,Uo,0);E(this,qp,t),E(this,Vp,e),E(this,Io,r.rawDims.pageWidth),E(this,Uo,r.rawDims.pageHeight),E(this,E1,i)}render(){const t=document.createElement("div");t.className="textLayerImages";for(let e=0;e<h(this,Vp).length;e+=6){const r=P(this,ab,Mk).call(this,h(this,Vp).subarray(e,e+6));r&&t.append(r)}return t.addEventListener("contextmenu",e=>{var v;if(!(e.target instanceof HTMLCanvasElement))return;const r=e.target,i=h(this,x1).get(r);if(!i)return;const s=(v=h(Fm,S1))==null?void 0:v.deref();if(s===r)return;s&&(s.width=0,s.height=0),E(Fm,S1,new WeakRef(r));const{inverseTransform:A,x1:a,y1:o,width:l,height:c}=i,u=h(this,E1).call(this),d=Math.ceil(a*u.width),f=Math.ceil(o*u.height),m=Math.floor((a+l/h(this,Io))*u.width),p=Math.floor((o+c/h(this,Uo))*u.height);r.width=m-d,r.height=p-f;const y=r.getContext("2d");y.setTransform(...A),y.translate(-d,-f),y.drawImage(u,0,0)}),t}};Vp=new WeakMap,x1=new WeakMap,E1=new WeakMap,qp=new WeakMap,Io=new WeakMap,Uo=new WeakMap,S1=new WeakMap,ab=new WeakSet,Mk=function([t,e,r,i,s,A]){const a=Math.hypot((s-t)*h(this,Io),(A-e)*h(this,Uo)),o=Math.hypot((r-t)*h(this,Io),(i-e)*h(this,Uo));if(a<h(this,qp)||o<h(this,qp))return null;const l=[(s-t)*h(this,Io)/a,(A-e)*h(this,Uo)/a,(r-t)*h(this,Io)/o,(i-e)*h(this,Uo)/o,0,0],c=Mt.inverseTransform(l),u=document.createElement("canvas");return u.className="textLayerImagePlaceholder",u.width=0,u.height=0,Object.assign(u.style,{opacity:0,position:"absolute",left:Dw(t),top:Dw(e),width:Dw(a/h(this,Io)),height:Dw(o/h(this,Uo)),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`}),h(this,x1).set(u,{inverseTransform:c,width:a,height:o,x1:t,y1:e}),u},T(Fm,S1,null);let x2=Fm;globalThis._pdfjsTestingUtils={HighlightOutliner:YS};globalThis.pdfjsLib={AbortException:sc,AnnotationEditorLayer:B2,AnnotationEditorParamsType:Qe,AnnotationEditorType:Fe,AnnotationEditorUIManager:jh,AnnotationLayer:v2,AnnotationMode:$l,AnnotationType:Si,applyOpacity:vM,build:MO,ColorPicker:km,createValidAbsoluteUrl:u4,CSSConstants:mM,DOMSVGFactory:Rm,DrawLayer:C2,FeatureTest:Qi,fetchData:vb,findContrastColor:wM,getDocument:w4,getFilenameFromUrl:dM,getPdfFilenameFromUrl:gM,getRGB:t0,getRGBA:bb,getUuid:d4,getXfaPageViewport:pM,GlobalWorkerOptions:Ma,ImageKind:vm,InvalidPDFException:f2,isDataScheme:Q1,isPdfFile:yb,isValidExplicitDest:iO,makeArr:pb,makeMap:mb,makeObj:d2,MathClamp:Wr,noContextMenu:UA,normalizeUnicode:fM,OPS:Po,OutputScale:Da,PasswordResponses:uM,PDFDataRangeTransport:y4,PDFDateString:Nm,PDFWorker:Yp,PermissionFlag:hM,PixelsPerInch:Ac,RenderingCancelledException:wb,renderRichText:p4,ResponseException:Lm,setLayerDimensions:Gh,shadow:Te,SignatureExtractor:No,stopEvent:Zr,SupportedImageMimeTypes:g2,TextLayer:Xp,TextLayerImages:x2,TouchManager:Qm,updateUrlHash:f4,Util:Mt,VerbosityLevel:P1,version:QO,XfaLayer:g4};const vj=Object.freeze(Object.defineProperty({__proto__:null,AbortException:sc,AnnotationEditorLayer:B2,AnnotationEditorParamsType:Qe,AnnotationEditorType:Fe,AnnotationEditorUIManager:jh,AnnotationLayer:v2,AnnotationMode:$l,AnnotationType:Si,CSSConstants:mM,ColorPicker:km,DOMSVGFactory:Rm,DrawLayer:C2,FeatureTest:Qi,GlobalWorkerOptions:Ma,ImageKind:vm,InvalidPDFException:f2,MathClamp:Wr,OPS:Po,OutputScale:Da,PDFDataRangeTransport:y4,PDFDateString:Nm,PDFWorker:Yp,PasswordResponses:uM,PermissionFlag:hM,PixelsPerInch:Ac,RenderingCancelledException:wb,ResponseException:Lm,SignatureExtractor:No,SupportedImageMimeTypes:g2,TextLayer:Xp,TextLayerImages:x2,TouchManager:Qm,Util:Mt,VerbosityLevel:P1,XfaLayer:g4,applyOpacity:vM,build:MO,createValidAbsoluteUrl:u4,fetchData:vb,findContrastColor:wM,getDocument:w4,getFilenameFromUrl:dM,getPdfFilenameFromUrl:gM,getRGB:t0,getRGBA:bb,getUuid:d4,getXfaPageViewport:pM,isDataScheme:Q1,isPdfFile:yb,isValidExplicitDest:iO,makeArr:pb,makeMap:mb,makeObj:d2,noContextMenu:UA,normalizeUnicode:fM,renderRichText:p4,setLayerDimensions:Gh,shadow:Te,stopEvent:Zr,updateUrlHash:f4,version:QO},Symbol.toStringTag,{value:"Module"}));Ma.workerSrc="";const rU=25.4/72,EC=8;class Ok{importFromFilePicker(t){const e=document.createElement("input");e.type="file",e.accept=".pdf",e.style.display="none",document.body.appendChild(e),e.addEventListener("change",async()=>{var s;const r=(s=e.files)==null?void 0:s[0];if(document.body.removeChild(e),!r)return;const i=await r.arrayBuffer();await this.convert(t,i)}),e.click()}async convert(t,e,r=1){try{const s=await(await w4({data:e}).promise).getPage(r),a=s.getViewport({scale:1}).height,o=await s.getOperatorList(),l=this.extractEntities(o,a);if(l.length===0){Ic.log.warn("[PdfImport] No vector paths found in PDF page.");return}const c=t.doc.database.tables.blockTable.modelSpace;for(const u of l)c.appendEntity(u);Ic.log.info(`[PdfImport] Imported ${l.length} entities from PDF.`)}catch(i){Ic.log.error("[PdfImport] Failed to import PDF:",i)}}extractEntities(t,e){const{OPS:r}=vj,{fnArray:i,argsArray:s}=t,A=[];let a=[],o=[],l=0,c=0;const u=()=>{o.length>1&&a.push(o),o=[]},d=()=>{u();for(const p of a){const y=this.subpathToEntity(p);y&&A.push(y)}a=[]},f=(p,y)=>p*rU,m=(p,y)=>(e-y)*rU;for(let p=0;p<i.length;p++){const y=i[p],v=s[p];switch(y){case r.moveTo:{u(),l=v[0],c=v[1],o=[{x:f(l),y:m(l,c)}];break}case r.lineTo:{l=v[0],c=v[1],o.push({x:f(l),y:m(l,c)});break}case r.curveTo:{const[b,C,x,F,I,Q]=v,R=SC({x:l,y:c},{x:b,y:C},{x,y:F},{x:I,y:Q},EC);for(const L of R)o.push({x:f(L.x,L.y),y:m(L.x,L.y)});l=I,c=Q;break}case r.curveTo2:{const[b,C,x,F]=v,I=SC({x:l,y:c},{x:l,y:c},{x:b,y:C},{x,y:F},EC);for(const Q of I)o.push({x:f(Q.x,Q.y),y:m(Q.x,Q.y)});l=x,c=F;break}case r.curveTo3:{const[b,C,x,F]=v,I=SC({x:l,y:c},{x:b,y:C},{x,y:F},{x,y:F},EC);for(const Q of I)o.push({x:f(Q.x,Q.y),y:m(Q.x,Q.y)});l=x,c=F;break}case r.closePath:{o.length>0&&a.length===0&&o.push({...o[0]}),u();break}case r.stroke:case r.fill:case r.eoFill:case r.fillStroke:case r.eoFillStroke:case r.endPath:{d();break}}}return d(),A}subpathToEntity(t){if(t.length<2)return null;if(t.length===2)return new Ic.AcDbLine(new Ic.AcGePoint3d(t[0].x,t[0].y,0),new Ic.AcGePoint3d(t[1].x,t[1].y,0));const e=new Ic.AcDbPolyline;for(let a=0;a<t.length;a++)e.addVertexAt(a,new Ic.AcGePoint2d(t[a].x,t[a].y));const r=t[0],i=t[t.length-1],s=r.x-i.x,A=r.y-i.y;return Math.sqrt(s*s+A*A)<1e-6&&(e.closed=!0),e}}function SC(n,t,e,r,i){const s=[];for(let A=1;A<=i;A++){const a=A/i,o=1-a,l=o*o*o*n.x+3*o*o*a*t.x+3*o*a*a*e.x+a*a*a*r.x,c=o*o*o*n.y+3*o*o*a*t.y+3*o*a*a*e.y+a*a*a*r.y;s.push({x:l,y:c})}return s}class kk extends _m.AcEdCommand{async execute(t){new Ok().importFromFilePicker(t)}}const wj="1.5.10",yj={version:wj};class bj{constructor(){this.name="PdfPlugin",this.version=yj.version,this.description="PDF export (cpdf) and import (ipdf) commands",this.registeredCommands=[]}onLoad(t,e){const r=_m.AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME;e.addCommand(r,"cpdf","cpdf",new cM),e.addCommand(r,"ipdf","ipdf",new kk),this.registeredCommands.push({group:r,name:"cpdf"},{group:r,name:"ipdf"})}onUnload(t,e){for(const r of this.registeredCommands)e.removeCmd(r.group,r.name);this.registeredCommands=[]}}async function Bj(){return new bj}/*!
|
|
273
273
|
* html2canvas 1.4.1 <https://html2canvas.hertzen.com>
|
|
274
274
|
* Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
|
|
275
275
|
* Released under MIT License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/cad-pdf-plugin",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -37,17 +37,17 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@mlightcad/data-model": "^1.
|
|
40
|
+
"@mlightcad/data-model": "^1.12.5",
|
|
41
41
|
"jspdf": "^4.2.1",
|
|
42
42
|
"pdfjs-dist": "^5.6.205",
|
|
43
43
|
"svg2pdf.js": "^2.7.0",
|
|
44
|
-
"@mlightcad/cad-
|
|
45
|
-
"@mlightcad/cad-
|
|
44
|
+
"@mlightcad/cad-svg-plugin": "1.5.10",
|
|
45
|
+
"@mlightcad/cad-simple-viewer": "1.5.10"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@mlightcad/data-model": "^1.
|
|
49
|
-
"@mlightcad/cad-simple-viewer": "1.5.
|
|
50
|
-
"@mlightcad/cad-svg-plugin": "1.5.
|
|
48
|
+
"@mlightcad/data-model": "^1.12.5",
|
|
49
|
+
"@mlightcad/cad-simple-viewer": "1.5.10",
|
|
50
|
+
"@mlightcad/cad-svg-plugin": "1.5.10"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|