darkfire514 commited on
Commit
9573928
·
verified ·
1 Parent(s): f8e7e6d

Delete ui/node_modules

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. ui/node_modules/.bin/marked +0 -17
  2. ui/node_modules/.bin/marked.CMD +0 -12
  3. ui/node_modules/.bin/marked.ps1 +0 -41
  4. ui/node_modules/.bin/playwright +0 -17
  5. ui/node_modules/.bin/playwright.CMD +0 -12
  6. ui/node_modules/.bin/playwright.ps1 +0 -41
  7. ui/node_modules/.bin/vite +0 -17
  8. ui/node_modules/.bin/vite.CMD +0 -12
  9. ui/node_modules/.bin/vite.ps1 +0 -41
  10. ui/node_modules/.bin/vitest +0 -17
  11. ui/node_modules/.bin/vitest.CMD +0 -12
  12. ui/node_modules/.bin/vitest.ps1 +0 -41
  13. ui/node_modules/@noble/ed25519/LICENSE +0 -21
  14. ui/node_modules/@noble/ed25519/README.md +0 -346
  15. ui/node_modules/@noble/ed25519/index.d.ts +0 -131
  16. ui/node_modules/@noble/ed25519/index.js +0 -630
  17. ui/node_modules/@noble/ed25519/index.ts +0 -685
  18. ui/node_modules/@noble/ed25519/package.json +0 -55
  19. ui/node_modules/@vitest/browser-playwright/LICENSE +0 -21
  20. ui/node_modules/@vitest/browser-playwright/README.md +0 -48
  21. ui/node_modules/@vitest/browser-playwright/context.d.ts +0 -1
  22. ui/node_modules/@vitest/browser-playwright/dist/index.d.ts +0 -106
  23. ui/node_modules/@vitest/browser-playwright/dist/index.js +0 -1112
  24. ui/node_modules/@vitest/browser-playwright/dist/locators.js +0 -114
  25. ui/node_modules/@vitest/browser-playwright/node_modules/.bin/playwright +0 -17
  26. ui/node_modules/@vitest/browser-playwright/node_modules/.bin/playwright.CMD +0 -12
  27. ui/node_modules/@vitest/browser-playwright/node_modules/.bin/playwright.ps1 +0 -41
  28. ui/node_modules/@vitest/browser-playwright/node_modules/.bin/vitest +0 -17
  29. ui/node_modules/@vitest/browser-playwright/node_modules/.bin/vitest.CMD +0 -12
  30. ui/node_modules/@vitest/browser-playwright/node_modules/.bin/vitest.ps1 +0 -41
  31. ui/node_modules/@vitest/browser-playwright/package.json +0 -65
  32. ui/node_modules/dompurify/LICENSE +0 -568
  33. ui/node_modules/dompurify/README.md +0 -479
  34. ui/node_modules/dompurify/dist/purify.cjs.d.ts +0 -450
  35. ui/node_modules/dompurify/dist/purify.cjs.js +0 -1388
  36. ui/node_modules/dompurify/dist/purify.cjs.js.map +0 -0
  37. ui/node_modules/dompurify/dist/purify.es.d.mts +0 -447
  38. ui/node_modules/dompurify/dist/purify.es.mjs +0 -1386
  39. ui/node_modules/dompurify/dist/purify.es.mjs.map +0 -0
  40. ui/node_modules/dompurify/dist/purify.js +0 -1394
  41. ui/node_modules/dompurify/dist/purify.js.map +0 -0
  42. ui/node_modules/dompurify/dist/purify.min.js +0 -3
  43. ui/node_modules/dompurify/dist/purify.min.js.map +0 -0
  44. ui/node_modules/dompurify/package.json +0 -171
  45. ui/node_modules/lit/LICENSE +0 -28
  46. ui/node_modules/lit/README.md +0 -71
  47. ui/node_modules/lit/async-directive.d.ts +0 -7
  48. ui/node_modules/lit/async-directive.d.ts.map +0 -1
  49. ui/node_modules/lit/async-directive.js +0 -2
  50. ui/node_modules/lit/async-directive.js.map +0 -1
ui/node_modules/.bin/marked DELETED
@@ -1,17 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
- esac
7
-
8
- if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules/marked/bin/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules/marked/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules/marked/bin/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules/marked/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules:$NODE_PATH"
12
- fi
13
- if [ -x "$basedir/node" ]; then
14
- exec "$basedir/node" "$basedir/../marked/bin/marked.js" "$@"
15
- else
16
- exec node "$basedir/../marked/bin/marked.js" "$@"
17
- fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/marked.CMD DELETED
@@ -1,12 +0,0 @@
1
- @SETLOCAL
2
- @IF NOT DEFINED NODE_PATH (
3
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules\marked\bin\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules\marked\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
4
- ) ELSE (
5
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules\marked\bin\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules\marked\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
- )
7
- @IF EXIST "%~dp0\node.exe" (
8
- "%~dp0\node.exe" "%~dp0\..\marked\bin\marked.js" %*
9
- ) ELSE (
10
- @SET PATHEXT=%PATHEXT:;.JS;=;%
11
- node "%~dp0\..\marked\bin\marked.js" %*
12
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/marked.ps1 DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env pwsh
2
- $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
-
4
- $exe=""
5
- $pathsep=":"
6
- $env_node_path=$env:NODE_PATH
7
- $new_node_path="F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules\marked\bin\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules\marked\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\marked@17.0.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
8
- if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
- # Fix case when both the Windows and Linux builds of Node
10
- # are installed in the same directory
11
- $exe=".exe"
12
- $pathsep=";"
13
- } else {
14
- $new_node_path="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules/marked/bin/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules/marked/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/marked@17.0.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
15
- }
16
- if ([string]::IsNullOrEmpty($env_node_path)) {
17
- $env:NODE_PATH=$new_node_path
18
- } else {
19
- $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
- }
21
-
22
- $ret=0
23
- if (Test-Path "$basedir/node$exe") {
24
- # Support pipeline input
25
- if ($MyInvocation.ExpectingInput) {
26
- $input | & "$basedir/node$exe" "$basedir/../marked/bin/marked.js" $args
27
- } else {
28
- & "$basedir/node$exe" "$basedir/../marked/bin/marked.js" $args
29
- }
30
- $ret=$LASTEXITCODE
31
- } else {
32
- # Support pipeline input
33
- if ($MyInvocation.ExpectingInput) {
34
- $input | & "node$exe" "$basedir/../marked/bin/marked.js" $args
35
- } else {
36
- & "node$exe" "$basedir/../marked/bin/marked.js" $args
37
- }
38
- $ret=$LASTEXITCODE
39
- }
40
- $env:NODE_PATH=$env_node_path
41
- exit $ret
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/playwright DELETED
@@ -1,17 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
- esac
7
-
8
- if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules/playwright/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules/playwright/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules:$NODE_PATH"
12
- fi
13
- if [ -x "$basedir/node" ]; then
14
- exec "$basedir/node" "$basedir/../playwright/cli.js" "$@"
15
- else
16
- exec node "$basedir/../playwright/cli.js" "$@"
17
- fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/playwright.CMD DELETED
@@ -1,12 +0,0 @@
1
- @SETLOCAL
2
- @IF NOT DEFINED NODE_PATH (
3
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules\playwright\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
4
- ) ELSE (
5
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules\playwright\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
- )
7
- @IF EXIST "%~dp0\node.exe" (
8
- "%~dp0\node.exe" "%~dp0\..\playwright\cli.js" %*
9
- ) ELSE (
10
- @SET PATHEXT=%PATHEXT:;.JS;=;%
11
- node "%~dp0\..\playwright\cli.js" %*
12
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/playwright.ps1 DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env pwsh
2
- $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
-
4
- $exe=""
5
- $pathsep=":"
6
- $env_node_path=$env:NODE_PATH
7
- $new_node_path="F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules\playwright\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
8
- if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
- # Fix case when both the Windows and Linux builds of Node
10
- # are installed in the same directory
11
- $exe=".exe"
12
- $pathsep=";"
13
- } else {
14
- $new_node_path="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules/playwright/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
15
- }
16
- if ([string]::IsNullOrEmpty($env_node_path)) {
17
- $env:NODE_PATH=$new_node_path
18
- } else {
19
- $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
- }
21
-
22
- $ret=0
23
- if (Test-Path "$basedir/node$exe") {
24
- # Support pipeline input
25
- if ($MyInvocation.ExpectingInput) {
26
- $input | & "$basedir/node$exe" "$basedir/../playwright/cli.js" $args
27
- } else {
28
- & "$basedir/node$exe" "$basedir/../playwright/cli.js" $args
29
- }
30
- $ret=$LASTEXITCODE
31
- } else {
32
- # Support pipeline input
33
- if ($MyInvocation.ExpectingInput) {
34
- $input | & "node$exe" "$basedir/../playwright/cli.js" $args
35
- } else {
36
- & "node$exe" "$basedir/../playwright/cli.js" $args
37
- }
38
- $ret=$LASTEXITCODE
39
- }
40
- $env:NODE_PATH=$env_node_path
41
- exit $ret
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/vite DELETED
@@ -1,17 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
- esac
7
-
8
- if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/bin/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/bin/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules:$NODE_PATH"
12
- fi
13
- if [ -x "$basedir/node" ]; then
14
- exec "$basedir/node" "$basedir/../vite/bin/vite.js" "$@"
15
- else
16
- exec node "$basedir/../vite/bin/vite.js" "$@"
17
- fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/vite.CMD DELETED
@@ -1,12 +0,0 @@
1
- @SETLOCAL
2
- @IF NOT DEFINED NODE_PATH (
3
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vite\bin\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vite\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
4
- ) ELSE (
5
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vite\bin\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vite\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
- )
7
- @IF EXIST "%~dp0\node.exe" (
8
- "%~dp0\node.exe" "%~dp0\..\vite\bin\vite.js" %*
9
- ) ELSE (
10
- @SET PATHEXT=%PATHEXT:;.JS;=;%
11
- node "%~dp0\..\vite\bin\vite.js" %*
12
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/vite.ps1 DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env pwsh
2
- $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
-
4
- $exe=""
5
- $pathsep=":"
6
- $env_node_path=$env:NODE_PATH
7
- $new_node_path="F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vite\bin\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vite\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
8
- if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
- # Fix case when both the Windows and Linux builds of Node
10
- # are installed in the same directory
11
- $exe=".exe"
12
- $pathsep=";"
13
- } else {
14
- $new_node_path="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/bin/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vite@7.3.1_@types+node@25.2.0_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
15
- }
16
- if ([string]::IsNullOrEmpty($env_node_path)) {
17
- $env:NODE_PATH=$new_node_path
18
- } else {
19
- $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
- }
21
-
22
- $ret=0
23
- if (Test-Path "$basedir/node$exe") {
24
- # Support pipeline input
25
- if ($MyInvocation.ExpectingInput) {
26
- $input | & "$basedir/node$exe" "$basedir/../vite/bin/vite.js" $args
27
- } else {
28
- & "$basedir/node$exe" "$basedir/../vite/bin/vite.js" $args
29
- }
30
- $ret=$LASTEXITCODE
31
- } else {
32
- # Support pipeline input
33
- if ($MyInvocation.ExpectingInput) {
34
- $input | & "node$exe" "$basedir/../vite/bin/vite.js" $args
35
- } else {
36
- & "node$exe" "$basedir/../vite/bin/vite.js" $args
37
- }
38
- $ret=$LASTEXITCODE
39
- }
40
- $env:NODE_PATH=$env_node_path
41
- exit $ret
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/vitest DELETED
@@ -1,17 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
- esac
7
-
8
- if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules:$NODE_PATH"
12
- fi
13
- if [ -x "$basedir/node" ]; then
14
- exec "$basedir/node" "$basedir/../vitest/vitest.mjs" "$@"
15
- else
16
- exec node "$basedir/../vitest/vitest.mjs" "$@"
17
- fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/vitest.CMD DELETED
@@ -1,12 +0,0 @@
1
- @SETLOCAL
2
- @IF NOT DEFINED NODE_PATH (
3
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vitest\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
4
- ) ELSE (
5
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vitest\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
- )
7
- @IF EXIST "%~dp0\node.exe" (
8
- "%~dp0\node.exe" "%~dp0\..\vitest\vitest.mjs" %*
9
- ) ELSE (
10
- @SET PATHEXT=%PATHEXT:;.JS;=;%
11
- node "%~dp0\..\vitest\vitest.mjs" %*
12
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/.bin/vitest.ps1 DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env pwsh
2
- $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
-
4
- $exe=""
5
- $pathsep=":"
6
- $env_node_path=$env:NODE_PATH
7
- $new_node_path="F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vitest\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
8
- if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
- # Fix case when both the Windows and Linux builds of Node
10
- # are installed in the same directory
11
- $exe=".exe"
12
- $pathsep=";"
13
- } else {
14
- $new_node_path="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
15
- }
16
- if ([string]::IsNullOrEmpty($env_node_path)) {
17
- $env:NODE_PATH=$new_node_path
18
- } else {
19
- $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
- }
21
-
22
- $ret=0
23
- if (Test-Path "$basedir/node$exe") {
24
- # Support pipeline input
25
- if ($MyInvocation.ExpectingInput) {
26
- $input | & "$basedir/node$exe" "$basedir/../vitest/vitest.mjs" $args
27
- } else {
28
- & "$basedir/node$exe" "$basedir/../vitest/vitest.mjs" $args
29
- }
30
- $ret=$LASTEXITCODE
31
- } else {
32
- # Support pipeline input
33
- if ($MyInvocation.ExpectingInput) {
34
- $input | & "node$exe" "$basedir/../vitest/vitest.mjs" $args
35
- } else {
36
- & "node$exe" "$basedir/../vitest/vitest.mjs" $args
37
- }
38
- $ret=$LASTEXITCODE
39
- }
40
- $env:NODE_PATH=$env_node_path
41
- exit $ret
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@noble/ed25519/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Paul Miller (https://paulmillr.com)
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
13
- all 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
21
- THE SOFTWARE.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@noble/ed25519/README.md DELETED
@@ -1,346 +0,0 @@
1
- # noble-ed25519
2
-
3
- Fastest 5KB JS implementation of ed25519 signatures.
4
-
5
- - ✍️ [EDDSA](https://en.wikipedia.org/wiki/EdDSA) signatures compliant with
6
- [RFC8032](https://tools.ietf.org/html/rfc8032), FIPS 186-5
7
- - 🪢 Consensus-friendly, compliant with [ZIP215](https://zips.z.cash/zip-0215)
8
- - 🔖 SUF-CMA (strong unforgeability under chosen message attacks) and
9
- SBS (non-repudiation / exclusive ownership)
10
- - 🪶 3.66KB (gzipped)
11
-
12
- The module is a sister project of [noble-curves](https://github.com/paulmillr/noble-curves),
13
- focusing on smaller attack surface & better auditability.
14
- Curves are drop-in replacement and have more features: ristretto255, x25519 / curve25519, ed25519ph, hash-to-curve, oprf. To upgrade from v1 to v2, see [Upgrading](#upgrading).
15
-
16
- ### This library belongs to _noble_ cryptography
17
-
18
- > **noble-cryptography** — high-security, easily auditable set of contained cryptographic libraries and tools.
19
-
20
- - Zero or minimal dependencies
21
- - Highly readable TypeScript / JS code
22
- - PGP-signed releases and transparent NPM builds with provenance
23
- - Check out [homepage](https://paulmillr.com/noble/) & all libraries:
24
- [ciphers](https://github.com/paulmillr/noble-ciphers),
25
- [curves](https://github.com/paulmillr/noble-curves),
26
- [hashes](https://github.com/paulmillr/noble-hashes),
27
- [post-quantum](https://github.com/paulmillr/noble-post-quantum),
28
- 5KB [secp256k1](https://github.com/paulmillr/noble-secp256k1) /
29
- [ed25519](https://github.com/paulmillr/noble-ed25519)
30
-
31
- ## Usage
32
-
33
- > `npm install @noble/ed25519`
34
-
35
- > `deno add jsr:@noble/ed25519`
36
-
37
- We support all major platforms and runtimes. For node.js <= 18 and React Native, additional polyfills are needed: see below.
38
-
39
- ```js
40
- import * as ed from '@noble/ed25519';
41
- (async () => {
42
- const { secretKey, publicKey } = await ed.keygenAsync();
43
- // const publicKey = await ed.getPublicKeyAsync(secretKey);
44
- const message = new TextEncoder().encode('hello noble');
45
- const signature = await ed.signAsync(message, secretKey);
46
- const isValid = await ed.verifyAsync(signature, message, publicKey);
47
- })();
48
- ```
49
-
50
- ### Enabling synchronous methods
51
-
52
- Only async methods are available by default, to keep the library dependency-free.
53
- To enable sync methods:
54
-
55
- ```ts
56
- import { sha512 } from '@noble/hashes/sha2.js';
57
- ed.hashes.sha512 = sha512;
58
- // Sync methods can be used now:
59
- const { secretKey, publicKey } = ed.keygen();
60
- // const publicKey = ed.getPublicKey(secretKey);
61
- const sig = ed.sign(msg, secretKey);
62
- const isValid = ed.verify(sig, msg, publicKey);
63
- ```
64
-
65
- ### React Native: polyfill getRandomValues and sha512
66
-
67
- ```ts
68
- import 'react-native-get-random-values';
69
- import { sha512 } from '@noble/hashes/sha2.js';
70
- ed.hashes.sha512 = sha512;
71
- ed.hashes.sha512Async = (m: Uint8Array) => Promise.resolve(sha512(m));
72
- ```
73
-
74
- ## API
75
-
76
- There are 4 main methods, which accept Uint8Array-s:
77
-
78
- - `keygen()` and `keygenAsync()`
79
- - `getPublicKey(secretKey)` and `getPublicKeyAsync(secretKey)`
80
- - `sign(message, secretKey)` and `signAsync(message, secretKey)`
81
- - `verify(signature, message, publicKey)` and `verifyAsync(signature, message, publicKey)`
82
-
83
- ### keygen
84
-
85
- ```typescript
86
- import * as ed from '@noble/ed25519';
87
- (async () => {
88
- const keys = ed.keygen(); // needs ed.hashes.sha512
89
- const { secretKey, publicKey } = keys
90
- const keysA = await ed.keygenAsync();
91
- })();
92
- ```
93
-
94
- ### getPublicKey
95
-
96
- ```typescript
97
- import * as ed from '@noble/ed25519';
98
- (async () => {
99
- const pubKey = ed.getPublicKey(secretKeyA); // needs ed.hashes.sha512
100
- const pubKeyA = await ed.getPublicKeyAsync(secretKeyA);
101
- const pubKeyPoint = ed.Point.fromBytes(pubKeyB);
102
- const pubKeyExtended = ed.utils.getExtendedPublicKey(secretKeyA);
103
- })();
104
- ```
105
-
106
- Generates 32-byte public key from 32-byte private key.
107
-
108
- - Some libraries have 64-byte private keys - those are just priv+pub concatenated
109
- - Use `ExtendedPoint.fromHex(publicKey)` if you want to convert hex / bytes into Point.
110
- It will use decompression algorithm 5.1.3 of RFC 8032.
111
- - Use `utils.getExtendedPublicKey` if you need full SHA512 hash of seed
112
-
113
- ### sign
114
-
115
- ```ts
116
- import * as ed from '@noble/ed25519';
117
- (async () => {
118
- const { secretKey, publicKey } = ed.keygen();
119
- const message = new TextEncoder().encode('hello noble');
120
- const signature = ed.sign(message, secretKey);
121
- const signatureA = await ed.signAsync(message, secretKey);
122
- })();
123
- ```
124
-
125
- Generates deterministic EdDSA signature. `message` would be hashed by ed25519 internally.
126
- For prehashed ed25519ph, switch to noble-curves.
127
-
128
- ### verify
129
-
130
- ```ts
131
- import * as ed from '@noble/ed25519';
132
- (async () => {
133
- const { secretKey, publicKey } = ed.keygen();
134
- const message = new TextEncoder().encode('hello noble');
135
- const signature = ed.sign(message, secretKey);
136
- const isValid = ed.verify(signature, message, pubKey);
137
-
138
- const isValidFips = ed.verify(signature, message, pubKey, { zip215: false });
139
- const isValidA = await ed.verifyAsync(signature, message, pubKey);
140
- })();
141
- ```
142
-
143
- Verifies EdDSA signature. Has SUF-CMA (strong unforgeability under chosen message attacks).
144
- By default, follows ZIP215 [^1] and can be used in consensus-critical apps [^2].
145
- `zip215: false` option switches verification criteria to strict
146
- RFC8032 / FIPS 186-5 and provides non-repudiation with SBS (Strongly Binding Signatures) [^3].
147
-
148
- ### utils
149
-
150
- A bunch of useful **utilities** are also exposed:
151
-
152
- ```typescript
153
- import * as ed from '@noble/ed25519';
154
- const { bytesToHex, hexToBytes, concatBytes, mod, invert, randomBytes } = ed.etc;
155
- const { getExtendedPublicKey, getExtendedPublicKeyAsync, randomSecretKey } = ed.utils;
156
- const { Point } = ed;
157
- console.log(Point.CURVE(), Point.BASE);
158
- /*
159
- class Point {
160
- static BASE: Point;
161
- static ZERO: Point;
162
- readonly X: bigint;
163
- readonly Y: bigint;
164
- readonly Z: bigint;
165
- readonly T: bigint;
166
- constructor(X: bigint, Y: bigint, Z: bigint, T: bigint);
167
- static CURVE(): EdwardsOpts;
168
- static fromAffine(p: AffinePoint): Point;
169
- static fromBytes(hex: Bytes, zip215?: boolean): Point;
170
- static fromHex(hex: string, zip215?: boolean): Point;
171
- get x(): bigint;
172
- get y(): bigint;
173
- assertValidity(): this;
174
- equals(other: Point): boolean;
175
- is0(): boolean;
176
- negate(): Point;
177
- double(): Point;
178
- add(other: Point): Point;
179
- subtract(other: Point): Point;
180
- multiply(n: bigint, safe?: boolean): Point;
181
- multiplyUnsafe(scalar: bigint): Point;
182
- toAffine(): AffinePoint;
183
- toBytes(): Bytes;
184
- toHex(): string;
185
- clearCofactor(): Point;
186
- isSmallOrder(): boolean;
187
- isTorsionFree(): boolean;
188
- }
189
- */
190
- ```
191
-
192
- ## Security
193
-
194
- The module is production-ready.
195
-
196
- We cross-test against sister project [noble-curves](https://github.com/paulmillr/noble-curves), which was audited and provides improved security.
197
-
198
- - The current version has not been independently audited. It is a rewrite of v1, which has been audited by cure53 in Feb 2022:
199
- [PDF](https://cure53.de/pentest-report_ed25519.pdf).
200
- - It's being fuzzed [in a separate repository](https://github.com/paulmillr/fuzzing)
201
-
202
- If you see anything unusual: investigate and report.
203
-
204
- ### Constant-timeness
205
-
206
- We're targetting algorithmic constant time. _JIT-compiler_ and _Garbage Collector_ make "constant time"
207
- extremely hard to achieve [timing attack](https://en.wikipedia.org/wiki/Timing_attack) resistance
208
- in a scripting language. Which means _any other JS library can't have
209
- constant-timeness_. Even statically typed Rust, a language without GC,
210
- [makes it harder to achieve constant-time](https://www.chosenplaintext.ca/open-source/rust-timing-shield/security)
211
- for some cases. If your goal is absolute security, don't use any JS lib — including bindings to native ones.
212
- Use low-level libraries & languages.
213
-
214
- ### Supply chain security
215
-
216
- - **Commits** are signed with PGP keys, to prevent forgery. Make sure to verify commit signatures
217
- - **Releases** are transparent and built on GitHub CI.
218
- Check out [attested checksums of single-file builds](https://github.com/paulmillr/noble-ed25519/attestations)
219
- and [provenance logs](https://github.com/paulmillr/noble-ed25519/actions/workflows/release.yml)
220
- - **Rare releasing** is followed to ensure less re-audit need for end-users
221
- - **Dependencies** are minimized and locked-down: any dependency could get hacked and users will be downloading malware with every install.
222
- - We make sure to use as few dependencies as possible
223
- - Automatic dep updates are prevented by locking-down version ranges; diffs are checked with `npm-diff`
224
- - **Dev Dependencies** are disabled for end-users; they are only used to develop / build the source code
225
-
226
- For this package, there are 0 dependencies; and a few dev dependencies:
227
-
228
- - [noble-hashes](https://github.com/paulmillr/noble-hashes) provides cryptographic hashing functionality
229
- - micro-bmark, micro-should and jsbt are used for benchmarking / testing / build tooling and developed by the same author
230
- - prettier, fast-check and typescript are used for code quality / test generation / ts compilation. It's hard to audit their source code thoroughly and fully because of their size
231
-
232
- ### Randomness
233
-
234
- We're deferring to built-in
235
- [crypto.getRandomValues](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues)
236
- which is considered cryptographically secure (CSPRNG).
237
-
238
- In the past, browsers had bugs that made it weak: it may happen again.
239
- Implementing a userspace CSPRNG to get resilient to the weakness
240
- is even worse: there is no reliable userspace source of quality entropy.
241
-
242
- ### Quantum computers
243
-
244
- Cryptographically relevant quantum computer, if built, will allow to
245
- break elliptic curve cryptography (both ECDSA / EdDSA & ECDH) using Shor's algorithm.
246
-
247
- Consider switching to newer / hybrid algorithms, such as SPHINCS+. They are available in
248
- [noble-post-quantum](https://github.com/paulmillr/noble-post-quantum).
249
-
250
- NIST prohibits classical cryptography (RSA, DSA, ECDSA, ECDH) [after 2035](https://nvlpubs.nist.gov/nistpubs/ir/2024/NIST.IR.8547.ipd.pdf). Australian ASD prohibits it [after 2030](https://www.cyber.gov.au/resources-business-and-government/essential-cyber-security/ism/cyber-security-guidelines/guidelines-cryptography).
251
-
252
- ## Speed
253
-
254
- npm run bench
255
-
256
- Benchmarks measured with Apple M4.
257
-
258
- init 11ms
259
- keygen x 11,253 ops/sec @ 88μs/op
260
- sign x 5,891 ops/sec @ 169μs/op
261
- verify x 1,281 ops/sec @ 780μs/op
262
-
263
- keygenAsync x 10,205 ops/sec @ 97μs/op
264
- signAsync x 4,985 ops/sec @ 200μs/op
265
- verifyAsync x 1,286 ops/sec @ 777μs/op
266
-
267
- Point.fromBytes x 22,811 ops/sec @ 43μs/op
268
-
269
- Compare to alternative implementations:
270
-
271
- tweetnacl@1.0.3 getPublicKey x 1,808 ops/sec @ 552μs/op ± 1.64%
272
- tweetnacl@1.0.3 sign x 651 ops/sec @ 1ms/op
273
- ristretto255@0.1.2 getPublicKey x 640 ops/sec @ 1ms/op ± 1.59%
274
- sodium-native#sign x 83,654 ops/sec @ 11μs/op
275
-
276
- ## Upgrading
277
-
278
- ### v2 to v3
279
-
280
- v3 brings the package closer to noble-curves v2.
281
-
282
- - Most methods now expect Uint8Array, string hex inputs are prohibited
283
- - Add `keygen`, `keygenAsync` method
284
- - Node v20.19 is now the minimum required version
285
- - Various small changes for types and Point class
286
- - etc: hashes are now set in `hashes` object:
287
-
288
- ```js
289
- // before
290
- ed.etc.sha512 = sha512;
291
- ed.etc.sha512Async = (m: Uint8Array) => Promise.resolve(sha512(m));
292
- // after
293
- ed.hashes.sha512 = sha512;
294
- ed.hashes.sha512Async = (m: Uint8Array) => Promise.resolve(sha512(m));
295
- ```
296
-
297
- ### v1 to v2
298
-
299
- v2 features improved security and smaller attack surface.
300
- The goal of v2 is to provide minimum possible JS library which is safe and fast.
301
-
302
- That means the library was reduced 4x, to just over 300 lines. In order to
303
- achieve the goal, **some features were moved** to
304
- [noble-curves](https://github.com/paulmillr/noble-curves), which is
305
- even safer and faster drop-in replacement library with same API.
306
- Switch to curves if you intend to keep using these features:
307
-
308
- - x25519 / curve25519 / getSharedSecret
309
- - ristretto255 / RistrettoPoint
310
- - Using `utils.precompute()` for non-base point
311
- - Support for environments which don't support bigint literals
312
- - Common.js support
313
- - Support for node.js 18 and older without [shim](#usage)
314
-
315
- Other changes for upgrading from @noble/ed25519 1.7 to 2.0:
316
-
317
- - Methods are now sync by default; use `getPublicKeyAsync`, `signAsync`, `verifyAsync` for async versions
318
- - `bigint` is no longer allowed in `getPublicKey`, `sign`, `verify`. Reason: ed25519 is LE, can lead to bugs
319
- - `Point` (2d xy) has been changed to `ExtendedPoint` (xyzt)
320
- - `Signature` was removed: just use raw bytes or hex now
321
- - `utils` were split into `utils` (same api as in noble-curves) and
322
- `etc` (`sha512Sync` and others)
323
-
324
- ## Contributing & testing
325
-
326
- - `npm install && npm run build && npm test` will build the code and run tests.
327
- - `npm run bench` will run benchmarks
328
- - `npm run build:release` will build single file
329
-
330
- See [paulmillr.com/noble](https://paulmillr.com/noble/)
331
- for useful resources, articles, documentation and demos
332
- related to the library.
333
-
334
- ## License
335
-
336
- The MIT License (MIT)
337
-
338
- Copyright (c) 2019 Paul Miller [(https://paulmillr.com)](https://paulmillr.com)
339
-
340
- See LICENSE file.
341
-
342
- [^1]: https://zips.z.cash/zip-0215
343
-
344
- [^2]: https://hdevalence.ca/blog/2020-10-04-its-25519am
345
-
346
- [^3]: https://eprint.iacr.org/2020/1244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@noble/ed25519/index.d.ts DELETED
@@ -1,131 +0,0 @@
1
- /** Alias to Uint8Array. */
2
- export type Bytes = Uint8Array;
3
- /** Hex-encoded string or Uint8Array. */
4
- /** Edwards elliptic curve options. */
5
- export type EdwardsOpts = Readonly<{
6
- p: bigint;
7
- n: bigint;
8
- h: bigint;
9
- a: bigint;
10
- d: bigint;
11
- Gx: bigint;
12
- Gy: bigint;
13
- }>;
14
- declare const bytesToHex: (b: Bytes) => string;
15
- declare const hexToBytes: (hex: string) => Bytes;
16
- declare const concatBytes: (...arrs: Bytes[]) => Bytes;
17
- /** WebCrypto OS-level CSPRNG (random number generator). Will throw when not available. */
18
- declare const randomBytes: (len?: number) => Bytes;
19
- /** modular division */
20
- declare const M: (a: bigint, b?: bigint) => bigint;
21
- /** Modular inversion using euclidean GCD (non-CT). No negative exponent for now. */
22
- declare const invert: (num: bigint, md: bigint) => bigint;
23
- declare const hash: (msg: Bytes) => Bytes;
24
- /** Point in 2d xy affine coordinates. */
25
- export type AffinePoint = {
26
- x: bigint;
27
- y: bigint;
28
- };
29
- /** Point in XYZT extended coordinates. */
30
- declare class Point {
31
- static BASE: Point;
32
- static ZERO: Point;
33
- readonly X: bigint;
34
- readonly Y: bigint;
35
- readonly Z: bigint;
36
- readonly T: bigint;
37
- constructor(X: bigint, Y: bigint, Z: bigint, T: bigint);
38
- static CURVE(): EdwardsOpts;
39
- static fromAffine(p: AffinePoint): Point;
40
- /** RFC8032 5.1.3: Uint8Array to Point. */
41
- static fromBytes(hex: Bytes, zip215?: boolean): Point;
42
- static fromHex(hex: string, zip215?: boolean): Point;
43
- get x(): bigint;
44
- get y(): bigint;
45
- /** Checks if the point is valid and on-curve. */
46
- assertValidity(): this;
47
- /** Equality check: compare points P&Q. */
48
- equals(other: Point): boolean;
49
- is0(): boolean;
50
- /** Flip point over y coordinate. */
51
- negate(): Point;
52
- /** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
53
- double(): Point;
54
- /** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
55
- add(other: Point): Point;
56
- subtract(other: Point): Point;
57
- /**
58
- * Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
59
- * Uses {@link wNAF} for base point.
60
- * Uses fake point to mitigate side-channel leakage.
61
- * @param n scalar by which point is multiplied
62
- * @param safe safe mode guards against timing attacks; unsafe mode is faster
63
- */
64
- multiply(n: bigint, safe?: boolean): Point;
65
- multiplyUnsafe(scalar: bigint): Point;
66
- /** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
67
- toAffine(): AffinePoint;
68
- toBytes(): Bytes;
69
- toHex(): string;
70
- clearCofactor(): Point;
71
- isSmallOrder(): boolean;
72
- isTorsionFree(): boolean;
73
- }
74
- type ExtK = {
75
- head: Bytes;
76
- prefix: Bytes;
77
- scalar: bigint;
78
- point: Point;
79
- pointBytes: Bytes;
80
- };
81
- declare const getExtendedPublicKeyAsync: (secretKey: Bytes) => Promise<ExtK>;
82
- declare const getExtendedPublicKey: (secretKey: Bytes) => ExtK;
83
- /** Creates 32-byte ed25519 public key from 32-byte secret key. Async. */
84
- declare const getPublicKeyAsync: (secretKey: Bytes) => Promise<Bytes>;
85
- /** Creates 32-byte ed25519 public key from 32-byte secret key. To use, set `hashes.sha512` first. */
86
- declare const getPublicKey: (priv: Bytes) => Bytes;
87
- /**
88
- * Signs message using secret key. Async.
89
- * Follows RFC8032 5.1.6.
90
- */
91
- declare const signAsync: (message: Bytes, secretKey: Bytes) => Promise<Bytes>;
92
- /**
93
- * Signs message using secret key. To use, set `hashes.sha512` first.
94
- * Follows RFC8032 5.1.6.
95
- */
96
- declare const sign: (message: Bytes, secretKey: Bytes) => Bytes;
97
- /** Verification options. zip215: true (default) follows ZIP215 spec. false would follow RFC8032. */
98
- export type EdDSAVerifyOpts = {
99
- zip215?: boolean;
100
- };
101
- /** Verifies signature on message and public key. Async. Follows RFC8032 5.1.7. */
102
- declare const verifyAsync: (signature: Bytes, message: Bytes, publicKey: Bytes, opts?: EdDSAVerifyOpts) => Promise<boolean>;
103
- /** Verifies signature on message and public key. To use, set `hashes.sha512` first. Follows RFC8032 5.1.7. */
104
- declare const verify: (signature: Bytes, message: Bytes, publicKey: Bytes, opts?: EdDSAVerifyOpts) => boolean;
105
- /** Math, hex, byte helpers. Not in `utils` because utils share API with noble-curves. */
106
- declare const etc: {
107
- bytesToHex: typeof bytesToHex;
108
- hexToBytes: typeof hexToBytes;
109
- concatBytes: typeof concatBytes;
110
- mod: typeof M;
111
- invert: typeof invert;
112
- randomBytes: typeof randomBytes;
113
- };
114
- declare const hashes: {
115
- sha512Async: (message: Bytes) => Promise<Bytes>;
116
- sha512: undefined | ((message: Bytes) => Bytes);
117
- };
118
- declare const randomSecretKey: (seed?: Bytes) => Bytes;
119
- type KeysSecPub = {
120
- secretKey: Bytes;
121
- publicKey: Bytes;
122
- };
123
- declare const keygen: (seed?: Bytes) => KeysSecPub;
124
- declare const keygenAsync: (seed?: Bytes) => Promise<KeysSecPub>;
125
- /** ed25519-specific key utilities. */
126
- declare const utils: {
127
- getExtendedPublicKeyAsync: typeof getExtendedPublicKeyAsync;
128
- getExtendedPublicKey: typeof getExtendedPublicKey;
129
- randomSecretKey: typeof randomSecretKey;
130
- };
131
- export { etc, getPublicKey, getPublicKeyAsync, hash, hashes, keygen, keygenAsync, Point, sign, signAsync, utils, verify, verifyAsync, };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@noble/ed25519/index.js DELETED
@@ -1,630 +0,0 @@
1
- /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
2
- /**
3
- * 5KB JS implementation of ed25519 EdDSA signatures.
4
- * Compliant with RFC8032, FIPS 186-5 & ZIP215.
5
- * @module
6
- * @example
7
- * ```js
8
- import * as ed from '@noble/ed25519';
9
- (async () => {
10
- const secretKey = ed.utils.randomSecretKey();
11
- const message = Uint8Array.from([0xab, 0xbc, 0xcd, 0xde]);
12
- const pubKey = await ed.getPublicKeyAsync(secretKey); // Sync methods are also present
13
- const signature = await ed.signAsync(message, secretKey);
14
- const isValid = await ed.verifyAsync(signature, message, pubKey);
15
- })();
16
- ```
17
- */
18
- /**
19
- * Curve params. ed25519 is twisted edwards curve. Equation is −x² + y² = -a + dx²y².
20
- * * P = `2n**255n - 19n` // field over which calculations are done
21
- * * N = `2n**252n + 27742317777372353535851937790883648493n` // group order, amount of curve points
22
- * * h = 8 // cofactor
23
- * * a = `Fp.create(BigInt(-1))` // equation param
24
- * * d = -121665/121666 a.k.a. `Fp.neg(121665 * Fp.inv(121666))` // equation param
25
- * * Gx, Gy are coordinates of Generator / base point
26
- */
27
- const ed25519_CURVE = {
28
- p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
29
- n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
30
- h: 8n,
31
- a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
32
- d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
33
- Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
34
- Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n,
35
- };
36
- const { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
37
- const L = 32; // field / group byte length
38
- const L2 = 64;
39
- // Helpers and Precomputes sections are reused between libraries
40
- // ## Helpers
41
- // ----------
42
- const captureTrace = (...args) => {
43
- if ('captureStackTrace' in Error && typeof Error.captureStackTrace === 'function') {
44
- Error.captureStackTrace(...args);
45
- }
46
- };
47
- const err = (message = '') => {
48
- const e = new Error(message);
49
- captureTrace(e, err);
50
- throw e;
51
- };
52
- const isBig = (n) => typeof n === 'bigint'; // is big integer
53
- const isStr = (s) => typeof s === 'string'; // is string
54
- const isBytes = (a) => a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
55
- /** Asserts something is Uint8Array. */
56
- const abytes = (value, length, title = '') => {
57
- const bytes = isBytes(value);
58
- const len = value?.length;
59
- const needsLen = length !== undefined;
60
- if (!bytes || (needsLen && len !== length)) {
61
- const prefix = title && `"${title}" `;
62
- const ofLen = needsLen ? ` of length ${length}` : '';
63
- const got = bytes ? `length=${len}` : `type=${typeof value}`;
64
- err(prefix + 'expected Uint8Array' + ofLen + ', got ' + got);
65
- }
66
- return value;
67
- };
68
- /** create Uint8Array */
69
- const u8n = (len) => new Uint8Array(len);
70
- const u8fr = (buf) => Uint8Array.from(buf);
71
- const padh = (n, pad) => n.toString(16).padStart(pad, '0');
72
- const bytesToHex = (b) => Array.from(abytes(b))
73
- .map((e) => padh(e, 2))
74
- .join('');
75
- const C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 }; // ASCII characters
76
- const _ch = (ch) => {
77
- if (ch >= C._0 && ch <= C._9)
78
- return ch - C._0; // '2' => 50-48
79
- if (ch >= C.A && ch <= C.F)
80
- return ch - (C.A - 10); // 'B' => 66-(65-10)
81
- if (ch >= C.a && ch <= C.f)
82
- return ch - (C.a - 10); // 'b' => 98-(97-10)
83
- return;
84
- };
85
- const hexToBytes = (hex) => {
86
- const e = 'hex invalid';
87
- if (!isStr(hex))
88
- return err(e);
89
- const hl = hex.length;
90
- const al = hl / 2;
91
- if (hl % 2)
92
- return err(e);
93
- const array = u8n(al);
94
- for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
95
- // treat each char as ASCII
96
- const n1 = _ch(hex.charCodeAt(hi)); // parse first char, multiply it by 16
97
- const n2 = _ch(hex.charCodeAt(hi + 1)); // parse second char
98
- if (n1 === undefined || n2 === undefined)
99
- return err(e);
100
- array[ai] = n1 * 16 + n2; // example: 'A9' => 10*16 + 9
101
- }
102
- return array;
103
- };
104
- const cr = () => globalThis?.crypto; // WebCrypto is available in all modern environments
105
- const subtle = () => cr()?.subtle ?? err('crypto.subtle must be defined, consider polyfill');
106
- // prettier-ignore
107
- const concatBytes = (...arrs) => {
108
- const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0)); // create u8a of summed length
109
- let pad = 0; // walk through each array,
110
- arrs.forEach(a => { r.set(a, pad); pad += a.length; }); // ensure they have proper type
111
- return r;
112
- };
113
- /** WebCrypto OS-level CSPRNG (random number generator). Will throw when not available. */
114
- const randomBytes = (len = L) => {
115
- const c = cr();
116
- return c.getRandomValues(u8n(len));
117
- };
118
- const big = BigInt;
119
- const assertRange = (n, min, max, msg = 'bad number: out of range') => (isBig(n) && min <= n && n < max ? n : err(msg));
120
- /** modular division */
121
- const M = (a, b = P) => {
122
- const r = a % b;
123
- return r >= 0n ? r : b + r;
124
- };
125
- const modN = (a) => M(a, N);
126
- /** Modular inversion using euclidean GCD (non-CT). No negative exponent for now. */
127
- // prettier-ignore
128
- const invert = (num, md) => {
129
- if (num === 0n || md <= 0n)
130
- err('no inverse n=' + num + ' mod=' + md);
131
- let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
132
- while (a !== 0n) {
133
- const q = b / a, r = b % a;
134
- const m = x - u * q, n = y - v * q;
135
- b = a, a = r, x = u, y = v, u = m, v = n;
136
- }
137
- return b === 1n ? M(x, md) : err('no inverse'); // b is gcd at this point
138
- };
139
- const callHash = (name) => {
140
- // @ts-ignore
141
- const fn = hashes[name];
142
- if (typeof fn !== 'function')
143
- err('hashes.' + name + ' not set');
144
- return fn;
145
- };
146
- const hash = (msg) => callHash('sha512')(msg);
147
- const apoint = (p) => (p instanceof Point ? p : err('Point expected'));
148
- // ## End of Helpers
149
- // -----------------
150
- const B256 = 2n ** 256n;
151
- /** Point in XYZT extended coordinates. */
152
- class Point {
153
- static BASE;
154
- static ZERO;
155
- X;
156
- Y;
157
- Z;
158
- T;
159
- constructor(X, Y, Z, T) {
160
- const max = B256;
161
- this.X = assertRange(X, 0n, max);
162
- this.Y = assertRange(Y, 0n, max);
163
- this.Z = assertRange(Z, 1n, max);
164
- this.T = assertRange(T, 0n, max);
165
- Object.freeze(this);
166
- }
167
- static CURVE() {
168
- return ed25519_CURVE;
169
- }
170
- static fromAffine(p) {
171
- return new Point(p.x, p.y, 1n, M(p.x * p.y));
172
- }
173
- /** RFC8032 5.1.3: Uint8Array to Point. */
174
- static fromBytes(hex, zip215 = false) {
175
- const d = _d;
176
- // Copy array to not mess it up.
177
- const normed = u8fr(abytes(hex, L));
178
- // adjust first LE byte = last BE byte
179
- const lastByte = hex[31];
180
- normed[31] = lastByte & ~0x80;
181
- const y = bytesToNumLE(normed);
182
- // zip215=true: 0 <= y < 2^256
183
- // zip215=false, RFC8032: 0 <= y < 2^255-19
184
- const max = zip215 ? B256 : P;
185
- assertRange(y, 0n, max);
186
- const y2 = M(y * y); // y²
187
- const u = M(y2 - 1n); // u=y²-1
188
- const v = M(d * y2 + 1n); // v=dy²+1
189
- let { isValid, value: x } = uvRatio(u, v); // (uv³)(uv⁷)^(p-5)/8; square root
190
- if (!isValid)
191
- err('bad point: y not sqrt'); // not square root: bad point
192
- const isXOdd = (x & 1n) === 1n; // adjust sign of x coordinate
193
- const isLastByteOdd = (lastByte & 0x80) !== 0; // x_0, last bit
194
- if (!zip215 && x === 0n && isLastByteOdd)
195
- err('bad point: x==0, isLastByteOdd'); // x=0, x_0=1
196
- if (isLastByteOdd !== isXOdd)
197
- x = M(-x);
198
- return new Point(x, y, 1n, M(x * y)); // Z=1, T=xy
199
- }
200
- static fromHex(hex, zip215) {
201
- return Point.fromBytes(hexToBytes(hex), zip215);
202
- }
203
- get x() {
204
- return this.toAffine().x;
205
- }
206
- get y() {
207
- return this.toAffine().y;
208
- }
209
- /** Checks if the point is valid and on-curve. */
210
- assertValidity() {
211
- const a = _a;
212
- const d = _d;
213
- const p = this;
214
- if (p.is0())
215
- return err('bad point: ZERO'); // TODO: optimize, with vars below?
216
- // Equation in affine coordinates: ax² + y² = 1 + dx²y²
217
- // Equation in projective coordinates (X/Z, Y/Z, Z): (aX² + Y²)Z² = Z⁴ + dX²Y²
218
- const { X, Y, Z, T } = p;
219
- const X2 = M(X * X); // X²
220
- const Y2 = M(Y * Y); // Y²
221
- const Z2 = M(Z * Z); // Z²
222
- const Z4 = M(Z2 * Z2); // Z⁴
223
- const aX2 = M(X2 * a); // aX²
224
- const left = M(Z2 * M(aX2 + Y2)); // (aX² + Y²)Z²
225
- const right = M(Z4 + M(d * M(X2 * Y2))); // Z⁴ + dX²Y²
226
- if (left !== right)
227
- return err('bad point: equation left != right (1)');
228
- // In Extended coordinates we also have T, which is x*y=T/Z: check X*Y == Z*T
229
- const XY = M(X * Y);
230
- const ZT = M(Z * T);
231
- if (XY !== ZT)
232
- return err('bad point: equation left != right (2)');
233
- return this;
234
- }
235
- /** Equality check: compare points P&Q. */
236
- equals(other) {
237
- const { X: X1, Y: Y1, Z: Z1 } = this;
238
- const { X: X2, Y: Y2, Z: Z2 } = apoint(other); // checks class equality
239
- const X1Z2 = M(X1 * Z2);
240
- const X2Z1 = M(X2 * Z1);
241
- const Y1Z2 = M(Y1 * Z2);
242
- const Y2Z1 = M(Y2 * Z1);
243
- return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
244
- }
245
- is0() {
246
- return this.equals(I);
247
- }
248
- /** Flip point over y coordinate. */
249
- negate() {
250
- return new Point(M(-this.X), this.Y, this.Z, M(-this.T));
251
- }
252
- /** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
253
- double() {
254
- const { X: X1, Y: Y1, Z: Z1 } = this;
255
- const a = _a;
256
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
257
- const A = M(X1 * X1);
258
- const B = M(Y1 * Y1);
259
- const C = M(2n * M(Z1 * Z1));
260
- const D = M(a * A);
261
- const x1y1 = X1 + Y1;
262
- const E = M(M(x1y1 * x1y1) - A - B);
263
- const G = D + B;
264
- const F = G - C;
265
- const H = D - B;
266
- const X3 = M(E * F);
267
- const Y3 = M(G * H);
268
- const T3 = M(E * H);
269
- const Z3 = M(F * G);
270
- return new Point(X3, Y3, Z3, T3);
271
- }
272
- /** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
273
- add(other) {
274
- const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
275
- const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other); // doesn't check if other on-curve
276
- const a = _a;
277
- const d = _d;
278
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html#addition-add-2008-hwcd-3
279
- const A = M(X1 * X2);
280
- const B = M(Y1 * Y2);
281
- const C = M(T1 * d * T2);
282
- const D = M(Z1 * Z2);
283
- const E = M((X1 + Y1) * (X2 + Y2) - A - B);
284
- const F = M(D - C);
285
- const G = M(D + C);
286
- const H = M(B - a * A);
287
- const X3 = M(E * F);
288
- const Y3 = M(G * H);
289
- const T3 = M(E * H);
290
- const Z3 = M(F * G);
291
- return new Point(X3, Y3, Z3, T3);
292
- }
293
- subtract(other) {
294
- return this.add(apoint(other).negate());
295
- }
296
- /**
297
- * Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
298
- * Uses {@link wNAF} for base point.
299
- * Uses fake point to mitigate side-channel leakage.
300
- * @param n scalar by which point is multiplied
301
- * @param safe safe mode guards against timing attacks; unsafe mode is faster
302
- */
303
- multiply(n, safe = true) {
304
- if (!safe && (n === 0n || this.is0()))
305
- return I;
306
- assertRange(n, 1n, N);
307
- if (n === 1n)
308
- return this;
309
- if (this.equals(G))
310
- return wNAF(n).p;
311
- // init result point & fake point
312
- let p = I;
313
- let f = G;
314
- for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
315
- // if bit is present, add to point
316
- // if not present, add to fake, for timing safety
317
- if (n & 1n)
318
- p = p.add(d);
319
- else if (safe)
320
- f = f.add(d);
321
- }
322
- return p;
323
- }
324
- multiplyUnsafe(scalar) {
325
- return this.multiply(scalar, false);
326
- }
327
- /** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
328
- toAffine() {
329
- const { X, Y, Z } = this;
330
- // fast-paths for ZERO point OR Z=1
331
- if (this.equals(I))
332
- return { x: 0n, y: 1n };
333
- const iz = invert(Z, P);
334
- // (Z * Z^-1) must be 1, otherwise bad math
335
- if (M(Z * iz) !== 1n)
336
- err('invalid inverse');
337
- // x = X*Z^-1; y = Y*Z^-1
338
- const x = M(X * iz);
339
- const y = M(Y * iz);
340
- return { x, y };
341
- }
342
- toBytes() {
343
- const { x, y } = this.assertValidity().toAffine();
344
- const b = numTo32bLE(y);
345
- // store sign in first LE byte
346
- b[31] |= x & 1n ? 0x80 : 0;
347
- return b;
348
- }
349
- toHex() {
350
- return bytesToHex(this.toBytes());
351
- }
352
- clearCofactor() {
353
- return this.multiply(big(h), false);
354
- }
355
- isSmallOrder() {
356
- return this.clearCofactor().is0();
357
- }
358
- isTorsionFree() {
359
- // Multiply by big number N. We can't `mul(N)` because of checks. Instead, we `mul(N/2)*2+1`
360
- let p = this.multiply(N / 2n, false).double();
361
- if (N % 2n)
362
- p = p.add(this);
363
- return p.is0();
364
- }
365
- }
366
- /** Generator / base point */
367
- const G = new Point(Gx, Gy, 1n, M(Gx * Gy));
368
- /** Identity / zero point */
369
- const I = new Point(0n, 1n, 1n, 0n);
370
- // Static aliases
371
- Point.BASE = G;
372
- Point.ZERO = I;
373
- const numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
374
- const bytesToNumLE = (b) => big('0x' + bytesToHex(u8fr(abytes(b)).reverse()));
375
- const pow2 = (x, power) => {
376
- // pow2(x, 4) == x^(2^4)
377
- let r = x;
378
- while (power-- > 0n) {
379
- r *= r;
380
- r %= P;
381
- }
382
- return r;
383
- };
384
- // prettier-ignore
385
- const pow_2_252_3 = (x) => {
386
- const x2 = (x * x) % P; // x^2, bits 1
387
- const b2 = (x2 * x) % P; // x^3, bits 11
388
- const b4 = (pow2(b2, 2n) * b2) % P; // x^(2^4-1), bits 1111
389
- const b5 = (pow2(b4, 1n) * x) % P; // x^(2^5-1), bits 11111
390
- const b10 = (pow2(b5, 5n) * b5) % P; // x^(2^10)
391
- const b20 = (pow2(b10, 10n) * b10) % P; // x^(2^20)
392
- const b40 = (pow2(b20, 20n) * b20) % P; // x^(2^40)
393
- const b80 = (pow2(b40, 40n) * b40) % P; // x^(2^80)
394
- const b160 = (pow2(b80, 80n) * b80) % P; // x^(2^160)
395
- const b240 = (pow2(b160, 80n) * b80) % P; // x^(2^240)
396
- const b250 = (pow2(b240, 10n) * b10) % P; // x^(2^250)
397
- const pow_p_5_8 = (pow2(b250, 2n) * x) % P; // < To pow to (p+3)/8, multiply it by x.
398
- return { pow_p_5_8, b2 };
399
- };
400
- const RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n; // √-1
401
- // for sqrt comp
402
- // prettier-ignore
403
- const uvRatio = (u, v) => {
404
- const v3 = M(v * v * v); // v³
405
- const v7 = M(v3 * v3 * v); // v⁷
406
- const pow = pow_2_252_3(u * v7).pow_p_5_8; // (uv⁷)^(p-5)/8
407
- let x = M(u * v3 * pow); // (uv³)(uv⁷)^(p-5)/8
408
- const vx2 = M(v * x * x); // vx²
409
- const root1 = x; // First root candidate
410
- const root2 = M(x * RM1); // Second root candidate; RM1 is √-1
411
- const useRoot1 = vx2 === u; // If vx² = u (mod p), x is a square root
412
- const useRoot2 = vx2 === M(-u); // If vx² = -u, set x <-- x * 2^((p-1)/4)
413
- const noRoot = vx2 === M(-u * RM1); // There is no valid root, vx² = -u√-1
414
- if (useRoot1)
415
- x = root1;
416
- if (useRoot2 || noRoot)
417
- x = root2; // We return root2 anyway, for const-time
418
- if ((M(x) & 1n) === 1n)
419
- x = M(-x); // edIsNegative
420
- return { isValid: useRoot1 || useRoot2, value: x };
421
- };
422
- // N == L, just weird naming
423
- const modL_LE = (hash) => modN(bytesToNumLE(hash)); // modulo L; but little-endian
424
- /** hashes.sha512 should conform to the interface. */
425
- // TODO: rename
426
- const sha512a = (...m) => hashes.sha512Async(concatBytes(...m)); // Async SHA512
427
- const sha512s = (...m) => callHash('sha512')(concatBytes(...m));
428
- // RFC8032 5.1.5
429
- const hash2extK = (hashed) => {
430
- // slice creates a copy, unlike subarray
431
- const head = hashed.slice(0, L);
432
- head[0] &= 248; // Clamp bits: 0b1111_1000
433
- head[31] &= 127; // 0b0111_1111
434
- head[31] |= 64; // 0b0100_0000
435
- const prefix = hashed.slice(L, L2); // secret key "prefix"
436
- const scalar = modL_LE(head); // modular division over curve order
437
- const point = G.multiply(scalar); // public key point
438
- const pointBytes = point.toBytes(); // point serialized to Uint8Array
439
- return { head, prefix, scalar, point, pointBytes };
440
- };
441
- // RFC8032 5.1.5; getPublicKey async, sync. Hash priv key and extract point.
442
- const getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes(secretKey, L)).then(hash2extK);
443
- const getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes(secretKey, L)));
444
- /** Creates 32-byte ed25519 public key from 32-byte secret key. Async. */
445
- const getPublicKeyAsync = (secretKey) => getExtendedPublicKeyAsync(secretKey).then((p) => p.pointBytes);
446
- /** Creates 32-byte ed25519 public key from 32-byte secret key. To use, set `hashes.sha512` first. */
447
- const getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
448
- const hashFinishA = (res) => sha512a(res.hashable).then(res.finish);
449
- const hashFinishS = (res) => res.finish(sha512s(res.hashable));
450
- // Code, shared between sync & async sign
451
- const _sign = (e, rBytes, msg) => {
452
- const { pointBytes: P, scalar: s } = e;
453
- const r = modL_LE(rBytes); // r was created outside, reduce it modulo L
454
- const R = G.multiply(r).toBytes(); // R = [r]B
455
- const hashable = concatBytes(R, P, msg); // dom2(F, C) || R || A || PH(M)
456
- const finish = (hashed) => {
457
- // k = SHA512(dom2(F, C) || R || A || PH(M))
458
- const S = modN(r + modL_LE(hashed) * s); // S = (r + k * s) mod L; 0 <= s < l
459
- return abytes(concatBytes(R, numTo32bLE(S)), L2); // 64-byte sig: 32b R.x + 32b LE(S)
460
- };
461
- return { hashable, finish };
462
- };
463
- /**
464
- * Signs message using secret key. Async.
465
- * Follows RFC8032 5.1.6.
466
- */
467
- const signAsync = async (message, secretKey) => {
468
- const m = abytes(message);
469
- const e = await getExtendedPublicKeyAsync(secretKey);
470
- const rBytes = await sha512a(e.prefix, m); // r = SHA512(dom2(F, C) || prefix || PH(M))
471
- return hashFinishA(_sign(e, rBytes, m)); // gen R, k, S, then 64-byte signature
472
- };
473
- /**
474
- * Signs message using secret key. To use, set `hashes.sha512` first.
475
- * Follows RFC8032 5.1.6.
476
- */
477
- const sign = (message, secretKey) => {
478
- const m = abytes(message);
479
- const e = getExtendedPublicKey(secretKey);
480
- const rBytes = sha512s(e.prefix, m); // r = SHA512(dom2(F, C) || prefix || PH(M))
481
- return hashFinishS(_sign(e, rBytes, m)); // gen R, k, S, then 64-byte signature
482
- };
483
- const defaultVerifyOpts = { zip215: true };
484
- const _verify = (sig, msg, pub, opts = defaultVerifyOpts) => {
485
- sig = abytes(sig, L2); // Signature hex str/Bytes, must be 64 bytes
486
- msg = abytes(msg); // Message hex str/Bytes
487
- pub = abytes(pub, L);
488
- const { zip215 } = opts; // switch between zip215 and rfc8032 verif
489
- let A;
490
- let R;
491
- let s;
492
- let SB;
493
- let hashable = Uint8Array.of();
494
- try {
495
- A = Point.fromBytes(pub, zip215); // public key A decoded
496
- R = Point.fromBytes(sig.slice(0, L), zip215); // 0 <= R < 2^256: ZIP215 R can be >= P
497
- s = bytesToNumLE(sig.slice(L, L2)); // Decode second half as an integer S
498
- SB = G.multiply(s, false); // in the range 0 <= s < L
499
- hashable = concatBytes(R.toBytes(), A.toBytes(), msg); // dom2(F, C) || R || A || PH(M)
500
- }
501
- catch (error) { }
502
- const finish = (hashed) => {
503
- // k = SHA512(dom2(F, C) || R || A || PH(M))
504
- if (SB == null)
505
- return false; // false if try-catch catched an error
506
- if (!zip215 && A.isSmallOrder())
507
- return false; // false for SBS: Strongly Binding Signature
508
- const k = modL_LE(hashed); // decode in little-endian, modulo L
509
- const RkA = R.add(A.multiply(k, false)); // [8]R + [8][k]A'
510
- return RkA.add(SB.negate()).clearCofactor().is0(); // [8][S]B = [8]R + [8][k]A'
511
- };
512
- return { hashable, finish };
513
- };
514
- /** Verifies signature on message and public key. Async. Follows RFC8032 5.1.7. */
515
- const verifyAsync = async (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishA(_verify(signature, message, publicKey, opts));
516
- /** Verifies signature on message and public key. To use, set `hashes.sha512` first. Follows RFC8032 5.1.7. */
517
- const verify = (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishS(_verify(signature, message, publicKey, opts));
518
- /** Math, hex, byte helpers. Not in `utils` because utils share API with noble-curves. */
519
- const etc = {
520
- bytesToHex: bytesToHex,
521
- hexToBytes: hexToBytes,
522
- concatBytes: concatBytes,
523
- mod: M,
524
- invert: invert,
525
- randomBytes: randomBytes,
526
- };
527
- const hashes = {
528
- sha512Async: async (message) => {
529
- const s = subtle();
530
- const m = concatBytes(message);
531
- return u8n(await s.digest('SHA-512', m.buffer));
532
- },
533
- sha512: undefined,
534
- };
535
- // FIPS 186 B.4.1 compliant key generation produces private keys
536
- // with modulo bias being neglible. takes >N+16 bytes, returns (hash mod n-1)+1
537
- const randomSecretKey = (seed = randomBytes(L)) => seed;
538
- const keygen = (seed) => {
539
- const secretKey = randomSecretKey(seed);
540
- const publicKey = getPublicKey(secretKey);
541
- return { secretKey, publicKey };
542
- };
543
- const keygenAsync = async (seed) => {
544
- const secretKey = randomSecretKey(seed);
545
- const publicKey = await getPublicKeyAsync(secretKey);
546
- return { secretKey, publicKey };
547
- };
548
- /** ed25519-specific key utilities. */
549
- const utils = {
550
- getExtendedPublicKeyAsync: getExtendedPublicKeyAsync,
551
- getExtendedPublicKey: getExtendedPublicKey,
552
- randomSecretKey: randomSecretKey,
553
- };
554
- // ## Precomputes
555
- // --------------
556
- const W = 8; // W is window size
557
- const scalarBits = 256;
558
- const pwindows = Math.ceil(scalarBits / W) + 1; // 33 for W=8, NOT 32 - see wNAF loop
559
- const pwindowSize = 2 ** (W - 1); // 128 for W=8
560
- const precompute = () => {
561
- const points = [];
562
- let p = G;
563
- let b = p;
564
- for (let w = 0; w < pwindows; w++) {
565
- b = p;
566
- points.push(b);
567
- for (let i = 1; i < pwindowSize; i++) {
568
- b = b.add(p);
569
- points.push(b);
570
- } // i=1, bc we skip 0
571
- p = b.double();
572
- }
573
- return points;
574
- };
575
- let Gpows = undefined; // precomputes for base point G
576
- // const-time negate
577
- const ctneg = (cnd, p) => {
578
- const n = p.negate();
579
- return cnd ? n : p;
580
- };
581
- /**
582
- * Precomputes give 12x faster getPublicKey(), 10x sign(), 2x verify() by
583
- * caching multiples of G (base point). Cache is stored in 32MB of RAM.
584
- * Any time `G.multiply` is done, precomputes are used.
585
- * Not used for getSharedSecret, which instead multiplies random pubkey `P.multiply`.
586
- *
587
- * w-ary non-adjacent form (wNAF) precomputation method is 10% slower than windowed method,
588
- * but takes 2x less RAM. RAM reduction is possible by utilizing `.subtract`.
589
- *
590
- * !! Precomputes can be disabled by commenting-out call of the wNAF() inside Point#multiply().
591
- */
592
- const wNAF = (n) => {
593
- const comp = Gpows || (Gpows = precompute());
594
- let p = I;
595
- let f = G; // f must be G, or could become I in the end
596
- const pow_2_w = 2 ** W; // 256 for W=8
597
- const maxNum = pow_2_w; // 256 for W=8
598
- const mask = big(pow_2_w - 1); // 255 for W=8 == mask 0b11111111
599
- const shiftBy = big(W); // 8 for W=8
600
- for (let w = 0; w < pwindows; w++) {
601
- let wbits = Number(n & mask); // extract W bits.
602
- n >>= shiftBy; // shift number by W bits.
603
- // We use negative indexes to reduce size of precomputed table by 2x.
604
- // Instead of needing precomputes 0..256, we only calculate them for 0..128.
605
- // If an index > 128 is found, we do (256-index) - where 256 is next window.
606
- // Naive: index +127 => 127, +224 => 224
607
- // Optimized: index +127 => 127, +224 => 256-32
608
- if (wbits > pwindowSize) {
609
- wbits -= maxNum;
610
- n += 1n;
611
- }
612
- const off = w * pwindowSize;
613
- const offF = off; // offsets, evaluate both
614
- const offP = off + Math.abs(wbits) - 1;
615
- const isEven = w % 2 !== 0; // conditions, evaluate both
616
- const isNeg = wbits < 0;
617
- if (wbits === 0) {
618
- // off == I: can't add it. Adding random offF instead.
619
- f = f.add(ctneg(isEven, comp[offF])); // bits are 0: add garbage to fake point
620
- }
621
- else {
622
- p = p.add(ctneg(isNeg, comp[offP])); // bits are 1: add to result point
623
- }
624
- }
625
- if (n !== 0n)
626
- err('invalid wnaf');
627
- return { p, f }; // return both real and fake points for JIT
628
- };
629
- // !! Remove the export to easily use in REPL / browser console
630
- export { etc, getPublicKey, getPublicKeyAsync, hash, hashes, keygen, keygenAsync, Point, sign, signAsync, utils, verify, verifyAsync, };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@noble/ed25519/index.ts DELETED
@@ -1,685 +0,0 @@
1
- /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
2
- /**
3
- * 5KB JS implementation of ed25519 EdDSA signatures.
4
- * Compliant with RFC8032, FIPS 186-5 & ZIP215.
5
- * @module
6
- * @example
7
- * ```js
8
- import * as ed from '@noble/ed25519';
9
- (async () => {
10
- const secretKey = ed.utils.randomSecretKey();
11
- const message = Uint8Array.from([0xab, 0xbc, 0xcd, 0xde]);
12
- const pubKey = await ed.getPublicKeyAsync(secretKey); // Sync methods are also present
13
- const signature = await ed.signAsync(message, secretKey);
14
- const isValid = await ed.verifyAsync(signature, message, pubKey);
15
- })();
16
- ```
17
- */
18
- /**
19
- * Curve params. ed25519 is twisted edwards curve. Equation is −x² + y² = -a + dx²y².
20
- * * P = `2n**255n - 19n` // field over which calculations are done
21
- * * N = `2n**252n + 27742317777372353535851937790883648493n` // group order, amount of curve points
22
- * * h = 8 // cofactor
23
- * * a = `Fp.create(BigInt(-1))` // equation param
24
- * * d = -121665/121666 a.k.a. `Fp.neg(121665 * Fp.inv(121666))` // equation param
25
- * * Gx, Gy are coordinates of Generator / base point
26
- */
27
- const ed25519_CURVE: EdwardsOpts = {
28
- p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
29
- n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
30
- h: 8n,
31
- a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
32
- d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
33
- Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
34
- Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n,
35
- };
36
- const { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
37
- const L = 32; // field / group byte length
38
- const L2 = 64;
39
- /** Alias to Uint8Array. */
40
- export type Bytes = Uint8Array;
41
- /** Hex-encoded string or Uint8Array. */
42
- /** Edwards elliptic curve options. */
43
- export type EdwardsOpts = Readonly<{
44
- p: bigint;
45
- n: bigint;
46
- h: bigint;
47
- a: bigint;
48
- d: bigint;
49
- Gx: bigint;
50
- Gy: bigint;
51
- }>;
52
-
53
- // Helpers and Precomputes sections are reused between libraries
54
-
55
- // ## Helpers
56
- // ----------
57
- const captureTrace = (...args: Parameters<typeof Error.captureStackTrace>): void => {
58
- if ('captureStackTrace' in Error && typeof Error.captureStackTrace === 'function') {
59
- Error.captureStackTrace(...args);
60
- }
61
- };
62
- const err = (message = ''): never => {
63
- const e = new Error(message);
64
- captureTrace(e, err);
65
- throw e;
66
- };
67
- const isBig = (n: unknown): n is bigint => typeof n === 'bigint'; // is big integer
68
- const isStr = (s: unknown): s is string => typeof s === 'string'; // is string
69
- const isBytes = (a: unknown): a is Bytes =>
70
- a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
71
- /** Asserts something is Uint8Array. */
72
- const abytes = (value: Bytes, length?: number, title: string = ''): Bytes => {
73
- const bytes = isBytes(value);
74
- const len = value?.length;
75
- const needsLen = length !== undefined;
76
- if (!bytes || (needsLen && len !== length)) {
77
- const prefix = title && `"${title}" `;
78
- const ofLen = needsLen ? ` of length ${length}` : '';
79
- const got = bytes ? `length=${len}` : `type=${typeof value}`;
80
- err(prefix + 'expected Uint8Array' + ofLen + ', got ' + got);
81
- }
82
- return value;
83
- };
84
- /** create Uint8Array */
85
- const u8n = (len: number) => new Uint8Array(len);
86
- const u8fr = (buf: ArrayLike<number>) => Uint8Array.from(buf);
87
- const padh = (n: number | bigint, pad: number) => n.toString(16).padStart(pad, '0');
88
- const bytesToHex = (b: Bytes): string =>
89
- Array.from(abytes(b))
90
- .map((e) => padh(e, 2))
91
- .join('');
92
- const C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const; // ASCII characters
93
- const _ch = (ch: number): number | undefined => {
94
- if (ch >= C._0 && ch <= C._9) return ch - C._0; // '2' => 50-48
95
- if (ch >= C.A && ch <= C.F) return ch - (C.A - 10); // 'B' => 66-(65-10)
96
- if (ch >= C.a && ch <= C.f) return ch - (C.a - 10); // 'b' => 98-(97-10)
97
- return;
98
- };
99
- const hexToBytes = (hex: string): Bytes => {
100
- const e = 'hex invalid';
101
- if (!isStr(hex)) return err(e);
102
- const hl = hex.length;
103
- const al = hl / 2;
104
- if (hl % 2) return err(e);
105
- const array = u8n(al);
106
- for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
107
- // treat each char as ASCII
108
- const n1 = _ch(hex.charCodeAt(hi)); // parse first char, multiply it by 16
109
- const n2 = _ch(hex.charCodeAt(hi + 1)); // parse second char
110
- if (n1 === undefined || n2 === undefined) return err(e);
111
- array[ai] = n1 * 16 + n2; // example: 'A9' => 10*16 + 9
112
- }
113
- return array;
114
- };
115
- declare const globalThis: Record<string, any> | undefined; // Typescript symbol present in browsers
116
- const cr = () => globalThis?.crypto; // WebCrypto is available in all modern environments
117
- const subtle = () => cr()?.subtle ?? err('crypto.subtle must be defined, consider polyfill');
118
- // prettier-ignore
119
- const concatBytes = (...arrs: Bytes[]): Bytes => {
120
- const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0)); // create u8a of summed length
121
- let pad = 0; // walk through each array,
122
- arrs.forEach(a => { r.set(a, pad); pad += a.length; }); // ensure they have proper type
123
- return r;
124
- };
125
- /** WebCrypto OS-level CSPRNG (random number generator). Will throw when not available. */
126
- const randomBytes = (len: number = L): Bytes => {
127
- const c = cr();
128
- return c.getRandomValues(u8n(len));
129
- };
130
- const big = BigInt;
131
- const assertRange = (
132
- n: bigint,
133
- min: bigint,
134
- max: bigint,
135
- msg = 'bad number: out of range'
136
- ): bigint => (isBig(n) && min <= n && n < max ? n : err(msg));
137
- /** modular division */
138
- const M = (a: bigint, b: bigint = P): bigint => {
139
- const r = a % b;
140
- return r >= 0n ? r : b + r;
141
- };
142
- const modN = (a: bigint) => M(a, N);
143
- /** Modular inversion using euclidean GCD (non-CT). No negative exponent for now. */
144
- // prettier-ignore
145
- const invert = (num: bigint, md: bigint): bigint => {
146
- if (num === 0n || md <= 0n) err('no inverse n=' + num + ' mod=' + md);
147
- let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
148
- while (a !== 0n) {
149
- const q = b / a, r = b % a;
150
- const m = x - u * q, n = y - v * q;
151
- b = a, a = r, x = u, y = v, u = m, v = n;
152
- }
153
- return b === 1n ? M(x, md) : err('no inverse'); // b is gcd at this point
154
- };
155
- const callHash = (name: string) => {
156
- // @ts-ignore
157
- const fn = hashes[name];
158
- if (typeof fn !== 'function') err('hashes.' + name + ' not set');
159
- return fn;
160
- };
161
- const hash = (msg: Bytes): Bytes => callHash('sha512')(msg);
162
- const apoint = (p: unknown) => (p instanceof Point ? p : err('Point expected'));
163
- /** Point in 2d xy affine coordinates. */
164
- export type AffinePoint = {
165
- x: bigint;
166
- y: bigint;
167
- };
168
- // ## End of Helpers
169
- // -----------------
170
-
171
- const B256 = 2n ** 256n;
172
- /** Point in XYZT extended coordinates. */
173
- class Point {
174
- static BASE: Point;
175
- static ZERO: Point;
176
- readonly X: bigint;
177
- readonly Y: bigint;
178
- readonly Z: bigint;
179
- readonly T: bigint;
180
- constructor(X: bigint, Y: bigint, Z: bigint, T: bigint) {
181
- const max = B256;
182
- this.X = assertRange(X, 0n, max);
183
- this.Y = assertRange(Y, 0n, max);
184
- this.Z = assertRange(Z, 1n, max);
185
- this.T = assertRange(T, 0n, max);
186
- Object.freeze(this);
187
- }
188
- static CURVE(): EdwardsOpts {
189
- return ed25519_CURVE;
190
- }
191
- static fromAffine(p: AffinePoint): Point {
192
- return new Point(p.x, p.y, 1n, M(p.x * p.y));
193
- }
194
- /** RFC8032 5.1.3: Uint8Array to Point. */
195
- static fromBytes(hex: Bytes, zip215 = false): Point {
196
- const d = _d;
197
- // Copy array to not mess it up.
198
- const normed = u8fr(abytes(hex, L));
199
- // adjust first LE byte = last BE byte
200
- const lastByte = hex[31];
201
- normed[31] = lastByte & ~0x80;
202
- const y = bytesToNumLE(normed);
203
- // zip215=true: 0 <= y < 2^256
204
- // zip215=false, RFC8032: 0 <= y < 2^255-19
205
- const max = zip215 ? B256 : P;
206
- assertRange(y, 0n, max);
207
-
208
- const y2 = M(y * y); // y²
209
- const u = M(y2 - 1n); // u=y²-1
210
- const v = M(d * y2 + 1n); // v=dy²+1
211
- let { isValid, value: x } = uvRatio(u, v); // (uv³)(uv⁷)^(p-5)/8; square root
212
- if (!isValid) err('bad point: y not sqrt'); // not square root: bad point
213
- const isXOdd = (x & 1n) === 1n; // adjust sign of x coordinate
214
- const isLastByteOdd = (lastByte & 0x80) !== 0; // x_0, last bit
215
- if (!zip215 && x === 0n && isLastByteOdd) err('bad point: x==0, isLastByteOdd'); // x=0, x_0=1
216
- if (isLastByteOdd !== isXOdd) x = M(-x);
217
- return new Point(x, y, 1n, M(x * y)); // Z=1, T=xy
218
- }
219
- static fromHex(hex: string, zip215?: boolean): Point {
220
- return Point.fromBytes(hexToBytes(hex), zip215);
221
- }
222
- get x(): bigint {
223
- return this.toAffine().x;
224
- }
225
- get y(): bigint {
226
- return this.toAffine().y;
227
- }
228
- /** Checks if the point is valid and on-curve. */
229
- assertValidity(): this {
230
- const a = _a;
231
- const d = _d;
232
- const p = this;
233
- if (p.is0()) return err('bad point: ZERO'); // TODO: optimize, with vars below?
234
- // Equation in affine coordinates: ax² + y² = 1 + dx²y²
235
- // Equation in projective coordinates (X/Z, Y/Z, Z): (aX² + Y²)Z² = Z⁴ + dX²Y²
236
- const { X, Y, Z, T } = p;
237
- const X2 = M(X * X); // X²
238
- const Y2 = M(Y * Y); // Y²
239
- const Z2 = M(Z * Z); // Z²
240
- const Z4 = M(Z2 * Z2); // Z⁴
241
- const aX2 = M(X2 * a); // aX²
242
- const left = M(Z2 * M(aX2 + Y2)); // (aX² + Y²)Z²
243
- const right = M(Z4 + M(d * M(X2 * Y2))); // Z⁴ + dX²Y²
244
- if (left !== right) return err('bad point: equation left != right (1)');
245
- // In Extended coordinates we also have T, which is x*y=T/Z: check X*Y == Z*T
246
- const XY = M(X * Y);
247
- const ZT = M(Z * T);
248
- if (XY !== ZT) return err('bad point: equation left != right (2)');
249
- return this;
250
- }
251
- /** Equality check: compare points P&Q. */
252
- equals(other: Point): boolean {
253
- const { X: X1, Y: Y1, Z: Z1 } = this;
254
- const { X: X2, Y: Y2, Z: Z2 } = apoint(other); // checks class equality
255
- const X1Z2 = M(X1 * Z2);
256
- const X2Z1 = M(X2 * Z1);
257
- const Y1Z2 = M(Y1 * Z2);
258
- const Y2Z1 = M(Y2 * Z1);
259
- return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
260
- }
261
- is0(): boolean {
262
- return this.equals(I);
263
- }
264
- /** Flip point over y coordinate. */
265
- negate(): Point {
266
- return new Point(M(-this.X), this.Y, this.Z, M(-this.T));
267
- }
268
- /** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
269
- double(): Point {
270
- const { X: X1, Y: Y1, Z: Z1 } = this;
271
- const a = _a;
272
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
273
- const A = M(X1 * X1);
274
- const B = M(Y1 * Y1);
275
- const C = M(2n * M(Z1 * Z1));
276
- const D = M(a * A);
277
- const x1y1 = X1 + Y1;
278
- const E = M(M(x1y1 * x1y1) - A - B);
279
- const G = D + B;
280
- const F = G - C;
281
- const H = D - B;
282
- const X3 = M(E * F);
283
- const Y3 = M(G * H);
284
- const T3 = M(E * H);
285
- const Z3 = M(F * G);
286
- return new Point(X3, Y3, Z3, T3);
287
- }
288
- /** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
289
- add(other: Point): Point {
290
- const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
291
- const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other); // doesn't check if other on-curve
292
- const a = _a;
293
- const d = _d;
294
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html#addition-add-2008-hwcd-3
295
- const A = M(X1 * X2);
296
- const B = M(Y1 * Y2);
297
- const C = M(T1 * d * T2);
298
- const D = M(Z1 * Z2);
299
- const E = M((X1 + Y1) * (X2 + Y2) - A - B);
300
- const F = M(D - C);
301
- const G = M(D + C);
302
- const H = M(B - a * A);
303
- const X3 = M(E * F);
304
- const Y3 = M(G * H);
305
- const T3 = M(E * H);
306
- const Z3 = M(F * G);
307
- return new Point(X3, Y3, Z3, T3);
308
- }
309
- subtract(other: Point): Point {
310
- return this.add(apoint(other).negate());
311
- }
312
- /**
313
- * Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
314
- * Uses {@link wNAF} for base point.
315
- * Uses fake point to mitigate side-channel leakage.
316
- * @param n scalar by which point is multiplied
317
- * @param safe safe mode guards against timing attacks; unsafe mode is faster
318
- */
319
- multiply(n: bigint, safe = true): Point {
320
- if (!safe && (n === 0n || this.is0())) return I;
321
- assertRange(n, 1n, N);
322
- if (n === 1n) return this;
323
- if (this.equals(G)) return wNAF(n).p;
324
- // init result point & fake point
325
- let p = I;
326
- let f = G;
327
- for (let d: Point = this; n > 0n; d = d.double(), n >>= 1n) {
328
- // if bit is present, add to point
329
- // if not present, add to fake, for timing safety
330
- if (n & 1n) p = p.add(d);
331
- else if (safe) f = f.add(d);
332
- }
333
- return p;
334
- }
335
- multiplyUnsafe(scalar: bigint): Point {
336
- return this.multiply(scalar, false);
337
- }
338
- /** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
339
- toAffine(): AffinePoint {
340
- const { X, Y, Z } = this;
341
- // fast-paths for ZERO point OR Z=1
342
- if (this.equals(I)) return { x: 0n, y: 1n };
343
- const iz = invert(Z, P);
344
- // (Z * Z^-1) must be 1, otherwise bad math
345
- if (M(Z * iz) !== 1n) err('invalid inverse');
346
- // x = X*Z^-1; y = Y*Z^-1
347
- const x = M(X * iz);
348
- const y = M(Y * iz);
349
- return { x, y };
350
- }
351
- toBytes(): Bytes {
352
- const { x, y } = this.assertValidity().toAffine();
353
- const b = numTo32bLE(y);
354
- // store sign in first LE byte
355
- b[31] |= x & 1n ? 0x80 : 0;
356
- return b;
357
- }
358
- toHex(): string {
359
- return bytesToHex(this.toBytes());
360
- }
361
-
362
- clearCofactor(): Point {
363
- return this.multiply(big(h), false);
364
- }
365
- isSmallOrder(): boolean {
366
- return this.clearCofactor().is0();
367
- }
368
- isTorsionFree(): boolean {
369
- // Multiply by big number N. We can't `mul(N)` because of checks. Instead, we `mul(N/2)*2+1`
370
- let p = this.multiply(N / 2n, false).double();
371
- if (N % 2n) p = p.add(this);
372
- return p.is0();
373
- }
374
- }
375
- /** Generator / base point */
376
- const G: Point = new Point(Gx, Gy, 1n, M(Gx * Gy));
377
- /** Identity / zero point */
378
- const I: Point = new Point(0n, 1n, 1n, 0n);
379
- // Static aliases
380
- Point.BASE = G;
381
- Point.ZERO = I;
382
-
383
- const numTo32bLE = (num: bigint) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
384
- const bytesToNumLE = (b: Bytes): bigint => big('0x' + bytesToHex(u8fr(abytes(b)).reverse()));
385
-
386
- const pow2 = (x: bigint, power: bigint): bigint => {
387
- // pow2(x, 4) == x^(2^4)
388
- let r = x;
389
- while (power-- > 0n) {
390
- r *= r;
391
- r %= P;
392
- }
393
- return r;
394
- };
395
-
396
- // prettier-ignore
397
- const pow_2_252_3 = (x: bigint) => { // x^(2^252-3) unrolled util for square root
398
- const x2 = (x * x) % P; // x^2, bits 1
399
- const b2 = (x2 * x) % P; // x^3, bits 11
400
- const b4 = (pow2(b2, 2n) * b2) % P; // x^(2^4-1), bits 1111
401
- const b5 = (pow2(b4, 1n) * x) % P; // x^(2^5-1), bits 11111
402
- const b10 = (pow2(b5, 5n) * b5) % P; // x^(2^10)
403
- const b20 = (pow2(b10, 10n) * b10) % P; // x^(2^20)
404
- const b40 = (pow2(b20, 20n) * b20) % P; // x^(2^40)
405
- const b80 = (pow2(b40, 40n) * b40) % P; // x^(2^80)
406
- const b160 = (pow2(b80, 80n) * b80) % P; // x^(2^160)
407
- const b240 = (pow2(b160, 80n) * b80) % P; // x^(2^240)
408
- const b250 = (pow2(b240, 10n) * b10) % P; // x^(2^250)
409
- const pow_p_5_8 = (pow2(b250, 2n) * x) % P; // < To pow to (p+3)/8, multiply it by x.
410
- return { pow_p_5_8, b2 };
411
- }
412
- const RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n; // √-1
413
- // for sqrt comp
414
- // prettier-ignore
415
- const uvRatio = (u: bigint, v: bigint): { isValid: boolean, value: bigint } => {
416
- const v3 = M(v * v * v); // v³
417
- const v7 = M(v3 * v3 * v); // v⁷
418
- const pow = pow_2_252_3(u * v7).pow_p_5_8; // (uv⁷)^(p-5)/8
419
- let x = M(u * v3 * pow); // (uv³)(uv⁷)^(p-5)/8
420
- const vx2 = M(v * x * x); // vx²
421
- const root1 = x; // First root candidate
422
- const root2 = M(x * RM1); // Second root candidate; RM1 is √-1
423
- const useRoot1 = vx2 === u; // If vx² = u (mod p), x is a square root
424
- const useRoot2 = vx2 === M(-u); // If vx² = -u, set x <-- x * 2^((p-1)/4)
425
- const noRoot = vx2 === M(-u * RM1); // There is no valid root, vx² = -u√-1
426
- if (useRoot1) x = root1;
427
- if (useRoot2 || noRoot) x = root2; // We return root2 anyway, for const-time
428
- if ((M(x) & 1n) === 1n) x = M(-x); // edIsNegative
429
- return { isValid: useRoot1 || useRoot2, value: x };
430
- }
431
- // N == L, just weird naming
432
- const modL_LE = (hash: Bytes): bigint => modN(bytesToNumLE(hash)); // modulo L; but little-endian
433
- /** hashes.sha512 should conform to the interface. */
434
- // TODO: rename
435
- const sha512a = (...m: Bytes[]) => hashes.sha512Async(concatBytes(...m)); // Async SHA512
436
- const sha512s = (...m: Bytes[]) => callHash('sha512')(concatBytes(...m));
437
- type ExtK = { head: Bytes; prefix: Bytes; scalar: bigint; point: Point; pointBytes: Bytes };
438
-
439
- // RFC8032 5.1.5
440
- const hash2extK = (hashed: Bytes): ExtK => {
441
- // slice creates a copy, unlike subarray
442
- const head = hashed.slice(0, L);
443
- head[0] &= 248; // Clamp bits: 0b1111_1000
444
- head[31] &= 127; // 0b0111_1111
445
- head[31] |= 64; // 0b0100_0000
446
- const prefix = hashed.slice(L, L2); // secret key "prefix"
447
- const scalar = modL_LE(head); // modular division over curve order
448
- const point = G.multiply(scalar); // public key point
449
- const pointBytes = point.toBytes(); // point serialized to Uint8Array
450
- return { head, prefix, scalar, point, pointBytes };
451
- };
452
-
453
- // RFC8032 5.1.5; getPublicKey async, sync. Hash priv key and extract point.
454
- const getExtendedPublicKeyAsync = (secretKey: Bytes): Promise<ExtK> =>
455
- sha512a(abytes(secretKey, L)).then(hash2extK);
456
- const getExtendedPublicKey = (secretKey: Bytes): ExtK => hash2extK(sha512s(abytes(secretKey, L)));
457
- /** Creates 32-byte ed25519 public key from 32-byte secret key. Async. */
458
- const getPublicKeyAsync = (secretKey: Bytes): Promise<Bytes> =>
459
- getExtendedPublicKeyAsync(secretKey).then((p) => p.pointBytes);
460
- /** Creates 32-byte ed25519 public key from 32-byte secret key. To use, set `hashes.sha512` first. */
461
- const getPublicKey = (priv: Bytes): Bytes => getExtendedPublicKey(priv).pointBytes;
462
- type Finishable<T> = {
463
- // Reduces logic duplication between
464
- hashable: Bytes;
465
- finish: (hashed: Bytes) => T; // sync & async versions of sign(), verify()
466
- };
467
- const hashFinishA = <T>(res: Finishable<T>): Promise<T> => sha512a(res.hashable).then(res.finish);
468
- const hashFinishS = <T>(res: Finishable<T>): T => res.finish(sha512s(res.hashable));
469
- // Code, shared between sync & async sign
470
- const _sign = (e: ExtK, rBytes: Bytes, msg: Bytes): Finishable<Bytes> => {
471
- const { pointBytes: P, scalar: s } = e;
472
- const r = modL_LE(rBytes); // r was created outside, reduce it modulo L
473
- const R = G.multiply(r).toBytes(); // R = [r]B
474
- const hashable = concatBytes(R, P, msg); // dom2(F, C) || R || A || PH(M)
475
- const finish = (hashed: Bytes): Bytes => {
476
- // k = SHA512(dom2(F, C) || R || A || PH(M))
477
- const S = modN(r + modL_LE(hashed) * s); // S = (r + k * s) mod L; 0 <= s < l
478
- return abytes(concatBytes(R, numTo32bLE(S)), L2); // 64-byte sig: 32b R.x + 32b LE(S)
479
- };
480
- return { hashable, finish };
481
- };
482
- /**
483
- * Signs message using secret key. Async.
484
- * Follows RFC8032 5.1.6.
485
- */
486
- const signAsync = async (message: Bytes, secretKey: Bytes): Promise<Bytes> => {
487
- const m = abytes(message);
488
- const e = await getExtendedPublicKeyAsync(secretKey);
489
- const rBytes = await sha512a(e.prefix, m); // r = SHA512(dom2(F, C) || prefix || PH(M))
490
- return hashFinishA(_sign(e, rBytes, m)); // gen R, k, S, then 64-byte signature
491
- };
492
- /**
493
- * Signs message using secret key. To use, set `hashes.sha512` first.
494
- * Follows RFC8032 5.1.6.
495
- */
496
- const sign = (message: Bytes, secretKey: Bytes): Bytes => {
497
- const m = abytes(message);
498
- const e = getExtendedPublicKey(secretKey);
499
- const rBytes = sha512s(e.prefix, m); // r = SHA512(dom2(F, C) || prefix || PH(M))
500
- return hashFinishS(_sign(e, rBytes, m)); // gen R, k, S, then 64-byte signature
501
- };
502
- /** Verification options. zip215: true (default) follows ZIP215 spec. false would follow RFC8032. */
503
- export type EdDSAVerifyOpts = { zip215?: boolean };
504
- const defaultVerifyOpts: EdDSAVerifyOpts = { zip215: true };
505
- const _verify = (
506
- sig: Bytes,
507
- msg: Bytes,
508
- pub: Bytes,
509
- opts: EdDSAVerifyOpts = defaultVerifyOpts
510
- ): Finishable<boolean> => {
511
- sig = abytes(sig, L2); // Signature hex str/Bytes, must be 64 bytes
512
- msg = abytes(msg); // Message hex str/Bytes
513
- pub = abytes(pub, L);
514
- const { zip215 } = opts; // switch between zip215 and rfc8032 verif
515
- let A: Point;
516
- let R: Point;
517
- let s: bigint;
518
- let SB: Point;
519
- let hashable: Bytes = Uint8Array.of();
520
- try {
521
- A = Point.fromBytes(pub, zip215); // public key A decoded
522
- R = Point.fromBytes(sig.slice(0, L), zip215); // 0 <= R < 2^256: ZIP215 R can be >= P
523
- s = bytesToNumLE(sig.slice(L, L2)); // Decode second half as an integer S
524
- SB = G.multiply(s, false); // in the range 0 <= s < L
525
- hashable = concatBytes(R.toBytes(), A.toBytes(), msg); // dom2(F, C) || R || A || PH(M)
526
- } catch (error) {}
527
- const finish = (hashed: Bytes): boolean => {
528
- // k = SHA512(dom2(F, C) || R || A || PH(M))
529
- if (SB == null) return false; // false if try-catch catched an error
530
- if (!zip215 && A.isSmallOrder()) return false; // false for SBS: Strongly Binding Signature
531
- const k = modL_LE(hashed); // decode in little-endian, modulo L
532
- const RkA = R.add(A.multiply(k, false)); // [8]R + [8][k]A'
533
- return RkA.add(SB.negate()).clearCofactor().is0(); // [8][S]B = [8]R + [8][k]A'
534
- };
535
- return { hashable, finish };
536
- };
537
-
538
- /** Verifies signature on message and public key. Async. Follows RFC8032 5.1.7. */
539
- const verifyAsync = async (
540
- signature: Bytes,
541
- message: Bytes,
542
- publicKey: Bytes,
543
- opts: EdDSAVerifyOpts = defaultVerifyOpts
544
- ): Promise<boolean> => hashFinishA(_verify(signature, message, publicKey, opts));
545
- /** Verifies signature on message and public key. To use, set `hashes.sha512` first. Follows RFC8032 5.1.7. */
546
- const verify = (
547
- signature: Bytes,
548
- message: Bytes,
549
- publicKey: Bytes,
550
- opts: EdDSAVerifyOpts = defaultVerifyOpts
551
- ): boolean => hashFinishS(_verify(signature, message, publicKey, opts));
552
-
553
- /** Math, hex, byte helpers. Not in `utils` because utils share API with noble-curves. */
554
- const etc = {
555
- bytesToHex: bytesToHex as typeof bytesToHex,
556
- hexToBytes: hexToBytes as typeof hexToBytes,
557
- concatBytes: concatBytes as typeof concatBytes,
558
- mod: M as typeof M,
559
- invert: invert as typeof invert,
560
- randomBytes: randomBytes as typeof randomBytes,
561
- };
562
- const hashes = {
563
- sha512Async: async (message: Bytes): Promise<Bytes> => {
564
- const s = subtle();
565
- const m = concatBytes(message);
566
- return u8n(await s.digest('SHA-512', m.buffer));
567
- },
568
- sha512: undefined as undefined | ((message: Bytes) => Bytes),
569
- };
570
-
571
- // FIPS 186 B.4.1 compliant key generation produces private keys
572
- // with modulo bias being neglible. takes >N+16 bytes, returns (hash mod n-1)+1
573
- const randomSecretKey = (seed: Bytes = randomBytes(L)): Bytes => seed;
574
-
575
- type KeysSecPub = { secretKey: Bytes; publicKey: Bytes };
576
- const keygen = (seed?: Bytes): KeysSecPub => {
577
- const secretKey = randomSecretKey(seed);
578
- const publicKey = getPublicKey(secretKey);
579
- return { secretKey, publicKey };
580
- };
581
- const keygenAsync = async (seed?: Bytes): Promise<KeysSecPub> => {
582
- const secretKey = randomSecretKey(seed);
583
- const publicKey = await getPublicKeyAsync(secretKey);
584
- return { secretKey, publicKey };
585
- };
586
-
587
- /** ed25519-specific key utilities. */
588
- const utils = {
589
- getExtendedPublicKeyAsync: getExtendedPublicKeyAsync as typeof getExtendedPublicKeyAsync,
590
- getExtendedPublicKey: getExtendedPublicKey as typeof getExtendedPublicKey,
591
- randomSecretKey: randomSecretKey as typeof randomSecretKey,
592
- };
593
-
594
- // ## Precomputes
595
- // --------------
596
-
597
- const W = 8; // W is window size
598
- const scalarBits = 256;
599
- const pwindows = Math.ceil(scalarBits / W) + 1; // 33 for W=8, NOT 32 - see wNAF loop
600
- const pwindowSize = 2 ** (W - 1); // 128 for W=8
601
- const precompute = () => {
602
- const points: Point[] = [];
603
- let p = G;
604
- let b = p;
605
- for (let w = 0; w < pwindows; w++) {
606
- b = p;
607
- points.push(b);
608
- for (let i = 1; i < pwindowSize; i++) {
609
- b = b.add(p);
610
- points.push(b);
611
- } // i=1, bc we skip 0
612
- p = b.double();
613
- }
614
- return points;
615
- };
616
- let Gpows: Point[] | undefined = undefined; // precomputes for base point G
617
- // const-time negate
618
- const ctneg = (cnd: boolean, p: Point) => {
619
- const n = p.negate();
620
- return cnd ? n : p;
621
- };
622
-
623
- /**
624
- * Precomputes give 12x faster getPublicKey(), 10x sign(), 2x verify() by
625
- * caching multiples of G (base point). Cache is stored in 32MB of RAM.
626
- * Any time `G.multiply` is done, precomputes are used.
627
- * Not used for getSharedSecret, which instead multiplies random pubkey `P.multiply`.
628
- *
629
- * w-ary non-adjacent form (wNAF) precomputation method is 10% slower than windowed method,
630
- * but takes 2x less RAM. RAM reduction is possible by utilizing `.subtract`.
631
- *
632
- * !! Precomputes can be disabled by commenting-out call of the wNAF() inside Point#multiply().
633
- */
634
- const wNAF = (n: bigint): { p: Point; f: Point } => {
635
- const comp = Gpows || (Gpows = precompute());
636
- let p = I;
637
- let f = G; // f must be G, or could become I in the end
638
- const pow_2_w = 2 ** W; // 256 for W=8
639
- const maxNum = pow_2_w; // 256 for W=8
640
- const mask = big(pow_2_w - 1); // 255 for W=8 == mask 0b11111111
641
- const shiftBy = big(W); // 8 for W=8
642
- for (let w = 0; w < pwindows; w++) {
643
- let wbits = Number(n & mask); // extract W bits.
644
- n >>= shiftBy; // shift number by W bits.
645
- // We use negative indexes to reduce size of precomputed table by 2x.
646
- // Instead of needing precomputes 0..256, we only calculate them for 0..128.
647
- // If an index > 128 is found, we do (256-index) - where 256 is next window.
648
- // Naive: index +127 => 127, +224 => 224
649
- // Optimized: index +127 => 127, +224 => 256-32
650
- if (wbits > pwindowSize) {
651
- wbits -= maxNum;
652
- n += 1n;
653
- }
654
- const off = w * pwindowSize;
655
- const offF = off; // offsets, evaluate both
656
- const offP = off + Math.abs(wbits) - 1;
657
- const isEven = w % 2 !== 0; // conditions, evaluate both
658
- const isNeg = wbits < 0;
659
- if (wbits === 0) {
660
- // off == I: can't add it. Adding random offF instead.
661
- f = f.add(ctneg(isEven, comp[offF])); // bits are 0: add garbage to fake point
662
- } else {
663
- p = p.add(ctneg(isNeg, comp[offP])); // bits are 1: add to result point
664
- }
665
- }
666
- if (n !== 0n) err('invalid wnaf');
667
- return { p, f }; // return both real and fake points for JIT
668
- };
669
-
670
- // !! Remove the export to easily use in REPL / browser console
671
- export {
672
- etc,
673
- getPublicKey,
674
- getPublicKeyAsync,
675
- hash,
676
- hashes,
677
- keygen,
678
- keygenAsync,
679
- Point,
680
- sign,
681
- signAsync,
682
- utils,
683
- verify,
684
- verifyAsync,
685
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@noble/ed25519/package.json DELETED
@@ -1,55 +0,0 @@
1
- {
2
- "name": "@noble/ed25519",
3
- "version": "3.0.0",
4
- "description": "Fastest 5KB JS implementation of ed25519 EDDSA signatures compliant with RFC8032, FIPS 186-5 & ZIP215",
5
- "files": [
6
- "index.js",
7
- "index.d.ts",
8
- "index.ts"
9
- ],
10
- "devDependencies": {
11
- "@noble/hashes": "2.0.0",
12
- "@paulmillr/jsbt": "0.4.4",
13
- "@types/node": "24.2.1",
14
- "fast-check": "4.2.0",
15
- "prettier": "3.6.2",
16
- "typescript": "5.9.2"
17
- },
18
- "scripts": {
19
- "build": "tsc",
20
- "build:release": "npx --no @paulmillr/jsbt esbuild test/build",
21
- "bench": "node test/benchmark.ts",
22
- "format": "prettier --write 'index.ts' 'test/**/*.{js,ts}'",
23
- "test": "node --experimental-strip-types --disable-warning=ExperimentalWarning test/index.ts",
24
- "test:bun": "bun test/index.ts",
25
- "test:deno": "deno --allow-env --allow-read test/index.ts",
26
- "test:node20": "cd test; npx tsc; node compiled/test/index.js"
27
- },
28
- "keywords": [
29
- "ed25519",
30
- "rfc8032",
31
- "fips186",
32
- "signature",
33
- "eddsa",
34
- "noble",
35
- "cryptography",
36
- "elliptic curve",
37
- "rfc7748",
38
- "zip215",
39
- "x25519",
40
- "curve25519"
41
- ],
42
- "homepage": "https://paulmillr.com/noble/",
43
- "funding": "https://paulmillr.com/funding/",
44
- "repository": {
45
- "type": "git",
46
- "url": "git+https://github.com/paulmillr/noble-ed25519.git"
47
- },
48
- "type": "module",
49
- "main": "index.js",
50
- "module": "index.js",
51
- "types": "index.d.ts",
52
- "sideEffects": false,
53
- "author": "Paul Miller (https://paulmillr.com)",
54
- "license": "MIT"
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/README.md DELETED
@@ -1,48 +0,0 @@
1
- # @vitest/browser-playwright
2
-
3
- [![NPM version](https://img.shields.io/npm/v/@vitest/browser-playwright?color=a1b858&label=)](https://www.npmjs.com/package/@vitest/browser-playwright)
4
-
5
- Run your Vitest [browser tests](https://vitest.dev/guide/browser/) using [playwright](https://playwright.dev/docs/api/class-playwright) API. Note that Vitest does not use playwright as a test runner, but only as a browser provider.
6
-
7
- We recommend using this package if you are already using playwright in your project or if you do not have any E2E tests yet.
8
-
9
- ## Installation
10
-
11
- Install the package with your favorite package manager:
12
-
13
- ```sh
14
- npm install -D @vitest/browser-playwright
15
- # or
16
- yarn add -D @vitest/browser-playwright
17
- # or
18
- pnpm add -D @vitest/browser-playwright
19
- ```
20
-
21
- Then specify it in the `browser.provider` field of your Vitest configuration:
22
-
23
- ```ts
24
- // vitest.config.ts
25
- import { defineConfig } from 'vitest/config'
26
- import { playwright } from '@vitest/browser-playwright'
27
-
28
- export default defineConfig({
29
- test: {
30
- browser: {
31
- provider: playwright({
32
- // ...custom playwright options
33
- }),
34
- instances: [
35
- { browser: 'chromium' },
36
- ],
37
- },
38
- },
39
- })
40
- ```
41
-
42
- Then run Vitest in the browser mode:
43
-
44
- ```sh
45
- npx vitest --browser
46
- ```
47
-
48
- [GitHub](https://github.com/vitest-dev/vitest/tree/main/packages/browser-playwright) | [Documentation](https://vitest.dev/config/browser/playwright)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/context.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '@vitest/browser/context'
 
 
ui/node_modules/@vitest/browser-playwright/dist/index.d.ts DELETED
@@ -1,106 +0,0 @@
1
- import { CustomComparatorsRegistry } from '@vitest/browser';
2
- export { defineBrowserCommand } from '@vitest/browser';
3
- import { Page, Frame, FrameLocator, BrowserContext, CDPSession, LaunchOptions, ConnectOptions, BrowserContextOptions, Browser } from 'playwright';
4
- import { ScreenshotMatcherOptions, ScreenshotComparatorRegistry, Locator } from 'vitest/browser';
5
- import { BrowserProviderOption, BrowserProvider, BrowserModuleMocker, TestProject, CDPSession as CDPSession$1 } from 'vitest/node';
6
-
7
- declare const playwrightBrowsers: readonly ["firefox", "webkit", "chromium"];
8
- type PlaywrightBrowser = (typeof playwrightBrowsers)[number];
9
- interface PlaywrightProviderOptions {
10
- /**
11
- * The options passed down to [`playwright.connect`](https://playwright.dev/docs/api/class-browsertype#browser-type-launch) method.
12
- * @see {@link https://playwright.dev/docs/api/class-browsertype#browser-type-launch}
13
- */
14
- launchOptions?: Omit<LaunchOptions, "tracesDir">;
15
- /**
16
- * The options passed down to [`playwright.connect`](https://playwright.dev/docs/api/class-browsertype#browser-type-connect) method.
17
- *
18
- * This is used only if you connect remotely to the playwright instance via a WebSocket connection.
19
- * @see {@link https://playwright.dev/docs/api/class-browsertype#browser-type-connect}
20
- */
21
- connectOptions?: ConnectOptions & {
22
- wsEndpoint: string;
23
- };
24
- /**
25
- * The options passed down to [`browser.newContext`](https://playwright.dev/docs/api/class-browser#browser-new-context) method.
26
- * @see {@link https://playwright.dev/docs/api/class-browser#browser-new-context}
27
- */
28
- contextOptions?: Omit<BrowserContextOptions, "ignoreHTTPSErrors" | "serviceWorkers">;
29
- /**
30
- * The maximum time in milliseconds to wait for `userEvent` action to complete.
31
- * @default 0 (no timeout)
32
- */
33
- actionTimeout?: number;
34
- }
35
- declare function playwright(options?: PlaywrightProviderOptions): BrowserProviderOption<PlaywrightProviderOptions>;
36
- declare class PlaywrightBrowserProvider implements BrowserProvider {
37
- private project;
38
- private options;
39
- name: "playwright";
40
- supportsParallelism: boolean;
41
- browser: Browser | null;
42
- contexts: Map<string, BrowserContext>;
43
- pages: Map<string, Page>;
44
- mocker: BrowserModuleMocker;
45
- browserName: PlaywrightBrowser;
46
- private browserPromise;
47
- private closing;
48
- tracingContexts: Set<string>;
49
- pendingTraces: Map<string, string>;
50
- initScripts: string[];
51
- constructor(project: TestProject, options: PlaywrightProviderOptions);
52
- private openBrowser;
53
- private createMocker;
54
- private createContext;
55
- getPage(sessionId: string): Page;
56
- getCommandsContext(sessionId: string): {
57
- page: Page;
58
- context: BrowserContext;
59
- frame: () => Promise<Frame>;
60
- readonly iframe: FrameLocator;
61
- };
62
- private openBrowserPage;
63
- openPage(sessionId: string, url: string): Promise<void>;
64
- private _throwIfClosing;
65
- getCDPSession(sessionid: string): Promise<CDPSession$1>;
66
- close(): Promise<void>;
67
- }
68
- declare module "vitest/node" {
69
- interface BrowserCommandContext {
70
- page: Page;
71
- frame(): Promise<Frame>;
72
- iframe: FrameLocator;
73
- context: BrowserContext;
74
- }
75
- interface _BrowserNames {
76
- playwright: PlaywrightBrowser;
77
- }
78
- interface ToMatchScreenshotOptions extends Omit<ScreenshotMatcherOptions, "comparatorName" | "comparatorOptions">, CustomComparatorsRegistry {}
79
- interface ToMatchScreenshotComparators extends ScreenshotComparatorRegistry {}
80
- }
81
- type PWHoverOptions = NonNullable<Parameters<Page["hover"]>[1]>;
82
- type PWClickOptions = NonNullable<Parameters<Page["click"]>[1]>;
83
- type PWDoubleClickOptions = NonNullable<Parameters<Page["dblclick"]>[1]>;
84
- type PWFillOptions = NonNullable<Parameters<Page["fill"]>[2]>;
85
- type PWScreenshotOptions = NonNullable<Parameters<Page["screenshot"]>[0]>;
86
- type PWSelectOptions = NonNullable<Parameters<Page["selectOption"]>[2]>;
87
- type PWDragAndDropOptions = NonNullable<Parameters<Page["dragAndDrop"]>[2]>;
88
- type PWSetInputFiles = NonNullable<Parameters<Page["setInputFiles"]>[2]>;
89
- type PWCDPSession = CDPSession;
90
- declare module "vitest/browser" {
91
- interface UserEventHoverOptions extends PWHoverOptions {}
92
- interface UserEventClickOptions extends PWClickOptions {}
93
- interface UserEventDoubleClickOptions extends PWDoubleClickOptions {}
94
- interface UserEventTripleClickOptions extends PWClickOptions {}
95
- interface UserEventFillOptions extends PWFillOptions {}
96
- interface UserEventSelectOptions extends PWSelectOptions {}
97
- interface UserEventDragAndDropOptions extends PWDragAndDropOptions {}
98
- interface UserEventUploadOptions extends PWSetInputFiles {}
99
- interface ScreenshotOptions extends Omit<PWScreenshotOptions, "mask"> {
100
- mask?: ReadonlyArray<Element | Locator> | undefined;
101
- }
102
- interface CDPSession extends PWCDPSession {}
103
- }
104
-
105
- export { PlaywrightBrowserProvider, playwright };
106
- export type { PlaywrightProviderOptions };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/dist/index.js DELETED
@@ -1,1112 +0,0 @@
1
- import { parseKeyDef, resolveScreenshotPath, defineBrowserProvider } from '@vitest/browser';
2
- export { defineBrowserCommand } from '@vitest/browser';
3
- import { createManualModuleSource } from '@vitest/mocker/node';
4
- import c from 'tinyrainbow';
5
- import { createDebugger, isCSSRequest } from 'vitest/node';
6
- import { mkdir, unlink } from 'node:fs/promises';
7
- import { fileURLToPath } from 'node:url';
8
-
9
- const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
10
- function normalizeWindowsPath(input = "") {
11
- if (!input) {
12
- return input;
13
- }
14
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
15
- }
16
-
17
- const _UNC_REGEX = /^[/\\]{2}/;
18
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
19
- const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
20
- const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
21
- const normalize = function(path) {
22
- if (path.length === 0) {
23
- return ".";
24
- }
25
- path = normalizeWindowsPath(path);
26
- const isUNCPath = path.match(_UNC_REGEX);
27
- const isPathAbsolute = isAbsolute(path);
28
- const trailingSeparator = path[path.length - 1] === "/";
29
- path = normalizeString(path, !isPathAbsolute);
30
- if (path.length === 0) {
31
- if (isPathAbsolute) {
32
- return "/";
33
- }
34
- return trailingSeparator ? "./" : ".";
35
- }
36
- if (trailingSeparator) {
37
- path += "/";
38
- }
39
- if (_DRIVE_LETTER_RE.test(path)) {
40
- path += "/";
41
- }
42
- if (isUNCPath) {
43
- if (!isPathAbsolute) {
44
- return `//./${path}`;
45
- }
46
- return `//${path}`;
47
- }
48
- return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
49
- };
50
- function cwd() {
51
- if (typeof process !== "undefined" && typeof process.cwd === "function") {
52
- return process.cwd().replace(/\\/g, "/");
53
- }
54
- return "/";
55
- }
56
- const resolve = function(...arguments_) {
57
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
58
- let resolvedPath = "";
59
- let resolvedAbsolute = false;
60
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
61
- const path = index >= 0 ? arguments_[index] : cwd();
62
- if (!path || path.length === 0) {
63
- continue;
64
- }
65
- resolvedPath = `${path}/${resolvedPath}`;
66
- resolvedAbsolute = isAbsolute(path);
67
- }
68
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
69
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
70
- return `/${resolvedPath}`;
71
- }
72
- return resolvedPath.length > 0 ? resolvedPath : ".";
73
- };
74
- function normalizeString(path, allowAboveRoot) {
75
- let res = "";
76
- let lastSegmentLength = 0;
77
- let lastSlash = -1;
78
- let dots = 0;
79
- let char = null;
80
- for (let index = 0; index <= path.length; ++index) {
81
- if (index < path.length) {
82
- char = path[index];
83
- } else if (char === "/") {
84
- break;
85
- } else {
86
- char = "/";
87
- }
88
- if (char === "/") {
89
- if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
90
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
91
- if (res.length > 2) {
92
- const lastSlashIndex = res.lastIndexOf("/");
93
- if (lastSlashIndex === -1) {
94
- res = "";
95
- lastSegmentLength = 0;
96
- } else {
97
- res = res.slice(0, lastSlashIndex);
98
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
99
- }
100
- lastSlash = index;
101
- dots = 0;
102
- continue;
103
- } else if (res.length > 0) {
104
- res = "";
105
- lastSegmentLength = 0;
106
- lastSlash = index;
107
- dots = 0;
108
- continue;
109
- }
110
- }
111
- if (allowAboveRoot) {
112
- res += res.length > 0 ? "/.." : "..";
113
- lastSegmentLength = 2;
114
- }
115
- } else {
116
- if (res.length > 0) {
117
- res += `/${path.slice(lastSlash + 1, index)}`;
118
- } else {
119
- res = path.slice(lastSlash + 1, index);
120
- }
121
- lastSegmentLength = index - lastSlash - 1;
122
- }
123
- lastSlash = index;
124
- dots = 0;
125
- } else if (char === "." && dots !== -1) {
126
- ++dots;
127
- } else {
128
- dots = -1;
129
- }
130
- }
131
- return res;
132
- }
133
- const isAbsolute = function(p) {
134
- return _IS_ABSOLUTE_RE.test(p);
135
- };
136
- const relative = function(from, to) {
137
- const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
138
- const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
139
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
140
- return _to.join("/");
141
- }
142
- const _fromCopy = [..._from];
143
- for (const segment of _fromCopy) {
144
- if (_to[0] !== segment) {
145
- break;
146
- }
147
- _from.shift();
148
- _to.shift();
149
- }
150
- return [..._from.map(() => ".."), ..._to].join("/");
151
- };
152
- const dirname = function(p) {
153
- const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
154
- if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
155
- segments[0] += "/";
156
- }
157
- return segments.join("/") || (isAbsolute(p) ? "/" : ".");
158
- };
159
- const basename = function(p, extension) {
160
- const segments = normalizeWindowsPath(p).split("/");
161
- let lastSegment = "";
162
- for (let i = segments.length - 1; i >= 0; i--) {
163
- const val = segments[i];
164
- if (val) {
165
- lastSegment = val;
166
- break;
167
- }
168
- }
169
- return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
170
- };
171
-
172
- const clear = async (context, selector) => {
173
- const { iframe } = context;
174
- const element = iframe.locator(selector);
175
- await element.clear();
176
- };
177
-
178
- const click = async (context, selector, options = {}) => {
179
- const tester = context.iframe;
180
- await tester.locator(selector).click(options);
181
- };
182
- const dblClick = async (context, selector, options = {}) => {
183
- const tester = context.iframe;
184
- await tester.locator(selector).dblclick(options);
185
- };
186
- const tripleClick = async (context, selector, options = {}) => {
187
- const tester = context.iframe;
188
- await tester.locator(selector).click({
189
- ...options,
190
- clickCount: 3
191
- });
192
- };
193
-
194
- const dragAndDrop = async (context, source, target, options_) => {
195
- const frame = await context.frame();
196
- await frame.dragAndDrop(source, target, options_);
197
- };
198
-
199
- const fill = async (context, selector, text, options = {}) => {
200
- const { iframe } = context;
201
- const element = iframe.locator(selector);
202
- await element.fill(text, options);
203
- };
204
-
205
- const hover = async (context, selector, options = {}) => {
206
- await context.iframe.locator(selector).hover(options);
207
- };
208
-
209
- const keyboard = async (context, text, state) => {
210
- const frame = await context.frame();
211
- await frame.evaluate(focusIframe);
212
- const pressed = new Set(state.unreleased);
213
- await keyboardImplementation(pressed, context.provider, context.sessionId, text, async () => {
214
- const frame = await context.frame();
215
- await frame.evaluate(selectAll);
216
- }, true);
217
- return { unreleased: Array.from(pressed) };
218
- };
219
- const keyboardCleanup = async (context, state) => {
220
- const { provider, sessionId } = context;
221
- if (!state.unreleased) {
222
- return;
223
- }
224
- const page = provider.getPage(sessionId);
225
- for (const key of state.unreleased) {
226
- await page.keyboard.up(key);
227
- }
228
- };
229
- // fallback to insertText for non US key
230
- // https://github.com/microsoft/playwright/blob/50775698ae13642742f2a1e8983d1d686d7f192d/packages/playwright-core/src/server/input.ts#L95
231
- const VALID_KEYS = new Set([
232
- "Escape",
233
- "F1",
234
- "F2",
235
- "F3",
236
- "F4",
237
- "F5",
238
- "F6",
239
- "F7",
240
- "F8",
241
- "F9",
242
- "F10",
243
- "F11",
244
- "F12",
245
- "Backquote",
246
- "`",
247
- "~",
248
- "Digit1",
249
- "1",
250
- "!",
251
- "Digit2",
252
- "2",
253
- "@",
254
- "Digit3",
255
- "3",
256
- "#",
257
- "Digit4",
258
- "4",
259
- "$",
260
- "Digit5",
261
- "5",
262
- "%",
263
- "Digit6",
264
- "6",
265
- "^",
266
- "Digit7",
267
- "7",
268
- "&",
269
- "Digit8",
270
- "8",
271
- "*",
272
- "Digit9",
273
- "9",
274
- "(",
275
- "Digit0",
276
- "0",
277
- ")",
278
- "Minus",
279
- "-",
280
- "_",
281
- "Equal",
282
- "=",
283
- "+",
284
- "Backslash",
285
- "\\",
286
- "|",
287
- "Backspace",
288
- "Tab",
289
- "KeyQ",
290
- "q",
291
- "Q",
292
- "KeyW",
293
- "w",
294
- "W",
295
- "KeyE",
296
- "e",
297
- "E",
298
- "KeyR",
299
- "r",
300
- "R",
301
- "KeyT",
302
- "t",
303
- "T",
304
- "KeyY",
305
- "y",
306
- "Y",
307
- "KeyU",
308
- "u",
309
- "U",
310
- "KeyI",
311
- "i",
312
- "I",
313
- "KeyO",
314
- "o",
315
- "O",
316
- "KeyP",
317
- "p",
318
- "P",
319
- "BracketLeft",
320
- "[",
321
- "{",
322
- "BracketRight",
323
- "]",
324
- "}",
325
- "CapsLock",
326
- "KeyA",
327
- "a",
328
- "A",
329
- "KeyS",
330
- "s",
331
- "S",
332
- "KeyD",
333
- "d",
334
- "D",
335
- "KeyF",
336
- "f",
337
- "F",
338
- "KeyG",
339
- "g",
340
- "G",
341
- "KeyH",
342
- "h",
343
- "H",
344
- "KeyJ",
345
- "j",
346
- "J",
347
- "KeyK",
348
- "k",
349
- "K",
350
- "KeyL",
351
- "l",
352
- "L",
353
- "Semicolon",
354
- ";",
355
- ":",
356
- "Quote",
357
- "'",
358
- "\"",
359
- "Enter",
360
- "\n",
361
- "\r",
362
- "ShiftLeft",
363
- "Shift",
364
- "KeyZ",
365
- "z",
366
- "Z",
367
- "KeyX",
368
- "x",
369
- "X",
370
- "KeyC",
371
- "c",
372
- "C",
373
- "KeyV",
374
- "v",
375
- "V",
376
- "KeyB",
377
- "b",
378
- "B",
379
- "KeyN",
380
- "n",
381
- "N",
382
- "KeyM",
383
- "m",
384
- "M",
385
- "Comma",
386
- ",",
387
- "<",
388
- "Period",
389
- ".",
390
- ">",
391
- "Slash",
392
- "/",
393
- "?",
394
- "ShiftRight",
395
- "ControlLeft",
396
- "Control",
397
- "MetaLeft",
398
- "Meta",
399
- "AltLeft",
400
- "Alt",
401
- "Space",
402
- " ",
403
- "AltRight",
404
- "AltGraph",
405
- "MetaRight",
406
- "ContextMenu",
407
- "ControlRight",
408
- "PrintScreen",
409
- "ScrollLock",
410
- "Pause",
411
- "PageUp",
412
- "PageDown",
413
- "Insert",
414
- "Delete",
415
- "Home",
416
- "End",
417
- "ArrowLeft",
418
- "ArrowUp",
419
- "ArrowRight",
420
- "ArrowDown",
421
- "NumLock",
422
- "NumpadDivide",
423
- "NumpadMultiply",
424
- "NumpadSubtract",
425
- "Numpad7",
426
- "Numpad8",
427
- "Numpad9",
428
- "Numpad4",
429
- "Numpad5",
430
- "Numpad6",
431
- "NumpadAdd",
432
- "Numpad1",
433
- "Numpad2",
434
- "Numpad3",
435
- "Numpad0",
436
- "NumpadDecimal",
437
- "NumpadEnter",
438
- "ControlOrMeta"
439
- ]);
440
- async function keyboardImplementation(pressed, provider, sessionId, text, selectAll, skipRelease) {
441
- const page = provider.getPage(sessionId);
442
- const actions = parseKeyDef(text);
443
- for (const { releasePrevious, releaseSelf, repeat, keyDef } of actions) {
444
- const key = keyDef.key;
445
- // TODO: instead of calling down/up for each key, join non special
446
- // together, and call `type` once for all non special keys,
447
- // and then `press` for special keys
448
- if (pressed.has(key)) {
449
- if (VALID_KEYS.has(key)) {
450
- await page.keyboard.up(key);
451
- }
452
- pressed.delete(key);
453
- }
454
- if (!releasePrevious) {
455
- if (key === "selectall") {
456
- await selectAll();
457
- continue;
458
- }
459
- for (let i = 1; i <= repeat; i++) {
460
- if (VALID_KEYS.has(key)) {
461
- await page.keyboard.down(key);
462
- } else {
463
- await page.keyboard.insertText(key);
464
- }
465
- }
466
- if (releaseSelf) {
467
- if (VALID_KEYS.has(key)) {
468
- await page.keyboard.up(key);
469
- }
470
- } else {
471
- pressed.add(key);
472
- }
473
- }
474
- }
475
- if (!skipRelease && pressed.size) {
476
- for (const key of pressed) {
477
- if (VALID_KEYS.has(key)) {
478
- await page.keyboard.up(key);
479
- }
480
- }
481
- }
482
- return { pressed };
483
- }
484
- function focusIframe() {
485
- if (!document.activeElement || document.activeElement.ownerDocument !== document || document.activeElement === document.body) {
486
- window.focus();
487
- }
488
- }
489
- function selectAll() {
490
- const element = document.activeElement;
491
- if (element && typeof element.select === "function") {
492
- element.select();
493
- }
494
- }
495
-
496
- /**
497
- * Takes a screenshot using the provided browser context and returns a buffer and the expected screenshot path.
498
- *
499
- * **Note**: the returned `path` indicates where the screenshot *might* be found.
500
- * It is not guaranteed to exist, especially if `options.save` is `false`.
501
- *
502
- * @throws {Error} If the function is not called within a test or if the browser provider does not support screenshots.
503
- */
504
- async function takeScreenshot(context, name, options) {
505
- if (!context.testPath) {
506
- throw new Error(`Cannot take a screenshot without a test path`);
507
- }
508
- const path = resolveScreenshotPath(context.testPath, name, context.project.config, options.path);
509
- // playwright does not need a screenshot path if we don't intend to save it
510
- let savePath;
511
- if (options.save) {
512
- savePath = normalize(path);
513
- await mkdir(dirname(savePath), { recursive: true });
514
- }
515
- const mask = options.mask?.map((selector) => context.iframe.locator(selector));
516
- if (options.element) {
517
- const { element: selector, ...config } = options;
518
- const element = context.iframe.locator(selector);
519
- const buffer = await element.screenshot({
520
- ...config,
521
- mask,
522
- path: savePath
523
- });
524
- return {
525
- buffer,
526
- path
527
- };
528
- }
529
- const buffer = await context.iframe.locator("body").screenshot({
530
- ...options,
531
- mask,
532
- path: savePath
533
- });
534
- return {
535
- buffer,
536
- path
537
- };
538
- }
539
-
540
- const selectOptions = async (context, selector, userValues, options = {}) => {
541
- const value = userValues;
542
- const { iframe } = context;
543
- const selectElement = iframe.locator(selector);
544
- const values = await Promise.all(value.map(async (v) => {
545
- if (typeof v === "string") {
546
- return v;
547
- }
548
- const elementHandler = await iframe.locator(v.element).elementHandle();
549
- if (!elementHandler) {
550
- throw new Error(`Element not found: ${v.element}`);
551
- }
552
- return elementHandler;
553
- }));
554
- await selectElement.selectOption(values, options);
555
- };
556
-
557
- const tab = async (context, options = {}) => {
558
- const page = context.page;
559
- await page.keyboard.press(options.shift === true ? "Shift+Tab" : "Tab");
560
- };
561
-
562
- const startTracing = async ({ context, project, provider, sessionId }) => {
563
- if (isPlaywrightProvider(provider)) {
564
- if (provider.tracingContexts.has(sessionId)) {
565
- return;
566
- }
567
- provider.tracingContexts.add(sessionId);
568
- const options = project.config.browser.trace;
569
- await context.tracing.start({
570
- screenshots: options.screenshots ?? true,
571
- snapshots: options.snapshots ?? true,
572
- sources: false
573
- }).catch(() => {
574
- provider.tracingContexts.delete(sessionId);
575
- });
576
- return;
577
- }
578
- throw new TypeError(`The ${provider.name} provider does not support tracing.`);
579
- };
580
- const startChunkTrace = async (command, { name, title }) => {
581
- const { provider, sessionId, testPath, context } = command;
582
- if (!testPath) {
583
- throw new Error(`stopChunkTrace cannot be called outside of the test file.`);
584
- }
585
- if (isPlaywrightProvider(provider)) {
586
- if (!provider.tracingContexts.has(sessionId)) {
587
- await startTracing(command);
588
- }
589
- const path = resolveTracesPath(command, name);
590
- provider.pendingTraces.set(path, sessionId);
591
- await context.tracing.startChunk({
592
- name,
593
- title
594
- });
595
- return;
596
- }
597
- throw new TypeError(`The ${provider.name} provider does not support tracing.`);
598
- };
599
- const stopChunkTrace = async (context, { name }) => {
600
- if (isPlaywrightProvider(context.provider)) {
601
- const path = resolveTracesPath(context, name);
602
- context.provider.pendingTraces.delete(path);
603
- await context.context.tracing.stopChunk({ path });
604
- return { tracePath: path };
605
- }
606
- throw new TypeError(`The ${context.provider.name} provider does not support tracing.`);
607
- };
608
- function resolveTracesPath({ testPath, project }, name) {
609
- if (!testPath) {
610
- throw new Error(`This command can only be called inside a test file.`);
611
- }
612
- const options = project.config.browser.trace;
613
- const sanitizedName = `${project.name.replace(/[^a-z0-9]/gi, "-")}-${name}.trace.zip`;
614
- if (options.tracesDir) {
615
- return resolve(options.tracesDir, sanitizedName);
616
- }
617
- const dir = dirname(testPath);
618
- const base = basename(testPath);
619
- return resolve(dir, "__traces__", base, `${project.name.replace(/[^a-z0-9]/gi, "-")}-${name}.trace.zip`);
620
- }
621
- const deleteTracing = async (context, { traces }) => {
622
- if (!context.testPath) {
623
- throw new Error(`stopChunkTrace cannot be called outside of the test file.`);
624
- }
625
- if (isPlaywrightProvider(context.provider)) {
626
- return Promise.all(traces.map((trace) => unlink(trace).catch((err) => {
627
- if (err.code === "ENOENT") {
628
- // Ignore the error if the file doesn't exist
629
- return;
630
- }
631
- // Re-throw other errors
632
- throw err;
633
- })));
634
- }
635
- throw new Error(`provider ${context.provider.name} is not supported`);
636
- };
637
- const annotateTraces = async ({ project }, { testId, traces }) => {
638
- const vitest = project.vitest;
639
- await Promise.all(traces.map((trace) => {
640
- const entity = vitest.state.getReportedEntityById(testId);
641
- const location = entity?.location ? {
642
- file: entity.module.moduleId,
643
- line: entity.location.line,
644
- column: entity.location.column
645
- } : undefined;
646
- return vitest._testRun.recordArtifact(testId, {
647
- type: "internal:annotation",
648
- annotation: {
649
- message: relative(project.config.root, trace),
650
- type: "traces",
651
- attachment: {
652
- path: trace,
653
- contentType: "application/octet-stream"
654
- },
655
- location
656
- },
657
- location
658
- });
659
- }));
660
- };
661
- function isPlaywrightProvider(provider) {
662
- return provider.name === "playwright";
663
- }
664
-
665
- const type = async (context, selector, text, options = {}) => {
666
- const { skipClick = false, skipAutoClose = false } = options;
667
- const unreleased = new Set(Reflect.get(options, "unreleased") ?? []);
668
- const { iframe } = context;
669
- const element = iframe.locator(selector);
670
- if (!skipClick) {
671
- await element.focus();
672
- }
673
- await keyboardImplementation(unreleased, context.provider, context.sessionId, text, () => element.selectText(), skipAutoClose);
674
- return { unreleased: Array.from(unreleased) };
675
- };
676
-
677
- const upload = async (context, selector, files, options) => {
678
- const testPath = context.testPath;
679
- if (!testPath) {
680
- throw new Error(`Cannot upload files outside of a test`);
681
- }
682
- const root = context.project.config.root;
683
- const { iframe } = context;
684
- const playwrightFiles = files.map((file) => {
685
- if (typeof file === "string") {
686
- return resolve(root, file);
687
- }
688
- return {
689
- name: file.name,
690
- mimeType: file.mimeType,
691
- buffer: Buffer.from(file.base64, "base64")
692
- };
693
- });
694
- await iframe.locator(selector).setInputFiles(playwrightFiles, options);
695
- };
696
-
697
- var commands = {
698
- __vitest_upload: upload,
699
- __vitest_click: click,
700
- __vitest_dblClick: dblClick,
701
- __vitest_tripleClick: tripleClick,
702
- __vitest_takeScreenshot: takeScreenshot,
703
- __vitest_type: type,
704
- __vitest_clear: clear,
705
- __vitest_fill: fill,
706
- __vitest_tab: tab,
707
- __vitest_keyboard: keyboard,
708
- __vitest_selectOptions: selectOptions,
709
- __vitest_dragAndDrop: dragAndDrop,
710
- __vitest_hover: hover,
711
- __vitest_cleanup: keyboardCleanup,
712
- __vitest_deleteTracing: deleteTracing,
713
- __vitest_startChunkTrace: startChunkTrace,
714
- __vitest_startTracing: startTracing,
715
- __vitest_stopChunkTrace: stopChunkTrace,
716
- __vitest_annotateTraces: annotateTraces
717
- };
718
-
719
- const pkgRoot = resolve(fileURLToPath(import.meta.url), "../..");
720
- const distRoot = resolve(pkgRoot, "dist");
721
-
722
- const debug = createDebugger("vitest:browser:playwright");
723
- const playwrightBrowsers = [
724
- "firefox",
725
- "webkit",
726
- "chromium"
727
- ];
728
- // Enable intercepting of requests made by service workers - experimental API is only available in Chromium based browsers
729
- // Requests from service workers are only available on context.route() https://playwright.dev/docs/service-workers-experimental
730
- process.env.PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS ??= "1";
731
- function playwright(options = {}) {
732
- return defineBrowserProvider({
733
- name: "playwright",
734
- supportedBrowser: playwrightBrowsers,
735
- options,
736
- providerFactory(project) {
737
- return new PlaywrightBrowserProvider(project, options);
738
- }
739
- });
740
- }
741
- class PlaywrightBrowserProvider {
742
- name = "playwright";
743
- supportsParallelism = true;
744
- browser = null;
745
- contexts = new Map();
746
- pages = new Map();
747
- mocker;
748
- browserName;
749
- browserPromise = null;
750
- closing = false;
751
- tracingContexts = new Set();
752
- pendingTraces = new Map();
753
- initScripts = [resolve(distRoot, "locators.js")];
754
- constructor(project, options) {
755
- this.project = project;
756
- this.options = options;
757
- this.browserName = project.config.browser.name;
758
- this.mocker = this.createMocker();
759
- for (const [name, command] of Object.entries(commands)) {
760
- project.browser.registerCommand(name, command);
761
- }
762
- // make sure the traces are finished if the test hangs
763
- process.on("SIGTERM", () => {
764
- if (!this.browser) {
765
- return;
766
- }
767
- const promises = [];
768
- for (const [trace, contextId] of this.pendingTraces.entries()) {
769
- promises.push((() => {
770
- const context = this.contexts.get(contextId);
771
- return context?.tracing.stopChunk({ path: trace });
772
- })());
773
- }
774
- return Promise.allSettled(promises);
775
- });
776
- }
777
- async openBrowser() {
778
- await this._throwIfClosing();
779
- if (this.browserPromise) {
780
- debug?.("[%s] the browser is resolving, reusing the promise", this.browserName);
781
- return this.browserPromise;
782
- }
783
- if (this.browser) {
784
- debug?.("[%s] the browser is resolved, reusing it", this.browserName);
785
- return this.browser;
786
- }
787
- this.browserPromise = (async () => {
788
- const options = this.project.config.browser;
789
- const playwright = await import('playwright');
790
- if (this.options.connectOptions) {
791
- if (this.options.launchOptions) {
792
- this.project.vitest.logger.warn(c.yellow(`Found both ${c.bold(c.italic(c.yellow("connect")))} and ${c.bold(c.italic(c.yellow("launch")))} options in browser instance configuration.
793
- Ignoring ${c.bold(c.italic(c.yellow("launch")))} options and using ${c.bold(c.italic(c.yellow("connect")))} mode.
794
- You probably want to remove one of the two options and keep only the one you want to use.`));
795
- }
796
- const browser = await playwright[this.browserName].connect(this.options.connectOptions.wsEndpoint, this.options.connectOptions);
797
- this.browser = browser;
798
- this.browserPromise = null;
799
- return this.browser;
800
- }
801
- const launchOptions = {
802
- ...this.options.launchOptions,
803
- headless: options.headless
804
- };
805
- if (typeof options.trace === "object" && options.trace.tracesDir) {
806
- launchOptions.tracesDir = options.trace?.tracesDir;
807
- }
808
- const inspector = this.project.vitest.config.inspector;
809
- if (inspector.enabled) {
810
- // NodeJS equivalent defaults: https://nodejs.org/en/learn/getting-started/debugging#enable-inspector
811
- const port = inspector.port || 9229;
812
- const host = inspector.host || "127.0.0.1";
813
- launchOptions.args ||= [];
814
- launchOptions.args.push(`--remote-debugging-port=${port}`);
815
- launchOptions.args.push(`--remote-debugging-address=${host}`);
816
- this.project.vitest.logger.log(`Debugger listening on ws://${host}:${port}`);
817
- }
818
- // start Vitest UI maximized only on supported browsers
819
- if (this.project.config.browser.ui && this.browserName === "chromium") {
820
- if (!launchOptions.args) {
821
- launchOptions.args = [];
822
- }
823
- if (!launchOptions.args.includes("--start-maximized") && !launchOptions.args.includes("--start-fullscreen")) {
824
- launchOptions.args.push("--start-maximized");
825
- }
826
- }
827
- debug?.("[%s] initializing the browser with launch options: %O", this.browserName, launchOptions);
828
- this.browser = await playwright[this.browserName].launch(launchOptions);
829
- this.browserPromise = null;
830
- return this.browser;
831
- })();
832
- return this.browserPromise;
833
- }
834
- createMocker() {
835
- const idPreficates = new Map();
836
- const sessionIds = new Map();
837
- function createPredicate(sessionId, url) {
838
- const moduleUrl = new URL(url, "http://localhost");
839
- const predicate = (url) => {
840
- if (url.searchParams.has("_vitest_original")) {
841
- return false;
842
- }
843
- // different modules, ignore request
844
- if (url.pathname !== moduleUrl.pathname) {
845
- return false;
846
- }
847
- url.searchParams.delete("t");
848
- url.searchParams.delete("v");
849
- url.searchParams.delete("import");
850
- // different search params, ignore request
851
- if (url.searchParams.size !== moduleUrl.searchParams.size) {
852
- return false;
853
- }
854
- // check that all search params are the same
855
- for (const [param, value] of url.searchParams.entries()) {
856
- if (moduleUrl.searchParams.get(param) !== value) {
857
- return false;
858
- }
859
- }
860
- return true;
861
- };
862
- const ids = sessionIds.get(sessionId) || [];
863
- ids.push(moduleUrl.href);
864
- sessionIds.set(sessionId, ids);
865
- idPreficates.set(predicateKey(sessionId, moduleUrl.href), predicate);
866
- return predicate;
867
- }
868
- function predicateKey(sessionId, url) {
869
- return `${sessionId}:${url}`;
870
- }
871
- return {
872
- register: async (sessionId, module) => {
873
- const page = this.getPage(sessionId);
874
- await page.context().route(createPredicate(sessionId, module.url), async (route) => {
875
- if (module.type === "manual") {
876
- const exports$1 = Object.keys(await module.resolve());
877
- const body = createManualModuleSource(module.url, exports$1);
878
- return route.fulfill({
879
- body,
880
- headers: getHeaders(this.project.browser.vite.config)
881
- });
882
- }
883
- // webkit doesn't support redirect responses
884
- // https://github.com/microsoft/playwright/issues/18318
885
- const isWebkit = this.browserName === "webkit";
886
- if (isWebkit) {
887
- let url;
888
- if (module.type === "redirect") {
889
- const redirect = new URL(module.redirect);
890
- url = redirect.href.slice(redirect.origin.length);
891
- } else {
892
- const request = new URL(route.request().url());
893
- request.searchParams.set("mock", module.type);
894
- url = request.href.slice(request.origin.length);
895
- }
896
- const result = await this.project.browser.vite.transformRequest(url).catch(() => null);
897
- if (!result) {
898
- return route.continue();
899
- }
900
- let content = result.code;
901
- if (result.map && "version" in result.map && result.map.mappings) {
902
- const type = isDirectCSSRequest(url) ? "css" : "js";
903
- content = getCodeWithSourcemap(type, content.toString(), result.map);
904
- }
905
- return route.fulfill({
906
- body: content,
907
- headers: getHeaders(this.project.browser.vite.config)
908
- });
909
- }
910
- if (module.type === "redirect") {
911
- return route.fulfill({
912
- status: 302,
913
- headers: { Location: module.redirect }
914
- });
915
- } else if (module.type === "automock" || module.type === "autospy") {
916
- const url = new URL(route.request().url());
917
- url.searchParams.set("mock", module.type);
918
- return route.fulfill({
919
- status: 302,
920
- headers: { Location: url.href }
921
- });
922
- } else ;
923
- });
924
- },
925
- delete: async (sessionId, id) => {
926
- const page = this.getPage(sessionId);
927
- const key = predicateKey(sessionId, id);
928
- const predicate = idPreficates.get(key);
929
- if (predicate) {
930
- await page.context().unroute(predicate).finally(() => idPreficates.delete(key));
931
- }
932
- },
933
- clear: async (sessionId) => {
934
- const page = this.getPage(sessionId);
935
- const ids = sessionIds.get(sessionId) || [];
936
- const promises = ids.map((id) => {
937
- const key = predicateKey(sessionId, id);
938
- const predicate = idPreficates.get(key);
939
- if (predicate) {
940
- return page.context().unroute(predicate).finally(() => idPreficates.delete(key));
941
- }
942
- return null;
943
- });
944
- await Promise.all(promises).finally(() => sessionIds.delete(sessionId));
945
- }
946
- };
947
- }
948
- async createContext(sessionId) {
949
- await this._throwIfClosing();
950
- if (this.contexts.has(sessionId)) {
951
- debug?.("[%s][%s] the context already exists, reusing it", sessionId, this.browserName);
952
- return this.contexts.get(sessionId);
953
- }
954
- const browser = await this.openBrowser();
955
- await this._throwIfClosing(browser);
956
- const actionTimeout = this.options.actionTimeout;
957
- const contextOptions = this.options.contextOptions ?? {};
958
- const options = {
959
- ...contextOptions,
960
- ignoreHTTPSErrors: true
961
- };
962
- if (this.project.config.browser.ui) {
963
- options.viewport = null;
964
- }
965
- // TODO: investigate the consequences for Vitest 5
966
- // else {
967
- // if UI is disabled, keep the iframe scale to 1
968
- // options.viewport ??= this.project.config.browser.viewport
969
- // }
970
- const context = await browser.newContext(options);
971
- await this._throwIfClosing(context);
972
- if (actionTimeout != null) {
973
- context.setDefaultTimeout(actionTimeout);
974
- }
975
- debug?.("[%s][%s] the context is ready", sessionId, this.browserName);
976
- this.contexts.set(sessionId, context);
977
- return context;
978
- }
979
- getPage(sessionId) {
980
- const page = this.pages.get(sessionId);
981
- if (!page) {
982
- throw new Error(`Page "${sessionId}" not found in ${this.browserName} browser.`);
983
- }
984
- return page;
985
- }
986
- getCommandsContext(sessionId) {
987
- const page = this.getPage(sessionId);
988
- return {
989
- page,
990
- context: this.contexts.get(sessionId),
991
- frame() {
992
- return new Promise((resolve, reject) => {
993
- const frame = page.frame("vitest-iframe");
994
- if (frame) {
995
- return resolve(frame);
996
- }
997
- const timeout = setTimeout(() => {
998
- const err = new Error(`Cannot find "vitest-iframe" on the page. This is a bug in Vitest, please report it.`);
999
- reject(err);
1000
- }, 1e3).unref();
1001
- page.on("frameattached", (frame) => {
1002
- clearTimeout(timeout);
1003
- resolve(frame);
1004
- });
1005
- });
1006
- },
1007
- get iframe() {
1008
- return page.frameLocator("[data-vitest=\"true\"]");
1009
- }
1010
- };
1011
- }
1012
- async openBrowserPage(sessionId) {
1013
- await this._throwIfClosing();
1014
- if (this.pages.has(sessionId)) {
1015
- debug?.("[%s][%s] the page already exists, closing the old one", sessionId, this.browserName);
1016
- const page = this.pages.get(sessionId);
1017
- await page.close();
1018
- this.pages.delete(sessionId);
1019
- }
1020
- const context = await this.createContext(sessionId);
1021
- const page = await context.newPage();
1022
- debug?.("[%s][%s] the page is ready", sessionId, this.browserName);
1023
- await this._throwIfClosing(page);
1024
- this.pages.set(sessionId, page);
1025
- if (process.env.VITEST_PW_DEBUG) {
1026
- page.on("requestfailed", (request) => {
1027
- console.error("[PW Error]", request.resourceType(), "request failed for", request.url(), "url:", request.failure()?.errorText);
1028
- });
1029
- }
1030
- return page;
1031
- }
1032
- async openPage(sessionId, url) {
1033
- debug?.("[%s][%s] creating the browser page for %s", sessionId, this.browserName, url);
1034
- const browserPage = await this.openBrowserPage(sessionId);
1035
- debug?.("[%s][%s] browser page is created, opening %s", sessionId, this.browserName, url);
1036
- await browserPage.goto(url, { timeout: 0 });
1037
- await this._throwIfClosing(browserPage);
1038
- }
1039
- async _throwIfClosing(disposable) {
1040
- if (this.closing) {
1041
- debug?.("[%s] provider was closed, cannot perform the action on %s", this.browserName, String(disposable));
1042
- await disposable?.close();
1043
- this.pages.clear();
1044
- this.contexts.clear();
1045
- this.browser = null;
1046
- this.browserPromise = null;
1047
- throw new Error(`[vitest] The provider was closed.`);
1048
- }
1049
- }
1050
- async getCDPSession(sessionid) {
1051
- const page = this.getPage(sessionid);
1052
- const cdp = await page.context().newCDPSession(page);
1053
- return {
1054
- async send(method, params) {
1055
- const result = await cdp.send(method, params);
1056
- return result;
1057
- },
1058
- on(event, listener) {
1059
- cdp.on(event, listener);
1060
- },
1061
- off(event, listener) {
1062
- cdp.off(event, listener);
1063
- },
1064
- once(event, listener) {
1065
- cdp.once(event, listener);
1066
- }
1067
- };
1068
- }
1069
- async close() {
1070
- debug?.("[%s] closing provider", this.browserName);
1071
- this.closing = true;
1072
- if (this.browserPromise) {
1073
- await this.browserPromise;
1074
- this.browserPromise = null;
1075
- }
1076
- const browser = this.browser;
1077
- this.browser = null;
1078
- await Promise.all([...this.pages.values()].map((p) => p.close()));
1079
- this.pages.clear();
1080
- await Promise.all([...this.contexts.values()].map((c) => c.close()));
1081
- this.contexts.clear();
1082
- await browser?.close();
1083
- debug?.("[%s] provider is closed", this.browserName);
1084
- }
1085
- }
1086
- function getHeaders(config) {
1087
- const headers = { "Content-Type": "application/javascript" };
1088
- for (const name in config.server.headers) {
1089
- headers[name] = String(config.server.headers[name]);
1090
- }
1091
- return headers;
1092
- }
1093
- function getCodeWithSourcemap(type, code, map) {
1094
- if (type === "js") {
1095
- code += `\n//# sourceMappingURL=${genSourceMapUrl(map)}`;
1096
- } else if (type === "css") {
1097
- code += `\n/*# sourceMappingURL=${genSourceMapUrl(map)} */`;
1098
- }
1099
- return code;
1100
- }
1101
- function genSourceMapUrl(map) {
1102
- if (typeof map !== "string") {
1103
- map = JSON.stringify(map);
1104
- }
1105
- return `data:application/json;base64,${Buffer.from(map).toString("base64")}`;
1106
- }
1107
- const directRequestRE = /[?&]direct\b/;
1108
- function isDirectCSSRequest(request) {
1109
- return isCSSRequest(request) && directRequestRE.test(request);
1110
- }
1111
-
1112
- export { PlaywrightBrowserProvider, playwright };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/dist/locators.js DELETED
@@ -1,114 +0,0 @@
1
- import { selectorEngine, getByTitleSelector, getByTextSelector, getByPlaceholderSelector, getByAltTextSelector, getByTestIdSelector, getByRoleSelector, getByLabelSelector, Locator, processTimeoutOptions, getIframeScale } from '@vitest/browser/locators';
2
- import { page, server } from 'vitest/browser';
3
- import { __INTERNAL } from 'vitest/internal/browser';
4
-
5
- class PlaywrightLocator extends Locator {
6
- constructor(selector, _container) {
7
- super();
8
- this.selector = selector;
9
- this._container = _container;
10
- }
11
- click(options) {
12
- return super.click(processTimeoutOptions(processClickOptions(options)));
13
- }
14
- dblClick(options) {
15
- return super.dblClick(processTimeoutOptions(processClickOptions(options)));
16
- }
17
- tripleClick(options) {
18
- return super.tripleClick(processTimeoutOptions(processClickOptions(options)));
19
- }
20
- selectOptions(value, options) {
21
- return super.selectOptions(value, processTimeoutOptions(options));
22
- }
23
- clear(options) {
24
- return super.clear(processTimeoutOptions(options));
25
- }
26
- hover(options) {
27
- return super.hover(processTimeoutOptions(processHoverOptions(options)));
28
- }
29
- upload(files, options) {
30
- return super.upload(files, processTimeoutOptions(options));
31
- }
32
- fill(text, options) {
33
- return super.fill(text, processTimeoutOptions(options));
34
- }
35
- dropTo(target, options) {
36
- return super.dropTo(target, processTimeoutOptions(processDragAndDropOptions(options)));
37
- }
38
- locator(selector) {
39
- return new PlaywrightLocator(`${this.selector} >> ${selector}`, this._container);
40
- }
41
- elementLocator(element) {
42
- return new PlaywrightLocator(selectorEngine.generateSelectorSimple(element), element);
43
- }
44
- }
45
- page.extend({
46
- getByLabelText(text, options) {
47
- return new PlaywrightLocator(getByLabelSelector(text, options));
48
- },
49
- getByRole(role, options) {
50
- return new PlaywrightLocator(getByRoleSelector(role, options));
51
- },
52
- getByTestId(testId) {
53
- return new PlaywrightLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
54
- },
55
- getByAltText(text, options) {
56
- return new PlaywrightLocator(getByAltTextSelector(text, options));
57
- },
58
- getByPlaceholder(text, options) {
59
- return new PlaywrightLocator(getByPlaceholderSelector(text, options));
60
- },
61
- getByText(text, options) {
62
- return new PlaywrightLocator(getByTextSelector(text, options));
63
- },
64
- getByTitle(title, options) {
65
- return new PlaywrightLocator(getByTitleSelector(title, options));
66
- },
67
- elementLocator(element) {
68
- return new PlaywrightLocator(selectorEngine.generateSelectorSimple(element), element);
69
- },
70
- frameLocator(locator) {
71
- return new PlaywrightLocator(`${locator.selector} >> internal:control=enter-frame`);
72
- }
73
- });
74
- __INTERNAL._createLocator = (selector) => new PlaywrightLocator(selector);
75
- function processDragAndDropOptions(options) {
76
- if (!options) {
77
- return options;
78
- }
79
- if (options.sourcePosition) {
80
- options.sourcePosition = processPlaywrightPosition(options.sourcePosition);
81
- }
82
- if (options.targetPosition) {
83
- options.targetPosition = processPlaywrightPosition(options.targetPosition);
84
- }
85
- return options;
86
- }
87
- function processHoverOptions(options) {
88
- if (!options) {
89
- return options;
90
- }
91
- if (options.position) {
92
- options.position = processPlaywrightPosition(options.position);
93
- }
94
- return options;
95
- }
96
- function processClickOptions(options) {
97
- if (!options) {
98
- return options;
99
- }
100
- if (options.position) {
101
- options.position = processPlaywrightPosition(options.position);
102
- }
103
- return options;
104
- }
105
- function processPlaywrightPosition(position) {
106
- const scale = getIframeScale();
107
- if (position.x != null) {
108
- position.x *= scale;
109
- }
110
- if (position.y != null) {
111
- position.y *= scale;
112
- }
113
- return position;
114
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/node_modules/.bin/playwright DELETED
@@ -1,17 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
- esac
7
-
8
- if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules/playwright/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules/playwright/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules:$NODE_PATH"
12
- fi
13
- if [ -x "$basedir/node" ]; then
14
- exec "$basedir/node" "$basedir/../../../../../../playwright@1.58.1/node_modules/playwright/cli.js" "$@"
15
- else
16
- exec node "$basedir/../../../../../../playwright@1.58.1/node_modules/playwright/cli.js" "$@"
17
- fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/node_modules/.bin/playwright.CMD DELETED
@@ -1,12 +0,0 @@
1
- @SETLOCAL
2
- @IF NOT DEFINED NODE_PATH (
3
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules\playwright\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
4
- ) ELSE (
5
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules\playwright\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
- )
7
- @IF EXIST "%~dp0\node.exe" (
8
- "%~dp0\node.exe" "%~dp0\..\..\..\..\..\..\playwright@1.58.1\node_modules\playwright\cli.js" %*
9
- ) ELSE (
10
- @SET PATHEXT=%PATHEXT:;.JS;=;%
11
- node "%~dp0\..\..\..\..\..\..\playwright@1.58.1\node_modules\playwright\cli.js" %*
12
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/node_modules/.bin/playwright.ps1 DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env pwsh
2
- $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
-
4
- $exe=""
5
- $pathsep=":"
6
- $env_node_path=$env:NODE_PATH
7
- $new_node_path="F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules\playwright\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\playwright@1.58.1\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
8
- if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
- # Fix case when both the Windows and Linux builds of Node
10
- # are installed in the same directory
11
- $exe=".exe"
12
- $pathsep=";"
13
- } else {
14
- $new_node_path="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules/playwright/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/playwright@1.58.1/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
15
- }
16
- if ([string]::IsNullOrEmpty($env_node_path)) {
17
- $env:NODE_PATH=$new_node_path
18
- } else {
19
- $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
- }
21
-
22
- $ret=0
23
- if (Test-Path "$basedir/node$exe") {
24
- # Support pipeline input
25
- if ($MyInvocation.ExpectingInput) {
26
- $input | & "$basedir/node$exe" "$basedir/../../../../../../playwright@1.58.1/node_modules/playwright/cli.js" $args
27
- } else {
28
- & "$basedir/node$exe" "$basedir/../../../../../../playwright@1.58.1/node_modules/playwright/cli.js" $args
29
- }
30
- $ret=$LASTEXITCODE
31
- } else {
32
- # Support pipeline input
33
- if ($MyInvocation.ExpectingInput) {
34
- $input | & "node$exe" "$basedir/../../../../../../playwright@1.58.1/node_modules/playwright/cli.js" $args
35
- } else {
36
- & "node$exe" "$basedir/../../../../../../playwright@1.58.1/node_modules/playwright/cli.js" $args
37
- }
38
- $ret=$LASTEXITCODE
39
- }
40
- $env:NODE_PATH=$env_node_path
41
- exit $ret
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/node_modules/.bin/vitest DELETED
@@ -1,17 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
- esac
7
-
8
- if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules:$NODE_PATH"
12
- fi
13
- if [ -x "$basedir/node" ]; then
14
- exec "$basedir/node" "$basedir/../../../../../../vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/vitest.mjs" "$@"
15
- else
16
- exec node "$basedir/../../../../../../vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/vitest.mjs" "$@"
17
- fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/node_modules/.bin/vitest.CMD DELETED
@@ -1,12 +0,0 @@
1
- @SETLOCAL
2
- @IF NOT DEFINED NODE_PATH (
3
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vitest\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
4
- ) ELSE (
5
- @SET "NODE_PATH=F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vitest\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
- )
7
- @IF EXIST "%~dp0\node.exe" (
8
- "%~dp0\node.exe" "%~dp0\..\..\..\..\..\..\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vitest\vitest.mjs" %*
9
- ) ELSE (
10
- @SET PATHEXT=%PATHEXT:;.JS;=;%
11
- node "%~dp0\..\..\..\..\..\..\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vitest\vitest.mjs" %*
12
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/node_modules/.bin/vitest.ps1 DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env pwsh
2
- $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
-
4
- $exe=""
5
- $pathsep=":"
6
- $env_node_path=$env:NODE_PATH
7
- $new_node_path="F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules\vitest\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2\node_modules;F:\apps\OpenClawBot\openclaw-main\node_modules\.pnpm\node_modules"
8
- if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
- # Fix case when both the Windows and Linux builds of Node
10
- # are installed in the same directory
11
- $exe=".exe"
12
- $pathsep=";"
13
- } else {
14
- $new_node_path="/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules:/mnt/f/apps/OpenClawBot/openclaw-main/node_modules/.pnpm/node_modules"
15
- }
16
- if ([string]::IsNullOrEmpty($env_node_path)) {
17
- $env:NODE_PATH=$new_node_path
18
- } else {
19
- $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
- }
21
-
22
- $ret=0
23
- if (Test-Path "$basedir/node$exe") {
24
- # Support pipeline input
25
- if ($MyInvocation.ExpectingInput) {
26
- $input | & "$basedir/node$exe" "$basedir/../../../../../../vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/vitest.mjs" $args
27
- } else {
28
- & "$basedir/node$exe" "$basedir/../../../../../../vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/vitest.mjs" $args
29
- }
30
- $ret=$LASTEXITCODE
31
- } else {
32
- # Support pipeline input
33
- if ($MyInvocation.ExpectingInput) {
34
- $input | & "node$exe" "$basedir/../../../../../../vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/vitest.mjs" $args
35
- } else {
36
- & "node$exe" "$basedir/../../../../../../vitest@4.0.18_@types+node@25.2.0_@vitest+browser-playwright@4.0.18_jiti@2.6.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/vitest.mjs" $args
37
- }
38
- $ret=$LASTEXITCODE
39
- }
40
- $env:NODE_PATH=$env_node_path
41
- exit $ret
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/@vitest/browser-playwright/package.json DELETED
@@ -1,65 +0,0 @@
1
- {
2
- "name": "@vitest/browser-playwright",
3
- "type": "module",
4
- "version": "4.0.18",
5
- "description": "Browser running for Vitest using playwright",
6
- "license": "MIT",
7
- "funding": "https://opencollective.com/vitest",
8
- "homepage": "https://vitest.dev/config/browser/playwright",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/vitest-dev/vitest.git",
12
- "directory": "packages/browser-playwright"
13
- },
14
- "bugs": {
15
- "url": "https://github.com/vitest-dev/vitest/issues"
16
- },
17
- "keywords": [
18
- "browser",
19
- "playwright",
20
- "component",
21
- "mocks",
22
- "test",
23
- "testing"
24
- ],
25
- "sideEffects": false,
26
- "exports": {
27
- ".": {
28
- "types": "./dist/index.d.ts",
29
- "default": "./dist/index.js"
30
- },
31
- "./context": {
32
- "types": "./context.d.ts"
33
- },
34
- "./package.json": "./package.json"
35
- },
36
- "main": "./dist/index.js",
37
- "module": "./dist/index.js",
38
- "types": "./dist/index.d.ts",
39
- "files": [
40
- "context.d.ts",
41
- "dist"
42
- ],
43
- "peerDependencies": {
44
- "playwright": "*",
45
- "vitest": "4.0.18"
46
- },
47
- "peerDependenciesMeta": {
48
- "playwright": {
49
- "optional": false
50
- }
51
- },
52
- "dependencies": {
53
- "tinyrainbow": "^3.0.3",
54
- "@vitest/browser": "4.0.18",
55
- "@vitest/mocker": "4.0.18"
56
- },
57
- "devDependencies": {
58
- "playwright": "^1.57.0",
59
- "vitest": "4.0.18"
60
- },
61
- "scripts": {
62
- "build": "premove dist && pnpm rollup -c",
63
- "dev": "rollup -c --watch --watch.include 'src/**'"
64
- }
65
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/dompurify/LICENSE DELETED
@@ -1,568 +0,0 @@
1
- DOMPurify
2
- Copyright 2025 Dr.-Ing. Mario Heiderich, Cure53
3
-
4
- DOMPurify is free software; you can redistribute it and/or modify it under the
5
- terms of either:
6
-
7
- a) the Apache License Version 2.0, or
8
- b) the Mozilla Public License Version 2.0
9
-
10
- -----------------------------------------------------------------------------
11
-
12
- Apache License
13
- Version 2.0, January 2004
14
- http://www.apache.org/licenses/
15
-
16
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
17
-
18
- 1. Definitions.
19
-
20
- "License" shall mean the terms and conditions for use, reproduction,
21
- and distribution as defined by Sections 1 through 9 of this document.
22
-
23
- "Licensor" shall mean the copyright owner or entity authorized by
24
- the copyright owner that is granting the License.
25
-
26
- "Legal Entity" shall mean the union of the acting entity and all
27
- other entities that control, are controlled by, or are under common
28
- control with that entity. For the purposes of this definition,
29
- "control" means (i) the power, direct or indirect, to cause the
30
- direction or management of such entity, whether by contract or
31
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
32
- outstanding shares, or (iii) beneficial ownership of such entity.
33
-
34
- "You" (or "Your") shall mean an individual or Legal Entity
35
- exercising permissions granted by this License.
36
-
37
- "Source" form shall mean the preferred form for making modifications,
38
- including but not limited to software source code, documentation
39
- source, and configuration files.
40
-
41
- "Object" form shall mean any form resulting from mechanical
42
- transformation or translation of a Source form, including but
43
- not limited to compiled object code, generated documentation,
44
- and conversions to other media types.
45
-
46
- "Work" shall mean the work of authorship, whether in Source or
47
- Object form, made available under the License, as indicated by a
48
- copyright notice that is included in or attached to the work
49
- (an example is provided in the Appendix below).
50
-
51
- "Derivative Works" shall mean any work, whether in Source or Object
52
- form, that is based on (or derived from) the Work and for which the
53
- editorial revisions, annotations, elaborations, or other modifications
54
- represent, as a whole, an original work of authorship. For the purposes
55
- of this License, Derivative Works shall not include works that remain
56
- separable from, or merely link (or bind by name) to the interfaces of,
57
- the Work and Derivative Works thereof.
58
-
59
- "Contribution" shall mean any work of authorship, including
60
- the original version of the Work and any modifications or additions
61
- to that Work or Derivative Works thereof, that is intentionally
62
- submitted to Licensor for inclusion in the Work by the copyright owner
63
- or by an individual or Legal Entity authorized to submit on behalf of
64
- the copyright owner. For the purposes of this definition, "submitted"
65
- means any form of electronic, verbal, or written communication sent
66
- to the Licensor or its representatives, including but not limited to
67
- communication on electronic mailing lists, source code control systems,
68
- and issue tracking systems that are managed by, or on behalf of, the
69
- Licensor for the purpose of discussing and improving the Work, but
70
- excluding communication that is conspicuously marked or otherwise
71
- designated in writing by the copyright owner as "Not a Contribution."
72
-
73
- "Contributor" shall mean Licensor and any individual or Legal Entity
74
- on behalf of whom a Contribution has been received by Licensor and
75
- subsequently incorporated within the Work.
76
-
77
- 2. Grant of Copyright License. Subject to the terms and conditions of
78
- this License, each Contributor hereby grants to You a perpetual,
79
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
80
- copyright license to reproduce, prepare Derivative Works of,
81
- publicly display, publicly perform, sublicense, and distribute the
82
- Work and such Derivative Works in Source or Object form.
83
-
84
- 3. Grant of Patent License. Subject to the terms and conditions of
85
- this License, each Contributor hereby grants to You a perpetual,
86
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
87
- (except as stated in this section) patent license to make, have made,
88
- use, offer to sell, sell, import, and otherwise transfer the Work,
89
- where such license applies only to those patent claims licensable
90
- by such Contributor that are necessarily infringed by their
91
- Contribution(s) alone or by combination of their Contribution(s)
92
- with the Work to which such Contribution(s) was submitted. If You
93
- institute patent litigation against any entity (including a
94
- cross-claim or counterclaim in a lawsuit) alleging that the Work
95
- or a Contribution incorporated within the Work constitutes direct
96
- or contributory patent infringement, then any patent licenses
97
- granted to You under this License for that Work shall terminate
98
- as of the date such litigation is filed.
99
-
100
- 4. Redistribution. You may reproduce and distribute copies of the
101
- Work or Derivative Works thereof in any medium, with or without
102
- modifications, and in Source or Object form, provided that You
103
- meet the following conditions:
104
-
105
- (a) You must give any other recipients of the Work or
106
- Derivative Works a copy of this License; and
107
-
108
- (b) You must cause any modified files to carry prominent notices
109
- stating that You changed the files; and
110
-
111
- (c) You must retain, in the Source form of any Derivative Works
112
- that You distribute, all copyright, patent, trademark, and
113
- attribution notices from the Source form of the Work,
114
- excluding those notices that do not pertain to any part of
115
- the Derivative Works; and
116
-
117
- (d) If the Work includes a "NOTICE" text file as part of its
118
- distribution, then any Derivative Works that You distribute must
119
- include a readable copy of the attribution notices contained
120
- within such NOTICE file, excluding those notices that do not
121
- pertain to any part of the Derivative Works, in at least one
122
- of the following places: within a NOTICE text file distributed
123
- as part of the Derivative Works; within the Source form or
124
- documentation, if provided along with the Derivative Works; or,
125
- within a display generated by the Derivative Works, if and
126
- wherever such third-party notices normally appear. The contents
127
- of the NOTICE file are for informational purposes only and
128
- do not modify the License. You may add Your own attribution
129
- notices within Derivative Works that You distribute, alongside
130
- or as an addendum to the NOTICE text from the Work, provided
131
- that such additional attribution notices cannot be construed
132
- as modifying the License.
133
-
134
- You may add Your own copyright statement to Your modifications and
135
- may provide additional or different license terms and conditions
136
- for use, reproduction, or distribution of Your modifications, or
137
- for any such Derivative Works as a whole, provided Your use,
138
- reproduction, and distribution of the Work otherwise complies with
139
- the conditions stated in this License.
140
-
141
- 5. Submission of Contributions. Unless You explicitly state otherwise,
142
- any Contribution intentionally submitted for inclusion in the Work
143
- by You to the Licensor shall be under the terms and conditions of
144
- this License, without any additional terms or conditions.
145
- Notwithstanding the above, nothing herein shall supersede or modify
146
- the terms of any separate license agreement you may have executed
147
- with Licensor regarding such Contributions.
148
-
149
- 6. Trademarks. This License does not grant permission to use the trade
150
- names, trademarks, service marks, or product names of the Licensor,
151
- except as required for reasonable and customary use in describing the
152
- origin of the Work and reproducing the content of the NOTICE file.
153
-
154
- 7. Disclaimer of Warranty. Unless required by applicable law or
155
- agreed to in writing, Licensor provides the Work (and each
156
- Contributor provides its Contributions) on an "AS IS" BASIS,
157
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
158
- implied, including, without limitation, any warranties or conditions
159
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
160
- PARTICULAR PURPOSE. You are solely responsible for determining the
161
- appropriateness of using or redistributing the Work and assume any
162
- risks associated with Your exercise of permissions under this License.
163
-
164
- 8. Limitation of Liability. In no event and under no legal theory,
165
- whether in tort (including negligence), contract, or otherwise,
166
- unless required by applicable law (such as deliberate and grossly
167
- negligent acts) or agreed to in writing, shall any Contributor be
168
- liable to You for damages, including any direct, indirect, special,
169
- incidental, or consequential damages of any character arising as a
170
- result of this License or out of the use or inability to use the
171
- Work (including but not limited to damages for loss of goodwill,
172
- work stoppage, computer failure or malfunction, or any and all
173
- other commercial damages or losses), even if such Contributor
174
- has been advised of the possibility of such damages.
175
-
176
- 9. Accepting Warranty or Additional Liability. While redistributing
177
- the Work or Derivative Works thereof, You may choose to offer,
178
- and charge a fee for, acceptance of support, warranty, indemnity,
179
- or other liability obligations and/or rights consistent with this
180
- License. However, in accepting such obligations, You may act only
181
- on Your own behalf and on Your sole responsibility, not on behalf
182
- of any other Contributor, and only if You agree to indemnify,
183
- defend, and hold each Contributor harmless for any liability
184
- incurred by, or claims asserted against, such Contributor by reason
185
- of your accepting any such warranty or additional liability.
186
-
187
- END OF TERMS AND CONDITIONS
188
-
189
- APPENDIX: How to apply the Apache License to your work.
190
-
191
- To apply the Apache License to your work, attach the following
192
- boilerplate notice, with the fields enclosed by brackets "[]"
193
- replaced with your own identifying information. (Don't include
194
- the brackets!) The text should be enclosed in the appropriate
195
- comment syntax for the file format. We also recommend that a
196
- file or class name and description of purpose be included on the
197
- same "printed page" as the copyright notice for easier
198
- identification within third-party archives.
199
-
200
- Copyright [yyyy] [name of copyright owner]
201
-
202
- Licensed under the Apache License, Version 2.0 (the "License");
203
- you may not use this file except in compliance with the License.
204
- You may obtain a copy of the License at
205
-
206
- http://www.apache.org/licenses/LICENSE-2.0
207
-
208
- Unless required by applicable law or agreed to in writing, software
209
- distributed under the License is distributed on an "AS IS" BASIS,
210
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
211
- See the License for the specific language governing permissions and
212
- limitations under the License.
213
-
214
- -----------------------------------------------------------------------------
215
- Mozilla Public License, version 2.0
216
-
217
- 1. Definitions
218
-
219
- 1.1. “Contributor”
220
-
221
- means each individual or legal entity that creates, contributes to the
222
- creation of, or owns Covered Software.
223
-
224
- 1.2. “Contributor Version”
225
-
226
- means the combination of the Contributions of others (if any) used by a
227
- Contributor and that particular Contributor’s Contribution.
228
-
229
- 1.3. “Contribution”
230
-
231
- means Covered Software of a particular Contributor.
232
-
233
- 1.4. “Covered Software”
234
-
235
- means Source Code Form to which the initial Contributor has attached the
236
- notice in Exhibit A, the Executable Form of such Source Code Form, and
237
- Modifications of such Source Code Form, in each case including portions
238
- thereof.
239
-
240
- 1.5. “Incompatible With Secondary Licenses”
241
- means
242
-
243
- a. that the initial Contributor has attached the notice described in
244
- Exhibit B to the Covered Software; or
245
-
246
- b. that the Covered Software was made available under the terms of version
247
- 1.1 or earlier of the License, but not also under the terms of a
248
- Secondary License.
249
-
250
- 1.6. “Executable Form”
251
-
252
- means any form of the work other than Source Code Form.
253
-
254
- 1.7. “Larger Work”
255
-
256
- means a work that combines Covered Software with other material, in a separate
257
- file or files, that is not Covered Software.
258
-
259
- 1.8. “License”
260
-
261
- means this document.
262
-
263
- 1.9. “Licensable”
264
-
265
- means having the right to grant, to the maximum extent possible, whether at the
266
- time of the initial grant or subsequently, any and all of the rights conveyed by
267
- this License.
268
-
269
- 1.10. “Modifications”
270
-
271
- means any of the following:
272
-
273
- a. any file in Source Code Form that results from an addition to, deletion
274
- from, or modification of the contents of Covered Software; or
275
-
276
- b. any new file in Source Code Form that contains any Covered Software.
277
-
278
- 1.11. “Patent Claims” of a Contributor
279
-
280
- means any patent claim(s), including without limitation, method, process,
281
- and apparatus claims, in any patent Licensable by such Contributor that
282
- would be infringed, but for the grant of the License, by the making,
283
- using, selling, offering for sale, having made, import, or transfer of
284
- either its Contributions or its Contributor Version.
285
-
286
- 1.12. “Secondary License”
287
-
288
- means either the GNU General Public License, Version 2.0, the GNU Lesser
289
- General Public License, Version 2.1, the GNU Affero General Public
290
- License, Version 3.0, or any later versions of those licenses.
291
-
292
- 1.13. “Source Code Form”
293
-
294
- means the form of the work preferred for making modifications.
295
-
296
- 1.14. “You” (or “Your”)
297
-
298
- means an individual or a legal entity exercising rights under this
299
- License. For legal entities, “You” includes any entity that controls, is
300
- controlled by, or is under common control with You. For purposes of this
301
- definition, “control” means (a) the power, direct or indirect, to cause
302
- the direction or management of such entity, whether by contract or
303
- otherwise, or (b) ownership of more than fifty percent (50%) of the
304
- outstanding shares or beneficial ownership of such entity.
305
-
306
-
307
- 2. License Grants and Conditions
308
-
309
- 2.1. Grants
310
-
311
- Each Contributor hereby grants You a world-wide, royalty-free,
312
- non-exclusive license:
313
-
314
- a. under intellectual property rights (other than patent or trademark)
315
- Licensable by such Contributor to use, reproduce, make available,
316
- modify, display, perform, distribute, and otherwise exploit its
317
- Contributions, either on an unmodified basis, with Modifications, or as
318
- part of a Larger Work; and
319
-
320
- b. under Patent Claims of such Contributor to make, use, sell, offer for
321
- sale, have made, import, and otherwise transfer either its Contributions
322
- or its Contributor Version.
323
-
324
- 2.2. Effective Date
325
-
326
- The licenses granted in Section 2.1 with respect to any Contribution become
327
- effective for each Contribution on the date the Contributor first distributes
328
- such Contribution.
329
-
330
- 2.3. Limitations on Grant Scope
331
-
332
- The licenses granted in this Section 2 are the only rights granted under this
333
- License. No additional rights or licenses will be implied from the distribution
334
- or licensing of Covered Software under this License. Notwithstanding Section
335
- 2.1(b) above, no patent license is granted by a Contributor:
336
-
337
- a. for any code that a Contributor has removed from Covered Software; or
338
-
339
- b. for infringements caused by: (i) Your and any other third party’s
340
- modifications of Covered Software, or (ii) the combination of its
341
- Contributions with other software (except as part of its Contributor
342
- Version); or
343
-
344
- c. under Patent Claims infringed by Covered Software in the absence of its
345
- Contributions.
346
-
347
- This License does not grant any rights in the trademarks, service marks, or
348
- logos of any Contributor (except as may be necessary to comply with the
349
- notice requirements in Section 3.4).
350
-
351
- 2.4. Subsequent Licenses
352
-
353
- No Contributor makes additional grants as a result of Your choice to
354
- distribute the Covered Software under a subsequent version of this License
355
- (see Section 10.2) or under the terms of a Secondary License (if permitted
356
- under the terms of Section 3.3).
357
-
358
- 2.5. Representation
359
-
360
- Each Contributor represents that the Contributor believes its Contributions
361
- are its original creation(s) or it has sufficient rights to grant the
362
- rights to its Contributions conveyed by this License.
363
-
364
- 2.6. Fair Use
365
-
366
- This License is not intended to limit any rights You have under applicable
367
- copyright doctrines of fair use, fair dealing, or other equivalents.
368
-
369
- 2.7. Conditions
370
-
371
- Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
372
- Section 2.1.
373
-
374
-
375
- 3. Responsibilities
376
-
377
- 3.1. Distribution of Source Form
378
-
379
- All distribution of Covered Software in Source Code Form, including any
380
- Modifications that You create or to which You contribute, must be under the
381
- terms of this License. You must inform recipients that the Source Code Form
382
- of the Covered Software is governed by the terms of this License, and how
383
- they can obtain a copy of this License. You may not attempt to alter or
384
- restrict the recipients’ rights in the Source Code Form.
385
-
386
- 3.2. Distribution of Executable Form
387
-
388
- If You distribute Covered Software in Executable Form then:
389
-
390
- a. such Covered Software must also be made available in Source Code Form,
391
- as described in Section 3.1, and You must inform recipients of the
392
- Executable Form how they can obtain a copy of such Source Code Form by
393
- reasonable means in a timely manner, at a charge no more than the cost
394
- of distribution to the recipient; and
395
-
396
- b. You may distribute such Executable Form under the terms of this License,
397
- or sublicense it under different terms, provided that the license for
398
- the Executable Form does not attempt to limit or alter the recipients’
399
- rights in the Source Code Form under this License.
400
-
401
- 3.3. Distribution of a Larger Work
402
-
403
- You may create and distribute a Larger Work under terms of Your choice,
404
- provided that You also comply with the requirements of this License for the
405
- Covered Software. If the Larger Work is a combination of Covered Software
406
- with a work governed by one or more Secondary Licenses, and the Covered
407
- Software is not Incompatible With Secondary Licenses, this License permits
408
- You to additionally distribute such Covered Software under the terms of
409
- such Secondary License(s), so that the recipient of the Larger Work may, at
410
- their option, further distribute the Covered Software under the terms of
411
- either this License or such Secondary License(s).
412
-
413
- 3.4. Notices
414
-
415
- You may not remove or alter the substance of any license notices (including
416
- copyright notices, patent notices, disclaimers of warranty, or limitations
417
- of liability) contained within the Source Code Form of the Covered
418
- Software, except that You may alter any license notices to the extent
419
- required to remedy known factual inaccuracies.
420
-
421
- 3.5. Application of Additional Terms
422
-
423
- You may choose to offer, and to charge a fee for, warranty, support,
424
- indemnity or liability obligations to one or more recipients of Covered
425
- Software. However, You may do so only on Your own behalf, and not on behalf
426
- of any Contributor. You must make it absolutely clear that any such
427
- warranty, support, indemnity, or liability obligation is offered by You
428
- alone, and You hereby agree to indemnify every Contributor for any
429
- liability incurred by such Contributor as a result of warranty, support,
430
- indemnity or liability terms You offer. You may include additional
431
- disclaimers of warranty and limitations of liability specific to any
432
- jurisdiction.
433
-
434
- 4. Inability to Comply Due to Statute or Regulation
435
-
436
- If it is impossible for You to comply with any of the terms of this License
437
- with respect to some or all of the Covered Software due to statute, judicial
438
- order, or regulation then You must: (a) comply with the terms of this License
439
- to the maximum extent possible; and (b) describe the limitations and the code
440
- they affect. Such description must be placed in a text file included with all
441
- distributions of the Covered Software under this License. Except to the
442
- extent prohibited by statute or regulation, such description must be
443
- sufficiently detailed for a recipient of ordinary skill to be able to
444
- understand it.
445
-
446
- 5. Termination
447
-
448
- 5.1. The rights granted under this License will terminate automatically if You
449
- fail to comply with any of its terms. However, if You become compliant,
450
- then the rights granted under this License from a particular Contributor
451
- are reinstated (a) provisionally, unless and until such Contributor
452
- explicitly and finally terminates Your grants, and (b) on an ongoing basis,
453
- if such Contributor fails to notify You of the non-compliance by some
454
- reasonable means prior to 60 days after You have come back into compliance.
455
- Moreover, Your grants from a particular Contributor are reinstated on an
456
- ongoing basis if such Contributor notifies You of the non-compliance by
457
- some reasonable means, this is the first time You have received notice of
458
- non-compliance with this License from such Contributor, and You become
459
- compliant prior to 30 days after Your receipt of the notice.
460
-
461
- 5.2. If You initiate litigation against any entity by asserting a patent
462
- infringement claim (excluding declaratory judgment actions, counter-claims,
463
- and cross-claims) alleging that a Contributor Version directly or
464
- indirectly infringes any patent, then the rights granted to You by any and
465
- all Contributors for the Covered Software under Section 2.1 of this License
466
- shall terminate.
467
-
468
- 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
469
- license agreements (excluding distributors and resellers) which have been
470
- validly granted by You or Your distributors under this License prior to
471
- termination shall survive termination.
472
-
473
- 6. Disclaimer of Warranty
474
-
475
- Covered Software is provided under this License on an “as is” basis, without
476
- warranty of any kind, either expressed, implied, or statutory, including,
477
- without limitation, warranties that the Covered Software is free of defects,
478
- merchantable, fit for a particular purpose or non-infringing. The entire
479
- risk as to the quality and performance of the Covered Software is with You.
480
- Should any Covered Software prove defective in any respect, You (not any
481
- Contributor) assume the cost of any necessary servicing, repair, or
482
- correction. This disclaimer of warranty constitutes an essential part of this
483
- License. No use of any Covered Software is authorized under this License
484
- except under this disclaimer.
485
-
486
- 7. Limitation of Liability
487
-
488
- Under no circumstances and under no legal theory, whether tort (including
489
- negligence), contract, or otherwise, shall any Contributor, or anyone who
490
- distributes Covered Software as permitted above, be liable to You for any
491
- direct, indirect, special, incidental, or consequential damages of any
492
- character including, without limitation, damages for lost profits, loss of
493
- goodwill, work stoppage, computer failure or malfunction, or any and all
494
- other commercial damages or losses, even if such party shall have been
495
- informed of the possibility of such damages. This limitation of liability
496
- shall not apply to liability for death or personal injury resulting from such
497
- party’s negligence to the extent applicable law prohibits such limitation.
498
- Some jurisdictions do not allow the exclusion or limitation of incidental or
499
- consequential damages, so this exclusion and limitation may not apply to You.
500
-
501
- 8. Litigation
502
-
503
- Any litigation relating to this License may be brought only in the courts of
504
- a jurisdiction where the defendant maintains its principal place of business
505
- and such litigation shall be governed by laws of that jurisdiction, without
506
- reference to its conflict-of-law provisions. Nothing in this Section shall
507
- prevent a party’s ability to bring cross-claims or counter-claims.
508
-
509
- 9. Miscellaneous
510
-
511
- This License represents the complete agreement concerning the subject matter
512
- hereof. If any provision of this License is held to be unenforceable, such
513
- provision shall be reformed only to the extent necessary to make it
514
- enforceable. Any law or regulation which provides that the language of a
515
- contract shall be construed against the drafter shall not be used to construe
516
- this License against a Contributor.
517
-
518
-
519
- 10. Versions of the License
520
-
521
- 10.1. New Versions
522
-
523
- Mozilla Foundation is the license steward. Except as provided in Section
524
- 10.3, no one other than the license steward has the right to modify or
525
- publish new versions of this License. Each version will be given a
526
- distinguishing version number.
527
-
528
- 10.2. Effect of New Versions
529
-
530
- You may distribute the Covered Software under the terms of the version of
531
- the License under which You originally received the Covered Software, or
532
- under the terms of any subsequent version published by the license
533
- steward.
534
-
535
- 10.3. Modified Versions
536
-
537
- If you create software not governed by this License, and you want to
538
- create a new license for such software, you may create and use a modified
539
- version of this License if you rename the license and remove any
540
- references to the name of the license steward (except to note that such
541
- modified license differs from this License).
542
-
543
- 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
544
- If You choose to distribute Source Code Form that is Incompatible With
545
- Secondary Licenses under the terms of this version of the License, the
546
- notice described in Exhibit B of this License must be attached.
547
-
548
- Exhibit A - Source Code Form License Notice
549
-
550
- This Source Code Form is subject to the
551
- terms of the Mozilla Public License, v.
552
- 2.0. If a copy of the MPL was not
553
- distributed with this file, You can
554
- obtain one at
555
- http://mozilla.org/MPL/2.0/.
556
-
557
- If it is not possible or desirable to put the notice in a particular file, then
558
- You may include the notice in a location (such as a LICENSE file in a relevant
559
- directory) where a recipient would be likely to look for such a notice.
560
-
561
- You may add additional accurate notices of copyright ownership.
562
-
563
- Exhibit B - “Incompatible With Secondary Licenses” Notice
564
-
565
- This Source Code Form is “Incompatible
566
- With Secondary Licenses”, as defined by
567
- the Mozilla Public License, v. 2.0.
568
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/dompurify/README.md DELETED
@@ -1,479 +0,0 @@
1
- # DOMPurify
2
-
3
- [![npm](https://badge.fury.io/js/dompurify.svg)](http://badge.fury.io/js/dompurify) ![Tests](https://github.com/cure53/DOMPurify/workflows/Build%20and%20Test/badge.svg) [![Downloads](https://img.shields.io/npm/dm/dompurify.svg)](https://www.npmjs.com/package/dompurify) ![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/dompurify?color=%233C1&label=gzipped) [![dependents](https://badgen.net/github/dependents-repo/cure53/dompurify?color=green&label=dependents)](https://github.com/cure53/DOMPurify/network/dependents) [![Build Status](https://app.cloudback.it/badge/cure53/DOMPurify)](https://cloudback.it)
4
-
5
- DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.
6
-
7
- It's also very simple to use and get started with. DOMPurify was [started in February 2014](https://github.com/cure53/DOMPurify/commit/a630922616927373485e0e787ab19e73e3691b2b) and, meanwhile, has reached version **v3.3.1**.
8
-
9
- DOMPurify is written in JavaScript and works in all modern browsers (Safari (10+), Opera (15+), Edge, Firefox and Chrome - as well as almost anything else using Blink, Gecko or WebKit). It doesn't break on MSIE or other legacy browsers. It simply does nothing.
10
-
11
- **Note that [DOMPurify v2.5.8](https://github.com/cure53/DOMPurify/releases/tag/2.5.8) is the latest version supporting MSIE. For important security updates compatible with MSIE, please use the [2.x branch](https://github.com/cure53/DOMPurify/tree/2.x).**
12
-
13
- Our automated tests cover [28 different browsers](https://github.com/cure53/DOMPurify/blob/main/test/karma.custom-launchers.config.js#L5) right now, more to come. We also cover Node.js v18.x, v19.x, v20.x, v21.x, v22.x and v23.x, running DOMPurify on [jsdom](https://github.com/jsdom/jsdom). Older Node versions are known to work as well, but hey... no guarantees.
14
-
15
- DOMPurify is written by security people who have vast background in web attacks and XSS. Fear not. For more details please also read about our [Security Goals & Threat Model](https://github.com/cure53/DOMPurify/wiki/Security-Goals-&-Threat-Model). Please, read it. Like, really.
16
-
17
- ## What does it do?
18
-
19
- DOMPurify sanitizes HTML and prevents XSS attacks. You can feed DOMPurify with string full of dirty HTML and it will return a string (unless configured otherwise) with clean HTML. DOMPurify will strip out everything that contains dangerous HTML and thereby prevent XSS attacks and other nastiness. It's also damn bloody fast. We use the technologies the browser provides and turn them into an XSS filter. The faster your browser, the faster DOMPurify will be.
20
-
21
- ## How do I use it?
22
-
23
- It's easy. Just include DOMPurify on your website.
24
-
25
- ### Using the unminified version (source-map available)
26
-
27
- ```html
28
- <script type="text/javascript" src="dist/purify.js"></script>
29
- ```
30
-
31
- ### Using the minified and tested production version (source-map available)
32
-
33
- ```html
34
- <script type="text/javascript" src="dist/purify.min.js"></script>
35
- ```
36
-
37
- Afterwards you can sanitize strings by executing the following code:
38
-
39
- ```js
40
- const clean = DOMPurify.sanitize(dirty);
41
- ```
42
-
43
- Or maybe this, if you love working with Angular or alike:
44
-
45
- ```js
46
- import DOMPurify from 'dompurify';
47
-
48
- const clean = DOMPurify.sanitize('<b>hello there</b>');
49
- ```
50
-
51
- The resulting HTML can be written into a DOM element using `innerHTML` or the DOM using `document.write()`. That is fully up to you.
52
- Note that by default, we permit HTML, SVG **and** MathML. If you only need HTML, which might be a very common use-case, you can easily set that up as well:
53
-
54
- ```js
55
- const clean = DOMPurify.sanitize(dirty, { USE_PROFILES: { html: true } });
56
- ```
57
-
58
- ### Is there any foot-gun potential?
59
-
60
- Well, please note, if you _first_ sanitize HTML and then modify it _afterwards_, you might easily **void the effects of sanitization**. If you feed the sanitized markup to another library _after_ sanitization, please be certain that the library doesn't mess around with the HTML on its own.
61
-
62
- ### Okay, makes sense, let's move on
63
-
64
- After sanitizing your markup, you can also have a look at the property `DOMPurify.removed` and find out, what elements and attributes were thrown out. Please **do not use** this property for making any security critical decisions. This is just a little helper for curious minds.
65
-
66
- ### Running DOMPurify on the server
67
-
68
- DOMPurify technically also works server-side with Node.js. Our support strives to follow the [Node.js release cycle](https://nodejs.org/en/about/releases/).
69
-
70
- Running DOMPurify on the server requires a DOM to be present, which is probably no surprise. Usually, [jsdom](https://github.com/jsdom/jsdom) is the tool of choice and we **strongly recommend** to use the latest version of _jsdom_.
71
-
72
- Why? Because older versions of _jsdom_ are known to be buggy in ways that result in XSS _even if_ DOMPurify does everything 100% correctly. There are **known attack vectors** in, e.g. _jsdom v19.0.0_ that are fixed in _jsdom v20.0.0_ - and we really recommend to keep _jsdom_ up to date because of that.
73
-
74
- Please also be aware that tools like [happy-dom](https://github.com/capricorn86/happy-dom) exist but **are not considered safe** at this point. Combining DOMPurify with _happy-dom_ is currently not recommended and will likely lead to XSS.
75
-
76
- Other than that, you are fine to use DOMPurify on the server. Probably. This really depends on _jsdom_ or whatever DOM you utilize server-side. If you can live with that, this is how you get it to work:
77
-
78
- ```bash
79
- npm install dompurify
80
- npm install jsdom
81
- ```
82
-
83
- For _jsdom_ (please use an up-to-date version), this should do the trick:
84
-
85
- ```js
86
- const createDOMPurify = require('dompurify');
87
- const { JSDOM } = require('jsdom');
88
-
89
- const window = new JSDOM('').window;
90
- const DOMPurify = createDOMPurify(window);
91
- const clean = DOMPurify.sanitize('<b>hello there</b>');
92
- ```
93
-
94
- Or even this, if you prefer working with imports:
95
-
96
- ```js
97
- import { JSDOM } from 'jsdom';
98
- import DOMPurify from 'dompurify';
99
-
100
- const window = new JSDOM('').window;
101
- const purify = DOMPurify(window);
102
- const clean = purify.sanitize('<b>hello there</b>');
103
- ```
104
-
105
- If you have problems making it work in your specific setup, consider looking at the amazing [isomorphic-dompurify](https://github.com/kkomelin/isomorphic-dompurify) project which solves lots of problems people might run into.
106
-
107
- ```bash
108
- npm install isomorphic-dompurify
109
- ```
110
-
111
- ```js
112
- import DOMPurify from 'isomorphic-dompurify';
113
-
114
- const clean = DOMPurify.sanitize('<s>hello</s>');
115
- ```
116
-
117
- ## Is there a demo?
118
-
119
- Of course there is a demo! [Play with DOMPurify](https://cure53.de/purify)
120
-
121
- ## What if I find a _security_ bug?
122
-
123
- First of all, please immediately contact us via [email](mailto:mario@cure53.de) so we can work on a fix. [PGP key](https://keyserver.ubuntu.com/pks/lookup?op=vindex&search=0xC26C858090F70ADA)
124
-
125
- Also, you probably qualify for a bug bounty! The fine folks over at [Fastmail](https://www.fastmail.com/) use DOMPurify for their services and added our library to their bug bounty scope. So, if you find a way to bypass or weaken DOMPurify, please also have a look at their website and the [bug bounty info](https://www.fastmail.com/about/bugbounty/).
126
-
127
- ## Some purification samples please?
128
-
129
- How does purified markup look like? Well, [the demo](https://cure53.de/purify) shows it for a big bunch of nasty elements. But let's also show some smaller examples!
130
-
131
- ```js
132
- DOMPurify.sanitize('<img src=x onerror=alert(1)//>'); // becomes <img src="x">
133
- DOMPurify.sanitize('<svg><g/onload=alert(2)//<p>'); // becomes <svg><g></g></svg>
134
- DOMPurify.sanitize('<p>abc<iframe//src=jAva&Tab;script:alert(3)>def</p>'); // becomes <p>abc</p>
135
- DOMPurify.sanitize('<math><mi//xlink:href="data:x,<script>alert(4)</script>">'); // becomes <math><mi></mi></math>
136
- DOMPurify.sanitize('<TABLE><tr><td>HELLO</tr></TABL>'); // becomes <table><tbody><tr><td>HELLO</td></tr></tbody></table>
137
- DOMPurify.sanitize('<UL><li><A HREF=//google.com>click</UL>'); // becomes <ul><li><a href="//google.com">click</a></li></ul>
138
- ```
139
-
140
- ## What is supported?
141
-
142
- DOMPurify currently supports HTML5, SVG and MathML. DOMPurify per default allows CSS, HTML custom data attributes. DOMPurify also supports the Shadow DOM - and sanitizes DOM templates recursively. DOMPurify also allows you to sanitize HTML for being used with the jQuery `$()` and `elm.html()` API without any known problems.
143
-
144
- ## What about legacy browsers like Internet Explorer?
145
-
146
- DOMPurify does nothing at all. It simply returns exactly the string that you fed it. DOMPurify exposes a property called `isSupported`, which tells you whether it will be able to do its job, so you can come up with your own backup plan.
147
-
148
- ## What about DOMPurify and Trusted Types?
149
-
150
- In version 1.0.9, support for [Trusted Types API](https://github.com/w3c/webappsec-trusted-types) was added to DOMPurify.
151
- In version 2.0.0, a config flag was added to control DOMPurify's behavior regarding this.
152
-
153
- When `DOMPurify.sanitize` is used in an environment where the Trusted Types API is available and `RETURN_TRUSTED_TYPE` is set to `true`, it tries to return a `TrustedHTML` value instead of a string (the behavior for `RETURN_DOM` and `RETURN_DOM_FRAGMENT` config options does not change).
154
-
155
- Note that in order to create a policy in `trustedTypes` using DOMPurify, `RETURN_TRUSTED_TYPE: false` is required, as `createHTML` expects a normal string, not `TrustedHTML`. The example below shows this.
156
-
157
- ```js
158
- window.trustedTypes!.createPolicy('default', {
159
- createHTML: (to_escape) =>
160
- DOMPurify.sanitize(to_escape, { RETURN_TRUSTED_TYPE: false }),
161
- });
162
- ```
163
-
164
- ## Can I configure DOMPurify?
165
-
166
- Yes. The included default configuration values are pretty good already - but you can of course override them. Check out the [`/demos`](https://github.com/cure53/DOMPurify/tree/main/demos) folder to see a bunch of examples on how you can [customize DOMPurify](https://github.com/cure53/DOMPurify/tree/main/demos#what-is-this).
167
-
168
- ### General settings
169
- ```js
170
- // strip {{ ... }}, ${ ... } and <% ... %> to make output safe for template systems
171
- // be careful please, this mode is not recommended for production usage.
172
- // allowing template parsing in user-controlled HTML is not advised at all.
173
- // only use this mode if there is really no alternative.
174
- const clean = DOMPurify.sanitize(dirty, {SAFE_FOR_TEMPLATES: true});
175
-
176
-
177
- // change how e.g. comments containing risky HTML characters are treated.
178
- // be very careful, this setting should only be set to `false` if you really only handle
179
- // HTML and nothing else, no SVG, MathML or the like.
180
- // Otherwise, changing from `true` to `false` will lead to XSS in this or some other way.
181
- const clean = DOMPurify.sanitize(dirty, {SAFE_FOR_XML: false});
182
- ```
183
-
184
- ### Control our allow-lists and block-lists
185
- ```js
186
- // allow only <b> elements, very strict
187
- const clean = DOMPurify.sanitize(dirty, {ALLOWED_TAGS: ['b']});
188
-
189
- // allow only <b> and <q> with style attributes
190
- const clean = DOMPurify.sanitize(dirty, {ALLOWED_TAGS: ['b', 'q'], ALLOWED_ATTR: ['style']});
191
-
192
- // allow all safe HTML elements but neither SVG nor MathML
193
- // note that the USE_PROFILES setting will override the ALLOWED_TAGS setting
194
- // so don't use them together
195
- const clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {html: true}});
196
-
197
- // allow all safe SVG elements and SVG Filters, no HTML or MathML
198
- const clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {svg: true, svgFilters: true}});
199
-
200
- // allow all safe MathML elements and SVG, but no SVG Filters
201
- const clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {mathMl: true, svg: true}});
202
-
203
- // change the default namespace from HTML to something different
204
- const clean = DOMPurify.sanitize(dirty, {NAMESPACE: 'http://www.w3.org/2000/svg'});
205
-
206
- // leave all safe HTML as it is and add <style> elements to block-list
207
- const clean = DOMPurify.sanitize(dirty, {FORBID_TAGS: ['style']});
208
-
209
- // leave all safe HTML as it is and add style attributes to block-list
210
- const clean = DOMPurify.sanitize(dirty, {FORBID_ATTR: ['style']});
211
-
212
- // extend the existing array of allowed tags and add <my-tag> to allow-list
213
- const clean = DOMPurify.sanitize(dirty, {ADD_TAGS: ['my-tag']});
214
-
215
- // extend the existing array of allowed attributes and add my-attr to allow-list
216
- const clean = DOMPurify.sanitize(dirty, {ADD_ATTR: ['my-attr']});
217
-
218
- // use functions to control which additional tags and attributes are allowed
219
- const allowlist = {
220
- 'one': ['attribute-one'],
221
- 'two': ['attribute-two']
222
- };
223
- const clean = DOMPurify.sanitize(
224
- '<one attribute-one="1" attribute-two="2"></one><two attribute-one="1" attribute-two="2"></two>',
225
- {
226
- ADD_TAGS: (tagName) => {
227
- return Object.keys(allowlist).includes(tagName);
228
- },
229
- ADD_ATTR: (attributeName, tagName) => {
230
-
231
- return allowlist[tagName]?.includes(attributeName) || false;
232
- }
233
- }
234
- ); // <one attribute-one="1"></one><two attribute-two="2"></two>
235
-
236
- // prohibit ARIA attributes, leave other safe HTML as is (default is true)
237
- const clean = DOMPurify.sanitize(dirty, {ALLOW_ARIA_ATTR: false});
238
-
239
- // prohibit HTML5 data attributes, leave other safe HTML as is (default is true)
240
- const clean = DOMPurify.sanitize(dirty, {ALLOW_DATA_ATTR: false});
241
- ```
242
-
243
- ### Control behavior relating to Custom Elements
244
- ```js
245
- // DOMPurify allows to define rules for Custom Elements. When using the CUSTOM_ELEMENT_HANDLING
246
- // literal, it is possible to define exactly what elements you wish to allow (by default, none are allowed).
247
- //
248
- // The same goes for their attributes. By default, the built-in or configured allow.list is used.
249
- //
250
- // You can use a RegExp literal to specify what is allowed or a predicate, examples for both can be seen below.
251
- // When using a predicate function for attributeNameCheck, it can optionally receive the tagName as a second parameter
252
- // for more granular control over which attributes are allowed for specific elements.
253
- // The default values are very restrictive to prevent accidental XSS bypasses. Handle with great care!
254
-
255
- const clean = DOMPurify.sanitize(
256
- '<foo-bar baz="foobar" forbidden="true"></foo-bar><div is="foo-baz"></div>',
257
- {
258
- CUSTOM_ELEMENT_HANDLING: {
259
- tagNameCheck: null, // no custom elements are allowed
260
- attributeNameCheck: null, // default / standard attribute allow-list is used
261
- allowCustomizedBuiltInElements: false, // no customized built-ins allowed
262
- },
263
- }
264
- ); // <div is=""></div>
265
-
266
- const clean = DOMPurify.sanitize(
267
- '<foo-bar baz="foobar" forbidden="true"></foo-bar><div is="foo-baz"></div>',
268
- {
269
- CUSTOM_ELEMENT_HANDLING: {
270
- tagNameCheck: /^foo-/, // allow all tags starting with "foo-"
271
- attributeNameCheck: /baz/, // allow all attributes containing "baz"
272
- allowCustomizedBuiltInElements: true, // customized built-ins are allowed
273
- },
274
- }
275
- ); // <foo-bar baz="foobar"></foo-bar><div is="foo-baz"></div>
276
-
277
- const clean = DOMPurify.sanitize(
278
- '<foo-bar baz="foobar" forbidden="true"></foo-bar><div is="foo-baz"></div>',
279
- {
280
- CUSTOM_ELEMENT_HANDLING: {
281
- tagNameCheck: (tagName) => tagName.match(/^foo-/), // allow all tags starting with "foo-"
282
- attributeNameCheck: (attr) => attr.match(/baz/), // allow all containing "baz"
283
- allowCustomizedBuiltInElements: true, // allow customized built-ins
284
- },
285
- }
286
- ); // <foo-bar baz="foobar"></foo-bar><div is="foo-baz"></div>
287
-
288
- // Example with attributeNameCheck receiving tagName as a second parameter
289
- const clean = DOMPurify.sanitize(
290
- '<element-one attribute-one="1" attribute-two="2"></element-one><element-two attribute-one="1" attribute-two="2"></element-two>',
291
- {
292
- CUSTOM_ELEMENT_HANDLING: {
293
- tagNameCheck: (tagName) => tagName.match(/^element-(one|two)$/),
294
- attributeNameCheck: (attr, tagName) => {
295
- if (tagName === 'element-one') {
296
- return ['attribute-one'].includes(attr);
297
- } else if (tagName === 'element-two') {
298
- return ['attribute-two'].includes(attr);
299
- } else {
300
- return false;
301
- }
302
- },
303
- allowCustomizedBuiltInElements: false,
304
- },
305
- }
306
- ); // <element-one attribute-one="1"></element-one><element-two attribute-two="2"></element-two>
307
- ```
308
- ### Control behavior relating to URI values
309
- ```js
310
- // extend the existing array of elements that can use Data URIs
311
- const clean = DOMPurify.sanitize(dirty, {ADD_DATA_URI_TAGS: ['a', 'area']});
312
-
313
- // extend the existing array of elements that are safe for URI-like values (be careful, XSS risk)
314
- const clean = DOMPurify.sanitize(dirty, {ADD_URI_SAFE_ATTR: ['my-attr']});
315
-
316
- ```
317
- ### Control permitted attribute values
318
- ```js
319
- // allow external protocol handlers in URL attributes (default is false, be careful, XSS risk)
320
- // by default only http, https, ftp, ftps, tel, mailto, callto, sms, cid and xmpp are allowed.
321
- const clean = DOMPurify.sanitize(dirty, {ALLOW_UNKNOWN_PROTOCOLS: true});
322
-
323
- // allow specific protocols handlers in URL attributes via regex (default is false, be careful, XSS risk)
324
- // by default only (protocol-)relative URLs, http, https, ftp, ftps, tel, mailto, callto, sms, cid, xmpp and matrix are allowed.
325
- // Default RegExp: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
326
- const clean = DOMPurify.sanitize(dirty, {ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i});
327
-
328
- ```
329
- ### Influence the return-type
330
- ```js
331
- // return a DOM HTMLBodyElement instead of an HTML string (default is false)
332
- const clean = DOMPurify.sanitize(dirty, {RETURN_DOM: true});
333
-
334
- // return a DOM DocumentFragment instead of an HTML string (default is false)
335
- const clean = DOMPurify.sanitize(dirty, {RETURN_DOM_FRAGMENT: true});
336
-
337
- // use the RETURN_TRUSTED_TYPE flag to turn on Trusted Types support if available
338
- const clean = DOMPurify.sanitize(dirty, {RETURN_TRUSTED_TYPE: true}); // will return a TrustedHTML object instead of a string if possible
339
-
340
- // use a provided Trusted Types policy
341
- const clean = DOMPurify.sanitize(dirty, {
342
- // supplied policy must define createHTML and createScriptURL
343
- TRUSTED_TYPES_POLICY: trustedTypes.createPolicy({
344
- createHTML(s) { return s},
345
- createScriptURL(s) { return s},
346
- })
347
- });
348
- ```
349
- ### Influence how we sanitize
350
- ```js
351
- // return entire document including <html> tags (default is false)
352
- const clean = DOMPurify.sanitize(dirty, {WHOLE_DOCUMENT: true});
353
-
354
- // disable DOM Clobbering protection on output (default is true, handle with care, minor XSS risks here)
355
- const clean = DOMPurify.sanitize(dirty, {SANITIZE_DOM: false});
356
-
357
- // enforce strict DOM Clobbering protection via namespace isolation (default is false)
358
- // when enabled, isolates the namespace of named properties (i.e., `id` and `name` attributes)
359
- // from JS variables by prefixing them with the string `user-content-`
360
- const clean = DOMPurify.sanitize(dirty, {SANITIZE_NAMED_PROPS: true});
361
-
362
- // keep an element's content when the element is removed (default is true)
363
- const clean = DOMPurify.sanitize(dirty, {KEEP_CONTENT: false});
364
-
365
- // glue elements like style, script or others to document.body and prevent unintuitive browser behavior in several edge-cases (default is false)
366
- const clean = DOMPurify.sanitize(dirty, {FORCE_BODY: true});
367
-
368
- // remove all <a> elements under <p> elements that are removed
369
- const clean = DOMPurify.sanitize(dirty, {FORBID_CONTENTS: ['a'], FORBID_TAGS: ['p']});
370
-
371
- // extend the default FORBID_CONTENTS list to also remove <a> elements under <p> elements
372
- const clean = DOMPurify.sanitize(dirty, {ADD_FORBID_CONTENTS: ['a'], FORBID_TAGS: ['p']});
373
-
374
- // change the parser type so sanitized data is treated as XML and not as HTML, which is the default
375
- const clean = DOMPurify.sanitize(dirty, {PARSER_MEDIA_TYPE: 'application/xhtml+xml'});
376
- ```
377
- ### Influence where we sanitize
378
- ```js
379
- // use the IN_PLACE mode to sanitize a node "in place", which is much faster depending on how you use DOMPurify
380
- const dirty = document.createElement('a');
381
- dirty.setAttribute('href', 'javascript:alert(1)');
382
-
383
- const clean = DOMPurify.sanitize(dirty, {IN_PLACE: true}); // see https://github.com/cure53/DOMPurify/issues/288 for more info
384
- ```
385
-
386
- There is even [more examples here](https://github.com/cure53/DOMPurify/tree/main/demos#what-is-this), showing how you can run, customize and configure DOMPurify to fit your needs.
387
-
388
- ## Persistent Configuration
389
-
390
- Instead of repeatedly passing the same configuration to `DOMPurify.sanitize`, you can use the `DOMPurify.setConfig` method. Your configuration will persist until your next call to `DOMPurify.setConfig`, or until you invoke `DOMPurify.clearConfig` to reset it. Remember that there is only one active configuration, which means once it is set, all extra configuration parameters passed to `DOMPurify.sanitize` are ignored.
391
-
392
- ## Hooks
393
-
394
- DOMPurify allows you to augment its functionality by attaching one or more functions with the `DOMPurify.addHook` method to one of the following hooks:
395
-
396
- - `beforeSanitizeElements`
397
- - `uponSanitizeElement` (No 's' - called for every element)
398
- - `afterSanitizeElements`
399
- - `beforeSanitizeAttributes`
400
- - `uponSanitizeAttribute`
401
- - `afterSanitizeAttributes`
402
- - `beforeSanitizeShadowDOM`
403
- - `uponSanitizeShadowNode`
404
- - `afterSanitizeShadowDOM`
405
-
406
- It passes the currently processed DOM node, when needed a literal with verified node and attribute data and the DOMPurify configuration to the callback. Check out the [MentalJS hook demo](https://github.com/cure53/DOMPurify/blob/main/demos/hooks-mentaljs-demo.html) to see how the API can be used nicely.
407
-
408
- _Example_:
409
-
410
- ```js
411
- DOMPurify.addHook(
412
- 'uponSanitizeAttribute',
413
- function (currentNode, hookEvent, config) {
414
- // Do something with the current node
415
- // You can also mutate hookEvent for current node (i.e. set hookEvent.forceKeepAttr = true)
416
- // For other than 'uponSanitizeAttribute' hook types hookEvent equals to null
417
- }
418
- );
419
- ```
420
-
421
- ## Removed Configuration
422
-
423
- | Option | Since | Note |
424
- |-----------------|-------|--------------------------|
425
- | SAFE_FOR_JQUERY | 2.1.0 | No replacement required. |
426
-
427
- ## Continuous Integration
428
-
429
- We are currently using Github Actions in combination with BrowserStack. This gives us the possibility to confirm for each and every commit that all is going according to plan in all supported browsers. Check out the build logs here: https://github.com/cure53/DOMPurify/actions
430
-
431
- You can further run local tests by executing `npm run test`.
432
-
433
- All relevant commits will be signed with the key `0x24BB6BF4` for additional security (since 8th of April 2016).
434
-
435
- ### Development and contributing
436
-
437
- #### Installation (`npm i`)
438
-
439
- We support `npm` officially. GitHub Actions workflow is configured to install dependencies using `npm`. When using deprecated version of `npm` we can not fully ensure the versions of installed dependencies which might lead to unanticipated problems.
440
-
441
- #### Scripts
442
-
443
- We rely on npm run-scripts for integrating with our tooling infrastructure. We use ESLint as a pre-commit hook to ensure code consistency. Moreover, to ease formatting we use [prettier](https://github.com/prettier/prettier) while building the `/dist` assets happens through `rollup`.
444
-
445
- These are our npm scripts:
446
-
447
- - `npm run dev` to start building while watching sources for changes
448
- - `npm run test` to run our test suite via jsdom and karma
449
- - `test:jsdom` to only run tests through jsdom
450
- - `test:karma` to only run tests through karma
451
- - `npm run lint` to lint the sources using ESLint (via xo)
452
- - `npm run format` to format our sources using prettier to ease to pass ESLint
453
- - `npm run build` to build our distribution assets minified and unminified as a UMD module
454
- - `npm run build:umd` to only build an unminified UMD module
455
- - `npm run build:umd:min` to only build a minified UMD module
456
-
457
- Note: all run scripts triggered via `npm run <script>`.
458
-
459
- There are more npm scripts but they are mainly to integrate with CI or are meant to be "private" for instance to amend build distribution files with every commit.
460
-
461
- ## Security Mailing List
462
-
463
- We maintain a mailing list that notifies whenever a security-critical release of DOMPurify was published. This means, if someone found a bypass and we fixed it with a release (which always happens when a bypass was found) a mail will go out to that list. This usually happens within minutes or few hours after learning about a bypass. The list can be subscribed to here:
464
-
465
- [https://lists.ruhr-uni-bochum.de/mailman/listinfo/dompurify-security](https://lists.ruhr-uni-bochum.de/mailman/listinfo/dompurify-security)
466
-
467
- Feature releases will not be announced to this list.
468
-
469
- ## Who contributed?
470
-
471
- Many people helped and help DOMPurify become what it is and need to be acknowledged here!
472
-
473
- [Cybozu 💛💸](https://github.com/cybozu), [hata6502 💸](https://github.com/hata6502), [intra-mart-dh 💸](https://github.com/intra-mart-dh), [nelstrom ❤️](https://github.com/nelstrom), [hash_kitten ❤️](https://twitter.com/hash_kitten), [kevin_mizu ❤️](https://twitter.com/kevin_mizu), [icesfont ❤️](https://github.com/icesfont), [reduckted ❤️](https://github.com/reduckted), [dcramer 💸](https://github.com/dcramer), [JGraph 💸](https://github.com/jgraph), [baekilda 💸](https://github.com/baekilda), [Healthchecks 💸](https://github.com/healthchecks), [Sentry 💸](https://github.com/getsentry), [jarrodldavis 💸](https://github.com/jarrodldavis), [CynegeticIO](https://github.com/CynegeticIO), [ssi02014 ❤️](https://github.com/ssi02014), [GrantGryczan](https://github.com/GrantGryczan), [Lowdefy](https://twitter.com/lowdefy), [granlem](https://twitter.com/MaximeVeit), [oreoshake](https://github.com/oreoshake), [tdeekens ❤️](https://github.com/tdeekens), [peernohell ❤️](https://github.com/peernohell), [is2ei](https://github.com/is2ei), [SoheilKhodayari](https://github.com/SoheilKhodayari), [franktopel](https://github.com/franktopel), [NateScarlet](https://github.com/NateScarlet), [neilj](https://github.com/neilj), [fhemberger](https://github.com/fhemberger), [Joris-van-der-Wel](https://github.com/Joris-van-der-Wel), [ydaniv](https://github.com/ydaniv), [terjanq](https://twitter.com/terjanq), [filedescriptor](https://github.com/filedescriptor), [ConradIrwin](https://github.com/ConradIrwin), [gibson042](https://github.com/gibson042), [choumx](https://github.com/choumx), [0xSobky](https://github.com/0xSobky), [styfle](https://github.com/styfle), [koto](https://github.com/koto), [tlau88](https://github.com/tlau88), [strugee](https://github.com/strugee), [oparoz](https://github.com/oparoz), [mathiasbynens](https://github.com/mathiasbynens), [edg2s](https://github.com/edg2s), [dnkolegov](https://github.com/dnkolegov), [dhardtke](https://github.com/dhardtke), [wirehead](https://github.com/wirehead), [thorn0](https://github.com/thorn0), [styu](https://github.com/styu), [mozfreddyb](https://github.com/mozfreddyb), [mikesamuel](https://github.com/mikesamuel), [jorangreef](https://github.com/jorangreef), [jimmyhchan](https://github.com/jimmyhchan), [jameydeorio](https://github.com/jameydeorio), [jameskraus](https://github.com/jameskraus), [hyderali](https://github.com/hyderali), [hansottowirtz](https://github.com/hansottowirtz), [hackvertor](https://github.com/hackvertor), [freddyb](https://github.com/freddyb), [flavorjones](https://github.com/flavorjones), [djfarrelly](https://github.com/djfarrelly), [devd](https://github.com/devd), [camerondunford](https://github.com/camerondunford), [buu700](https://github.com/buu700), [buildog](https://github.com/buildog), [alabiaga](https://github.com/alabiaga), [Vector919](https://github.com/Vector919), [Robbert](https://github.com/Robbert), [GreLI](https://github.com/GreLI), [FuzzySockets](https://github.com/FuzzySockets), [ArtemBernatskyy](https://github.com/ArtemBernatskyy), [@garethheyes](https://twitter.com/garethheyes), [@shafigullin](https://twitter.com/shafigullin), [@mmrupp](https://twitter.com/mmrupp), [@irsdl](https://twitter.com/irsdl),[ShikariSenpai](https://github.com/ShikariSenpai), [ansjdnakjdnajkd](https://github.com/ansjdnakjdnajkd), [@asutherland](https://twitter.com/asutherland), [@mathias](https://twitter.com/mathias), [@cgvwzq](https://twitter.com/cgvwzq), [@robbertatwork](https://twitter.com/robbertatwork), [@giutro](https://twitter.com/giutro), [@CmdEngineer\_](https://twitter.com/CmdEngineer_), [@avr4mit](https://twitter.com/avr4mit), [davecardwell](https://github.com/davecardwell) and especially [@securitymb ❤️](https://twitter.com/securitymb) & [@masatokinugawa ❤️](https://twitter.com/masatokinugawa)
474
-
475
- ## Testing powered by
476
-
477
- <a target="_blank" href="https://www.browserstack.com/"><img width="200" src="https://github.com/cure53/DOMPurify/assets/6709482/f70be7eb-8fc4-41ea-9653-9d359235328f"></a><br>
478
-
479
- And last but not least, thanks to [BrowserStack Open-Source Program](https://www.browserstack.com/open-source) for supporting this project with their services for free and delivering excellent, dedicated and very professional support on top of that.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/dompurify/dist/purify.cjs.d.ts DELETED
@@ -1,450 +0,0 @@
1
- /*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
2
-
3
- import { TrustedTypePolicy, TrustedHTML, TrustedTypesWindow } from 'trusted-types/lib/index.js';
4
-
5
- /**
6
- * Configuration to control DOMPurify behavior.
7
- */
8
- interface Config {
9
- /**
10
- * Extend the existing array of allowed attributes.
11
- * Can be an array of attribute names, or a function that receives
12
- * the attribute name and tag name to determine if the attribute is allowed.
13
- */
14
- ADD_ATTR?: string[] | ((attributeName: string, tagName: string) => boolean) | undefined;
15
- /**
16
- * Extend the existing array of elements that can use Data URIs.
17
- */
18
- ADD_DATA_URI_TAGS?: string[] | undefined;
19
- /**
20
- * Extend the existing array of allowed tags.
21
- * Can be an array of tag names, or a function that receives
22
- * the tag name to determine if the tag is allowed.
23
- */
24
- ADD_TAGS?: string[] | ((tagName: string) => boolean) | undefined;
25
- /**
26
- * Extend the existing array of elements that are safe for URI-like values (be careful, XSS risk).
27
- */
28
- ADD_URI_SAFE_ATTR?: string[] | undefined;
29
- /**
30
- * Allow ARIA attributes, leave other safe HTML as is (default is true).
31
- */
32
- ALLOW_ARIA_ATTR?: boolean | undefined;
33
- /**
34
- * Allow HTML5 data attributes, leave other safe HTML as is (default is true).
35
- */
36
- ALLOW_DATA_ATTR?: boolean | undefined;
37
- /**
38
- * Allow external protocol handlers in URL attributes (default is false, be careful, XSS risk).
39
- * By default only `http`, `https`, `ftp`, `ftps`, `tel`, `mailto`, `callto`, `sms`, `cid` and `xmpp` are allowed.
40
- */
41
- ALLOW_UNKNOWN_PROTOCOLS?: boolean | undefined;
42
- /**
43
- * Decide if self-closing tags in attributes are allowed.
44
- * Usually removed due to a mXSS issue in jQuery 3.0.
45
- */
46
- ALLOW_SELF_CLOSE_IN_ATTR?: boolean | undefined;
47
- /**
48
- * Allow only specific attributes.
49
- */
50
- ALLOWED_ATTR?: string[] | undefined;
51
- /**
52
- * Allow only specific elements.
53
- */
54
- ALLOWED_TAGS?: string[] | undefined;
55
- /**
56
- * Allow only specific namespaces. Defaults to:
57
- * - `http://www.w3.org/1999/xhtml`
58
- * - `http://www.w3.org/2000/svg`
59
- * - `http://www.w3.org/1998/Math/MathML`
60
- */
61
- ALLOWED_NAMESPACES?: string[] | undefined;
62
- /**
63
- * Allow specific protocols handlers in URL attributes via regex (be careful, XSS risk).
64
- * Default RegExp:
65
- * ```
66
- * /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
67
- * ```
68
- */
69
- ALLOWED_URI_REGEXP?: RegExp | undefined;
70
- /**
71
- * Define how custom elements are handled.
72
- */
73
- CUSTOM_ELEMENT_HANDLING?: {
74
- /**
75
- * Regular expression or function to match to allowed elements.
76
- * Default is null (disallow any custom elements).
77
- */
78
- tagNameCheck?: RegExp | ((tagName: string) => boolean) | null | undefined;
79
- /**
80
- * Regular expression or function to match to allowed attributes.
81
- * Default is null (disallow any attributes not on the allow list).
82
- */
83
- attributeNameCheck?: RegExp | ((attributeName: string, tagName?: string) => boolean) | null | undefined;
84
- /**
85
- * Allow custom elements derived from built-ins if they pass `tagNameCheck`. Default is false.
86
- */
87
- allowCustomizedBuiltInElements?: boolean | undefined;
88
- };
89
- /**
90
- * Add attributes to block-list.
91
- */
92
- FORBID_ATTR?: string[] | undefined;
93
- /**
94
- * Add child elements to be removed when their parent is removed.
95
- */
96
- FORBID_CONTENTS?: string[] | undefined;
97
- /**
98
- * Extend the existing or default array of forbidden content elements.
99
- */
100
- ADD_FORBID_CONTENTS?: string[] | undefined;
101
- /**
102
- * Add elements to block-list.
103
- */
104
- FORBID_TAGS?: string[] | undefined;
105
- /**
106
- * Glue elements like style, script or others to `document.body` and prevent unintuitive browser behavior in several edge-cases (default is false).
107
- */
108
- FORCE_BODY?: boolean | undefined;
109
- /**
110
- * Map of non-standard HTML element names to support. Map to true to enable support. For example:
111
- *
112
- * ```
113
- * HTML_INTEGRATION_POINTS: { foreignobject: true }
114
- * ```
115
- */
116
- HTML_INTEGRATION_POINTS?: Record<string, boolean> | undefined;
117
- /**
118
- * Sanitize a node "in place", which is much faster depending on how you use DOMPurify.
119
- */
120
- IN_PLACE?: boolean | undefined;
121
- /**
122
- * Keep an element's content when the element is removed (default is true).
123
- */
124
- KEEP_CONTENT?: boolean | undefined;
125
- /**
126
- * Map of MathML element names to support. Map to true to enable support. For example:
127
- *
128
- * ```
129
- * MATHML_TEXT_INTEGRATION_POINTS: { mtext: true }
130
- * ```
131
- */
132
- MATHML_TEXT_INTEGRATION_POINTS?: Record<string, boolean> | undefined;
133
- /**
134
- * Change the default namespace from HTML to something different.
135
- */
136
- NAMESPACE?: string | undefined;
137
- /**
138
- * Change the parser type so sanitized data is treated as XML and not as HTML, which is the default.
139
- */
140
- PARSER_MEDIA_TYPE?: DOMParserSupportedType | undefined;
141
- /**
142
- * Return a DOM `DocumentFragment` instead of an HTML string (default is false).
143
- */
144
- RETURN_DOM_FRAGMENT?: boolean | undefined;
145
- /**
146
- * Return a DOM `HTMLBodyElement` instead of an HTML string (default is false).
147
- */
148
- RETURN_DOM?: boolean | undefined;
149
- /**
150
- * Return a TrustedHTML object instead of a string if possible.
151
- */
152
- RETURN_TRUSTED_TYPE?: boolean | undefined;
153
- /**
154
- * Strip `{{ ... }}`, `${ ... }` and `<% ... %>` to make output safe for template systems.
155
- * Be careful please, this mode is not recommended for production usage.
156
- * Allowing template parsing in user-controlled HTML is not advised at all.
157
- * Only use this mode if there is really no alternative.
158
- */
159
- SAFE_FOR_TEMPLATES?: boolean | undefined;
160
- /**
161
- * Change how e.g. comments containing risky HTML characters are treated.
162
- * Be very careful, this setting should only be set to `false` if you really only handle
163
- * HTML and nothing else, no SVG, MathML or the like.
164
- * Otherwise, changing from `true` to `false` will lead to XSS in this or some other way.
165
- */
166
- SAFE_FOR_XML?: boolean | undefined;
167
- /**
168
- * Use DOM Clobbering protection on output (default is true, handle with care, minor XSS risks here).
169
- */
170
- SANITIZE_DOM?: boolean | undefined;
171
- /**
172
- * Enforce strict DOM Clobbering protection via namespace isolation (default is false).
173
- * When enabled, isolates the namespace of named properties (i.e., `id` and `name` attributes)
174
- * from JS variables by prefixing them with the string `user-content-`
175
- */
176
- SANITIZE_NAMED_PROPS?: boolean | undefined;
177
- /**
178
- * Supplied policy must define `createHTML` and `createScriptURL`.
179
- */
180
- TRUSTED_TYPES_POLICY?: TrustedTypePolicy | undefined;
181
- /**
182
- * Controls categories of allowed elements.
183
- *
184
- * Note that the `USE_PROFILES` setting will override the `ALLOWED_TAGS` setting
185
- * so don't use them together.
186
- */
187
- USE_PROFILES?: false | UseProfilesConfig | undefined;
188
- /**
189
- * Return entire document including <html> tags (default is false).
190
- */
191
- WHOLE_DOCUMENT?: boolean | undefined;
192
- }
193
- /**
194
- * Defines categories of allowed elements.
195
- */
196
- interface UseProfilesConfig {
197
- /**
198
- * Allow all safe MathML elements.
199
- */
200
- mathMl?: boolean | undefined;
201
- /**
202
- * Allow all safe SVG elements.
203
- */
204
- svg?: boolean | undefined;
205
- /**
206
- * Allow all save SVG Filters.
207
- */
208
- svgFilters?: boolean | undefined;
209
- /**
210
- * Allow all safe HTML elements.
211
- */
212
- html?: boolean | undefined;
213
- }
214
-
215
- declare const _default: DOMPurify;
216
-
217
- interface DOMPurify {
218
- /**
219
- * Creates a DOMPurify instance using the given window-like object. Defaults to `window`.
220
- */
221
- (root?: WindowLike): DOMPurify;
222
- /**
223
- * Version label, exposed for easier checks
224
- * if DOMPurify is up to date or not
225
- */
226
- version: string;
227
- /**
228
- * Array of elements that DOMPurify removed during sanitation.
229
- * Empty if nothing was removed.
230
- */
231
- removed: Array<RemovedElement | RemovedAttribute>;
232
- /**
233
- * Expose whether this browser supports running the full DOMPurify.
234
- */
235
- isSupported: boolean;
236
- /**
237
- * Set the configuration once.
238
- *
239
- * @param cfg configuration object
240
- */
241
- setConfig(cfg?: Config): void;
242
- /**
243
- * Removes the configuration.
244
- */
245
- clearConfig(): void;
246
- /**
247
- * Provides core sanitation functionality.
248
- *
249
- * @param dirty string or DOM node
250
- * @param cfg object
251
- * @returns Sanitized TrustedHTML.
252
- */
253
- sanitize(dirty: string | Node, cfg: Config & {
254
- RETURN_TRUSTED_TYPE: true;
255
- }): TrustedHTML;
256
- /**
257
- * Provides core sanitation functionality.
258
- *
259
- * @param dirty DOM node
260
- * @param cfg object
261
- * @returns Sanitized DOM node.
262
- */
263
- sanitize(dirty: Node, cfg: Config & {
264
- IN_PLACE: true;
265
- }): Node;
266
- /**
267
- * Provides core sanitation functionality.
268
- *
269
- * @param dirty string or DOM node
270
- * @param cfg object
271
- * @returns Sanitized DOM node.
272
- */
273
- sanitize(dirty: string | Node, cfg: Config & {
274
- RETURN_DOM: true;
275
- }): Node;
276
- /**
277
- * Provides core sanitation functionality.
278
- *
279
- * @param dirty string or DOM node
280
- * @param cfg object
281
- * @returns Sanitized document fragment.
282
- */
283
- sanitize(dirty: string | Node, cfg: Config & {
284
- RETURN_DOM_FRAGMENT: true;
285
- }): DocumentFragment;
286
- /**
287
- * Provides core sanitation functionality.
288
- *
289
- * @param dirty string or DOM node
290
- * @param cfg object
291
- * @returns Sanitized string.
292
- */
293
- sanitize(dirty: string | Node, cfg?: Config): string;
294
- /**
295
- * Checks if an attribute value is valid.
296
- * Uses last set config, if any. Otherwise, uses config defaults.
297
- *
298
- * @param tag Tag name of containing element.
299
- * @param attr Attribute name.
300
- * @param value Attribute value.
301
- * @returns Returns true if `value` is valid. Otherwise, returns false.
302
- */
303
- isValidAttribute(tag: string, attr: string, value: string): boolean;
304
- /**
305
- * Adds a DOMPurify hook.
306
- *
307
- * @param entryPoint entry point for the hook to add
308
- * @param hookFunction function to execute
309
- */
310
- addHook(entryPoint: BasicHookName, hookFunction: NodeHook): void;
311
- /**
312
- * Adds a DOMPurify hook.
313
- *
314
- * @param entryPoint entry point for the hook to add
315
- * @param hookFunction function to execute
316
- */
317
- addHook(entryPoint: ElementHookName, hookFunction: ElementHook): void;
318
- /**
319
- * Adds a DOMPurify hook.
320
- *
321
- * @param entryPoint entry point for the hook to add
322
- * @param hookFunction function to execute
323
- */
324
- addHook(entryPoint: DocumentFragmentHookName, hookFunction: DocumentFragmentHook): void;
325
- /**
326
- * Adds a DOMPurify hook.
327
- *
328
- * @param entryPoint entry point for the hook to add
329
- * @param hookFunction function to execute
330
- */
331
- addHook(entryPoint: 'uponSanitizeElement', hookFunction: UponSanitizeElementHook): void;
332
- /**
333
- * Adds a DOMPurify hook.
334
- *
335
- * @param entryPoint entry point for the hook to add
336
- * @param hookFunction function to execute
337
- */
338
- addHook(entryPoint: 'uponSanitizeAttribute', hookFunction: UponSanitizeAttributeHook): void;
339
- /**
340
- * Remove a DOMPurify hook at a given entryPoint
341
- * (pops it from the stack of hooks if hook not specified)
342
- *
343
- * @param entryPoint entry point for the hook to remove
344
- * @param hookFunction optional specific hook to remove
345
- * @returns removed hook
346
- */
347
- removeHook(entryPoint: BasicHookName, hookFunction?: NodeHook): NodeHook | undefined;
348
- /**
349
- * Remove a DOMPurify hook at a given entryPoint
350
- * (pops it from the stack of hooks if hook not specified)
351
- *
352
- * @param entryPoint entry point for the hook to remove
353
- * @param hookFunction optional specific hook to remove
354
- * @returns removed hook
355
- */
356
- removeHook(entryPoint: ElementHookName, hookFunction?: ElementHook): ElementHook | undefined;
357
- /**
358
- * Remove a DOMPurify hook at a given entryPoint
359
- * (pops it from the stack of hooks if hook not specified)
360
- *
361
- * @param entryPoint entry point for the hook to remove
362
- * @param hookFunction optional specific hook to remove
363
- * @returns removed hook
364
- */
365
- removeHook(entryPoint: DocumentFragmentHookName, hookFunction?: DocumentFragmentHook): DocumentFragmentHook | undefined;
366
- /**
367
- * Remove a DOMPurify hook at a given entryPoint
368
- * (pops it from the stack of hooks if hook not specified)
369
- *
370
- * @param entryPoint entry point for the hook to remove
371
- * @param hookFunction optional specific hook to remove
372
- * @returns removed hook
373
- */
374
- removeHook(entryPoint: 'uponSanitizeElement', hookFunction?: UponSanitizeElementHook): UponSanitizeElementHook | undefined;
375
- /**
376
- * Remove a DOMPurify hook at a given entryPoint
377
- * (pops it from the stack of hooks if hook not specified)
378
- *
379
- * @param entryPoint entry point for the hook to remove
380
- * @param hookFunction optional specific hook to remove
381
- * @returns removed hook
382
- */
383
- removeHook(entryPoint: 'uponSanitizeAttribute', hookFunction?: UponSanitizeAttributeHook): UponSanitizeAttributeHook | undefined;
384
- /**
385
- * Removes all DOMPurify hooks at a given entryPoint
386
- *
387
- * @param entryPoint entry point for the hooks to remove
388
- */
389
- removeHooks(entryPoint: HookName): void;
390
- /**
391
- * Removes all DOMPurify hooks.
392
- */
393
- removeAllHooks(): void;
394
- }
395
- /**
396
- * An element removed by DOMPurify.
397
- */
398
- interface RemovedElement {
399
- /**
400
- * The element that was removed.
401
- */
402
- element: Node;
403
- }
404
- /**
405
- * An element removed by DOMPurify.
406
- */
407
- interface RemovedAttribute {
408
- /**
409
- * The attribute that was removed.
410
- */
411
- attribute: Attr | null;
412
- /**
413
- * The element that the attribute was removed.
414
- */
415
- from: Node;
416
- }
417
- type BasicHookName = 'beforeSanitizeElements' | 'afterSanitizeElements' | 'uponSanitizeShadowNode';
418
- type ElementHookName = 'beforeSanitizeAttributes' | 'afterSanitizeAttributes';
419
- type DocumentFragmentHookName = 'beforeSanitizeShadowDOM' | 'afterSanitizeShadowDOM';
420
- type UponSanitizeElementHookName = 'uponSanitizeElement';
421
- type UponSanitizeAttributeHookName = 'uponSanitizeAttribute';
422
- type HookName = BasicHookName | ElementHookName | DocumentFragmentHookName | UponSanitizeElementHookName | UponSanitizeAttributeHookName;
423
- type NodeHook = (this: DOMPurify, currentNode: Node, hookEvent: null, config: Config) => void;
424
- type ElementHook = (this: DOMPurify, currentNode: Element, hookEvent: null, config: Config) => void;
425
- type DocumentFragmentHook = (this: DOMPurify, currentNode: DocumentFragment, hookEvent: null, config: Config) => void;
426
- type UponSanitizeElementHook = (this: DOMPurify, currentNode: Node, hookEvent: UponSanitizeElementHookEvent, config: Config) => void;
427
- type UponSanitizeAttributeHook = (this: DOMPurify, currentNode: Element, hookEvent: UponSanitizeAttributeHookEvent, config: Config) => void;
428
- interface UponSanitizeElementHookEvent {
429
- tagName: string;
430
- allowedTags: Record<string, boolean>;
431
- }
432
- interface UponSanitizeAttributeHookEvent {
433
- attrName: string;
434
- attrValue: string;
435
- keepAttr: boolean;
436
- allowedAttributes: Record<string, boolean>;
437
- forceKeepAttr: boolean | undefined;
438
- }
439
- /**
440
- * A `Window`-like object containing the properties and types that DOMPurify requires.
441
- */
442
- type WindowLike = Pick<typeof globalThis, 'DocumentFragment' | 'HTMLTemplateElement' | 'Node' | 'Element' | 'NodeFilter' | 'NamedNodeMap' | 'HTMLFormElement' | 'DOMParser'> & {
443
- document?: Document;
444
- MozNamedAttrMap?: typeof window.NamedNodeMap;
445
- } & Pick<TrustedTypesWindow, 'trustedTypes'>;
446
-
447
- export { type Config, type DOMPurify, type DocumentFragmentHook, type ElementHook, type HookName, type NodeHook, type RemovedAttribute, type RemovedElement, type UponSanitizeAttributeHook, type UponSanitizeAttributeHookEvent, type UponSanitizeElementHook, type UponSanitizeElementHookEvent, type WindowLike };
448
-
449
- // @ts-ignore
450
- export = _default;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/dompurify/dist/purify.cjs.js DELETED
@@ -1,1388 +0,0 @@
1
- /*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
2
-
3
- 'use strict';
4
-
5
- const {
6
- entries,
7
- setPrototypeOf,
8
- isFrozen,
9
- getPrototypeOf,
10
- getOwnPropertyDescriptor
11
- } = Object;
12
- let {
13
- freeze,
14
- seal,
15
- create
16
- } = Object; // eslint-disable-line import/no-mutable-exports
17
- let {
18
- apply,
19
- construct
20
- } = typeof Reflect !== 'undefined' && Reflect;
21
- if (!freeze) {
22
- freeze = function freeze(x) {
23
- return x;
24
- };
25
- }
26
- if (!seal) {
27
- seal = function seal(x) {
28
- return x;
29
- };
30
- }
31
- if (!apply) {
32
- apply = function apply(func, thisArg) {
33
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
34
- args[_key - 2] = arguments[_key];
35
- }
36
- return func.apply(thisArg, args);
37
- };
38
- }
39
- if (!construct) {
40
- construct = function construct(Func) {
41
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
42
- args[_key2 - 1] = arguments[_key2];
43
- }
44
- return new Func(...args);
45
- };
46
- }
47
- const arrayForEach = unapply(Array.prototype.forEach);
48
- const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
49
- const arrayPop = unapply(Array.prototype.pop);
50
- const arrayPush = unapply(Array.prototype.push);
51
- const arraySplice = unapply(Array.prototype.splice);
52
- const stringToLowerCase = unapply(String.prototype.toLowerCase);
53
- const stringToString = unapply(String.prototype.toString);
54
- const stringMatch = unapply(String.prototype.match);
55
- const stringReplace = unapply(String.prototype.replace);
56
- const stringIndexOf = unapply(String.prototype.indexOf);
57
- const stringTrim = unapply(String.prototype.trim);
58
- const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
59
- const regExpTest = unapply(RegExp.prototype.test);
60
- const typeErrorCreate = unconstruct(TypeError);
61
- /**
62
- * Creates a new function that calls the given function with a specified thisArg and arguments.
63
- *
64
- * @param func - The function to be wrapped and called.
65
- * @returns A new function that calls the given function with a specified thisArg and arguments.
66
- */
67
- function unapply(func) {
68
- return function (thisArg) {
69
- if (thisArg instanceof RegExp) {
70
- thisArg.lastIndex = 0;
71
- }
72
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
73
- args[_key3 - 1] = arguments[_key3];
74
- }
75
- return apply(func, thisArg, args);
76
- };
77
- }
78
- /**
79
- * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
80
- *
81
- * @param func - The constructor function to be wrapped and called.
82
- * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
83
- */
84
- function unconstruct(Func) {
85
- return function () {
86
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
87
- args[_key4] = arguments[_key4];
88
- }
89
- return construct(Func, args);
90
- };
91
- }
92
- /**
93
- * Add properties to a lookup table
94
- *
95
- * @param set - The set to which elements will be added.
96
- * @param array - The array containing elements to be added to the set.
97
- * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
98
- * @returns The modified set with added elements.
99
- */
100
- function addToSet(set, array) {
101
- let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
102
- if (setPrototypeOf) {
103
- // Make 'in' and truthy checks like Boolean(set.constructor)
104
- // independent of any properties defined on Object.prototype.
105
- // Prevent prototype setters from intercepting set as a this value.
106
- setPrototypeOf(set, null);
107
- }
108
- let l = array.length;
109
- while (l--) {
110
- let element = array[l];
111
- if (typeof element === 'string') {
112
- const lcElement = transformCaseFunc(element);
113
- if (lcElement !== element) {
114
- // Config presets (e.g. tags.js, attrs.js) are immutable.
115
- if (!isFrozen(array)) {
116
- array[l] = lcElement;
117
- }
118
- element = lcElement;
119
- }
120
- }
121
- set[element] = true;
122
- }
123
- return set;
124
- }
125
- /**
126
- * Clean up an array to harden against CSPP
127
- *
128
- * @param array - The array to be cleaned.
129
- * @returns The cleaned version of the array
130
- */
131
- function cleanArray(array) {
132
- for (let index = 0; index < array.length; index++) {
133
- const isPropertyExist = objectHasOwnProperty(array, index);
134
- if (!isPropertyExist) {
135
- array[index] = null;
136
- }
137
- }
138
- return array;
139
- }
140
- /**
141
- * Shallow clone an object
142
- *
143
- * @param object - The object to be cloned.
144
- * @returns A new object that copies the original.
145
- */
146
- function clone(object) {
147
- const newObject = create(null);
148
- for (const [property, value] of entries(object)) {
149
- const isPropertyExist = objectHasOwnProperty(object, property);
150
- if (isPropertyExist) {
151
- if (Array.isArray(value)) {
152
- newObject[property] = cleanArray(value);
153
- } else if (value && typeof value === 'object' && value.constructor === Object) {
154
- newObject[property] = clone(value);
155
- } else {
156
- newObject[property] = value;
157
- }
158
- }
159
- }
160
- return newObject;
161
- }
162
- /**
163
- * This method automatically checks if the prop is function or getter and behaves accordingly.
164
- *
165
- * @param object - The object to look up the getter function in its prototype chain.
166
- * @param prop - The property name for which to find the getter function.
167
- * @returns The getter function found in the prototype chain or a fallback function.
168
- */
169
- function lookupGetter(object, prop) {
170
- while (object !== null) {
171
- const desc = getOwnPropertyDescriptor(object, prop);
172
- if (desc) {
173
- if (desc.get) {
174
- return unapply(desc.get);
175
- }
176
- if (typeof desc.value === 'function') {
177
- return unapply(desc.value);
178
- }
179
- }
180
- object = getPrototypeOf(object);
181
- }
182
- function fallbackValue() {
183
- return null;
184
- }
185
- return fallbackValue;
186
- }
187
-
188
- const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
189
- const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
190
- const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
191
- // List of SVG elements that are disallowed by default.
192
- // We still need to know them so that we can do namespace
193
- // checks properly in case one wants to add them to
194
- // allow-list.
195
- const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
196
- const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
197
- // Similarly to SVG, we want to know all MathML elements,
198
- // even those that we disallow by default.
199
- const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
200
- const text = freeze(['#text']);
201
-
202
- const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
203
- const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
204
- const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
205
- const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
206
-
207
- // eslint-disable-next-line unicorn/better-regex
208
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
209
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
210
- const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
211
- const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
212
- const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
213
- const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
214
- );
215
- const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
216
- const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
217
- );
218
- const DOCTYPE_NAME = seal(/^html$/i);
219
- const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
220
-
221
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
222
- __proto__: null,
223
- ARIA_ATTR: ARIA_ATTR,
224
- ATTR_WHITESPACE: ATTR_WHITESPACE,
225
- CUSTOM_ELEMENT: CUSTOM_ELEMENT,
226
- DATA_ATTR: DATA_ATTR,
227
- DOCTYPE_NAME: DOCTYPE_NAME,
228
- ERB_EXPR: ERB_EXPR,
229
- IS_ALLOWED_URI: IS_ALLOWED_URI,
230
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
231
- MUSTACHE_EXPR: MUSTACHE_EXPR,
232
- TMPLIT_EXPR: TMPLIT_EXPR
233
- });
234
-
235
- /* eslint-disable @typescript-eslint/indent */
236
- // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
237
- const NODE_TYPE = {
238
- element: 1,
239
- attribute: 2,
240
- text: 3,
241
- cdataSection: 4,
242
- entityReference: 5,
243
- // Deprecated
244
- entityNode: 6,
245
- // Deprecated
246
- progressingInstruction: 7,
247
- comment: 8,
248
- document: 9,
249
- documentType: 10,
250
- documentFragment: 11,
251
- notation: 12 // Deprecated
252
- };
253
- const getGlobal = function getGlobal() {
254
- return typeof window === 'undefined' ? null : window;
255
- };
256
- /**
257
- * Creates a no-op policy for internal use only.
258
- * Don't export this function outside this module!
259
- * @param trustedTypes The policy factory.
260
- * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
261
- * @return The policy created (or null, if Trusted Types
262
- * are not supported or creating the policy failed).
263
- */
264
- const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
265
- if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
266
- return null;
267
- }
268
- // Allow the callers to control the unique policy name
269
- // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
270
- // Policy creation with duplicate names throws in Trusted Types.
271
- let suffix = null;
272
- const ATTR_NAME = 'data-tt-policy-suffix';
273
- if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
274
- suffix = purifyHostElement.getAttribute(ATTR_NAME);
275
- }
276
- const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
277
- try {
278
- return trustedTypes.createPolicy(policyName, {
279
- createHTML(html) {
280
- return html;
281
- },
282
- createScriptURL(scriptUrl) {
283
- return scriptUrl;
284
- }
285
- });
286
- } catch (_) {
287
- // Policy creation failed (most likely another DOMPurify script has
288
- // already run). Skip creating the policy, as this will only cause errors
289
- // if TT are enforced.
290
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
291
- return null;
292
- }
293
- };
294
- const _createHooksMap = function _createHooksMap() {
295
- return {
296
- afterSanitizeAttributes: [],
297
- afterSanitizeElements: [],
298
- afterSanitizeShadowDOM: [],
299
- beforeSanitizeAttributes: [],
300
- beforeSanitizeElements: [],
301
- beforeSanitizeShadowDOM: [],
302
- uponSanitizeAttribute: [],
303
- uponSanitizeElement: [],
304
- uponSanitizeShadowNode: []
305
- };
306
- };
307
- function createDOMPurify() {
308
- let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
309
- const DOMPurify = root => createDOMPurify(root);
310
- DOMPurify.version = '3.3.1';
311
- DOMPurify.removed = [];
312
- if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
313
- // Not running in a browser, provide a factory function
314
- // so that you can pass your own Window
315
- DOMPurify.isSupported = false;
316
- return DOMPurify;
317
- }
318
- let {
319
- document
320
- } = window;
321
- const originalDocument = document;
322
- const currentScript = originalDocument.currentScript;
323
- const {
324
- DocumentFragment,
325
- HTMLTemplateElement,
326
- Node,
327
- Element,
328
- NodeFilter,
329
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
330
- HTMLFormElement,
331
- DOMParser,
332
- trustedTypes
333
- } = window;
334
- const ElementPrototype = Element.prototype;
335
- const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
336
- const remove = lookupGetter(ElementPrototype, 'remove');
337
- const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
338
- const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
339
- const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
340
- // As per issue #47, the web-components registry is inherited by a
341
- // new document created via createHTMLDocument. As per the spec
342
- // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
343
- // a new empty registry is used when creating a template contents owner
344
- // document, so we use that as our parent document to ensure nothing
345
- // is inherited.
346
- if (typeof HTMLTemplateElement === 'function') {
347
- const template = document.createElement('template');
348
- if (template.content && template.content.ownerDocument) {
349
- document = template.content.ownerDocument;
350
- }
351
- }
352
- let trustedTypesPolicy;
353
- let emptyHTML = '';
354
- const {
355
- implementation,
356
- createNodeIterator,
357
- createDocumentFragment,
358
- getElementsByTagName
359
- } = document;
360
- const {
361
- importNode
362
- } = originalDocument;
363
- let hooks = _createHooksMap();
364
- /**
365
- * Expose whether this browser supports running the full DOMPurify.
366
- */
367
- DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
368
- const {
369
- MUSTACHE_EXPR,
370
- ERB_EXPR,
371
- TMPLIT_EXPR,
372
- DATA_ATTR,
373
- ARIA_ATTR,
374
- IS_SCRIPT_OR_DATA,
375
- ATTR_WHITESPACE,
376
- CUSTOM_ELEMENT
377
- } = EXPRESSIONS;
378
- let {
379
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
380
- } = EXPRESSIONS;
381
- /**
382
- * We consider the elements and attributes below to be safe. Ideally
383
- * don't add any new ones but feel free to remove unwanted ones.
384
- */
385
- /* allowed element names */
386
- let ALLOWED_TAGS = null;
387
- const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
388
- /* Allowed attribute names */
389
- let ALLOWED_ATTR = null;
390
- const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
391
- /*
392
- * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
393
- * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
394
- * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
395
- * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
396
- */
397
- let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
398
- tagNameCheck: {
399
- writable: true,
400
- configurable: false,
401
- enumerable: true,
402
- value: null
403
- },
404
- attributeNameCheck: {
405
- writable: true,
406
- configurable: false,
407
- enumerable: true,
408
- value: null
409
- },
410
- allowCustomizedBuiltInElements: {
411
- writable: true,
412
- configurable: false,
413
- enumerable: true,
414
- value: false
415
- }
416
- }));
417
- /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
418
- let FORBID_TAGS = null;
419
- /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
420
- let FORBID_ATTR = null;
421
- /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
422
- const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
423
- tagCheck: {
424
- writable: true,
425
- configurable: false,
426
- enumerable: true,
427
- value: null
428
- },
429
- attributeCheck: {
430
- writable: true,
431
- configurable: false,
432
- enumerable: true,
433
- value: null
434
- }
435
- }));
436
- /* Decide if ARIA attributes are okay */
437
- let ALLOW_ARIA_ATTR = true;
438
- /* Decide if custom data attributes are okay */
439
- let ALLOW_DATA_ATTR = true;
440
- /* Decide if unknown protocols are okay */
441
- let ALLOW_UNKNOWN_PROTOCOLS = false;
442
- /* Decide if self-closing tags in attributes are allowed.
443
- * Usually removed due to a mXSS issue in jQuery 3.0 */
444
- let ALLOW_SELF_CLOSE_IN_ATTR = true;
445
- /* Output should be safe for common template engines.
446
- * This means, DOMPurify removes data attributes, mustaches and ERB
447
- */
448
- let SAFE_FOR_TEMPLATES = false;
449
- /* Output should be safe even for XML used within HTML and alike.
450
- * This means, DOMPurify removes comments when containing risky content.
451
- */
452
- let SAFE_FOR_XML = true;
453
- /* Decide if document with <html>... should be returned */
454
- let WHOLE_DOCUMENT = false;
455
- /* Track whether config is already set on this instance of DOMPurify. */
456
- let SET_CONFIG = false;
457
- /* Decide if all elements (e.g. style, script) must be children of
458
- * document.body. By default, browsers might move them to document.head */
459
- let FORCE_BODY = false;
460
- /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
461
- * string (or a TrustedHTML object if Trusted Types are supported).
462
- * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
463
- */
464
- let RETURN_DOM = false;
465
- /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
466
- * string (or a TrustedHTML object if Trusted Types are supported) */
467
- let RETURN_DOM_FRAGMENT = false;
468
- /* Try to return a Trusted Type object instead of a string, return a string in
469
- * case Trusted Types are not supported */
470
- let RETURN_TRUSTED_TYPE = false;
471
- /* Output should be free from DOM clobbering attacks?
472
- * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
473
- */
474
- let SANITIZE_DOM = true;
475
- /* Achieve full DOM Clobbering protection by isolating the namespace of named
476
- * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
477
- *
478
- * HTML/DOM spec rules that enable DOM Clobbering:
479
- * - Named Access on Window (§7.3.3)
480
- * - DOM Tree Accessors (§3.1.5)
481
- * - Form Element Parent-Child Relations (§4.10.3)
482
- * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
483
- * - HTMLCollection (§4.2.10.2)
484
- *
485
- * Namespace isolation is implemented by prefixing `id` and `name` attributes
486
- * with a constant string, i.e., `user-content-`
487
- */
488
- let SANITIZE_NAMED_PROPS = false;
489
- const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
490
- /* Keep element content when removing element? */
491
- let KEEP_CONTENT = true;
492
- /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
493
- * of importing it into a new Document and returning a sanitized copy */
494
- let IN_PLACE = false;
495
- /* Allow usage of profiles like html, svg and mathMl */
496
- let USE_PROFILES = {};
497
- /* Tags to ignore content of when KEEP_CONTENT is true */
498
- let FORBID_CONTENTS = null;
499
- const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
500
- /* Tags that are safe for data: URIs */
501
- let DATA_URI_TAGS = null;
502
- const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
503
- /* Attributes safe for values like "javascript:" */
504
- let URI_SAFE_ATTRIBUTES = null;
505
- const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
506
- const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
507
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
508
- const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
509
- /* Document namespace */
510
- let NAMESPACE = HTML_NAMESPACE;
511
- let IS_EMPTY_INPUT = false;
512
- /* Allowed XHTML+XML namespaces */
513
- let ALLOWED_NAMESPACES = null;
514
- const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
515
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
516
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
517
- // Certain elements are allowed in both SVG and HTML
518
- // namespace. We need to specify them explicitly
519
- // so that they don't get erroneously deleted from
520
- // HTML namespace.
521
- const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
522
- /* Parsing of strict XHTML documents */
523
- let PARSER_MEDIA_TYPE = null;
524
- const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
525
- const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
526
- let transformCaseFunc = null;
527
- /* Keep a reference to config to pass to hooks */
528
- let CONFIG = null;
529
- /* Ideally, do not touch anything below this line */
530
- /* ______________________________________________ */
531
- const formElement = document.createElement('form');
532
- const isRegexOrFunction = function isRegexOrFunction(testValue) {
533
- return testValue instanceof RegExp || testValue instanceof Function;
534
- };
535
- /**
536
- * _parseConfig
537
- *
538
- * @param cfg optional config literal
539
- */
540
- // eslint-disable-next-line complexity
541
- const _parseConfig = function _parseConfig() {
542
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
543
- if (CONFIG && CONFIG === cfg) {
544
- return;
545
- }
546
- /* Shield configuration object from tampering */
547
- if (!cfg || typeof cfg !== 'object') {
548
- cfg = {};
549
- }
550
- /* Shield configuration object from prototype pollution */
551
- cfg = clone(cfg);
552
- PARSER_MEDIA_TYPE =
553
- // eslint-disable-next-line unicorn/prefer-includes
554
- SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
555
- // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
556
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
557
- /* Set configuration parameters */
558
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
559
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
560
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
561
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
562
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
563
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
564
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
565
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
566
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
567
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
568
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
569
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
570
- ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
571
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
572
- SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
573
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
574
- RETURN_DOM = cfg.RETURN_DOM || false; // Default false
575
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
576
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
577
- FORCE_BODY = cfg.FORCE_BODY || false; // Default false
578
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
579
- SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
580
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
581
- IN_PLACE = cfg.IN_PLACE || false; // Default false
582
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
583
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
584
- MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
585
- HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
586
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
587
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
588
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
589
- }
590
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
591
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
592
- }
593
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
594
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
595
- }
596
- if (SAFE_FOR_TEMPLATES) {
597
- ALLOW_DATA_ATTR = false;
598
- }
599
- if (RETURN_DOM_FRAGMENT) {
600
- RETURN_DOM = true;
601
- }
602
- /* Parse profile info */
603
- if (USE_PROFILES) {
604
- ALLOWED_TAGS = addToSet({}, text);
605
- ALLOWED_ATTR = [];
606
- if (USE_PROFILES.html === true) {
607
- addToSet(ALLOWED_TAGS, html$1);
608
- addToSet(ALLOWED_ATTR, html);
609
- }
610
- if (USE_PROFILES.svg === true) {
611
- addToSet(ALLOWED_TAGS, svg$1);
612
- addToSet(ALLOWED_ATTR, svg);
613
- addToSet(ALLOWED_ATTR, xml);
614
- }
615
- if (USE_PROFILES.svgFilters === true) {
616
- addToSet(ALLOWED_TAGS, svgFilters);
617
- addToSet(ALLOWED_ATTR, svg);
618
- addToSet(ALLOWED_ATTR, xml);
619
- }
620
- if (USE_PROFILES.mathMl === true) {
621
- addToSet(ALLOWED_TAGS, mathMl$1);
622
- addToSet(ALLOWED_ATTR, mathMl);
623
- addToSet(ALLOWED_ATTR, xml);
624
- }
625
- }
626
- /* Merge configuration parameters */
627
- if (cfg.ADD_TAGS) {
628
- if (typeof cfg.ADD_TAGS === 'function') {
629
- EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
630
- } else {
631
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
632
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
633
- }
634
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
635
- }
636
- }
637
- if (cfg.ADD_ATTR) {
638
- if (typeof cfg.ADD_ATTR === 'function') {
639
- EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
640
- } else {
641
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
642
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
643
- }
644
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
645
- }
646
- }
647
- if (cfg.ADD_URI_SAFE_ATTR) {
648
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
649
- }
650
- if (cfg.FORBID_CONTENTS) {
651
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
652
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
653
- }
654
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
655
- }
656
- if (cfg.ADD_FORBID_CONTENTS) {
657
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
658
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
659
- }
660
- addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
661
- }
662
- /* Add #text in case KEEP_CONTENT is set to true */
663
- if (KEEP_CONTENT) {
664
- ALLOWED_TAGS['#text'] = true;
665
- }
666
- /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
667
- if (WHOLE_DOCUMENT) {
668
- addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
669
- }
670
- /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
671
- if (ALLOWED_TAGS.table) {
672
- addToSet(ALLOWED_TAGS, ['tbody']);
673
- delete FORBID_TAGS.tbody;
674
- }
675
- if (cfg.TRUSTED_TYPES_POLICY) {
676
- if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
677
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
678
- }
679
- if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
680
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
681
- }
682
- // Overwrite existing TrustedTypes policy.
683
- trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
684
- // Sign local variables required by `sanitize`.
685
- emptyHTML = trustedTypesPolicy.createHTML('');
686
- } else {
687
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
688
- if (trustedTypesPolicy === undefined) {
689
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
690
- }
691
- // If creating the internal policy succeeded sign internal variables.
692
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
693
- emptyHTML = trustedTypesPolicy.createHTML('');
694
- }
695
- }
696
- // Prevent further manipulation of configuration.
697
- // Not available in IE8, Safari 5, etc.
698
- if (freeze) {
699
- freeze(cfg);
700
- }
701
- CONFIG = cfg;
702
- };
703
- /* Keep track of all possible SVG and MathML tags
704
- * so that we can perform the namespace checks
705
- * correctly. */
706
- const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
707
- const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
708
- /**
709
- * @param element a DOM element whose namespace is being checked
710
- * @returns Return false if the element has a
711
- * namespace that a spec-compliant parser would never
712
- * return. Return true otherwise.
713
- */
714
- const _checkValidNamespace = function _checkValidNamespace(element) {
715
- let parent = getParentNode(element);
716
- // In JSDOM, if we're inside shadow DOM, then parentNode
717
- // can be null. We just simulate parent in this case.
718
- if (!parent || !parent.tagName) {
719
- parent = {
720
- namespaceURI: NAMESPACE,
721
- tagName: 'template'
722
- };
723
- }
724
- const tagName = stringToLowerCase(element.tagName);
725
- const parentTagName = stringToLowerCase(parent.tagName);
726
- if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
727
- return false;
728
- }
729
- if (element.namespaceURI === SVG_NAMESPACE) {
730
- // The only way to switch from HTML namespace to SVG
731
- // is via <svg>. If it happens via any other tag, then
732
- // it should be killed.
733
- if (parent.namespaceURI === HTML_NAMESPACE) {
734
- return tagName === 'svg';
735
- }
736
- // The only way to switch from MathML to SVG is via`
737
- // svg if parent is either <annotation-xml> or MathML
738
- // text integration points.
739
- if (parent.namespaceURI === MATHML_NAMESPACE) {
740
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
741
- }
742
- // We only allow elements that are defined in SVG
743
- // spec. All others are disallowed in SVG namespace.
744
- return Boolean(ALL_SVG_TAGS[tagName]);
745
- }
746
- if (element.namespaceURI === MATHML_NAMESPACE) {
747
- // The only way to switch from HTML namespace to MathML
748
- // is via <math>. If it happens via any other tag, then
749
- // it should be killed.
750
- if (parent.namespaceURI === HTML_NAMESPACE) {
751
- return tagName === 'math';
752
- }
753
- // The only way to switch from SVG to MathML is via
754
- // <math> and HTML integration points
755
- if (parent.namespaceURI === SVG_NAMESPACE) {
756
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
757
- }
758
- // We only allow elements that are defined in MathML
759
- // spec. All others are disallowed in MathML namespace.
760
- return Boolean(ALL_MATHML_TAGS[tagName]);
761
- }
762
- if (element.namespaceURI === HTML_NAMESPACE) {
763
- // The only way to switch from SVG to HTML is via
764
- // HTML integration points, and from MathML to HTML
765
- // is via MathML text integration points
766
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
767
- return false;
768
- }
769
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
770
- return false;
771
- }
772
- // We disallow tags that are specific for MathML
773
- // or SVG and should never appear in HTML namespace
774
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
775
- }
776
- // For XHTML and XML documents that support custom namespaces
777
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
778
- return true;
779
- }
780
- // The code should never reach this place (this means
781
- // that the element somehow got namespace that is not
782
- // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
783
- // Return false just in case.
784
- return false;
785
- };
786
- /**
787
- * _forceRemove
788
- *
789
- * @param node a DOM node
790
- */
791
- const _forceRemove = function _forceRemove(node) {
792
- arrayPush(DOMPurify.removed, {
793
- element: node
794
- });
795
- try {
796
- // eslint-disable-next-line unicorn/prefer-dom-node-remove
797
- getParentNode(node).removeChild(node);
798
- } catch (_) {
799
- remove(node);
800
- }
801
- };
802
- /**
803
- * _removeAttribute
804
- *
805
- * @param name an Attribute name
806
- * @param element a DOM node
807
- */
808
- const _removeAttribute = function _removeAttribute(name, element) {
809
- try {
810
- arrayPush(DOMPurify.removed, {
811
- attribute: element.getAttributeNode(name),
812
- from: element
813
- });
814
- } catch (_) {
815
- arrayPush(DOMPurify.removed, {
816
- attribute: null,
817
- from: element
818
- });
819
- }
820
- element.removeAttribute(name);
821
- // We void attribute values for unremovable "is" attributes
822
- if (name === 'is') {
823
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
824
- try {
825
- _forceRemove(element);
826
- } catch (_) {}
827
- } else {
828
- try {
829
- element.setAttribute(name, '');
830
- } catch (_) {}
831
- }
832
- }
833
- };
834
- /**
835
- * _initDocument
836
- *
837
- * @param dirty - a string of dirty markup
838
- * @return a DOM, filled with the dirty markup
839
- */
840
- const _initDocument = function _initDocument(dirty) {
841
- /* Create a HTML document */
842
- let doc = null;
843
- let leadingWhitespace = null;
844
- if (FORCE_BODY) {
845
- dirty = '<remove></remove>' + dirty;
846
- } else {
847
- /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
848
- const matches = stringMatch(dirty, /^[\r\n\t ]+/);
849
- leadingWhitespace = matches && matches[0];
850
- }
851
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
852
- // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
853
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
854
- }
855
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
856
- /*
857
- * Use the DOMParser API by default, fallback later if needs be
858
- * DOMParser not work for svg when has multiple root element.
859
- */
860
- if (NAMESPACE === HTML_NAMESPACE) {
861
- try {
862
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
863
- } catch (_) {}
864
- }
865
- /* Use createHTMLDocument in case DOMParser is not available */
866
- if (!doc || !doc.documentElement) {
867
- doc = implementation.createDocument(NAMESPACE, 'template', null);
868
- try {
869
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
870
- } catch (_) {
871
- // Syntax error if dirtyPayload is invalid xml
872
- }
873
- }
874
- const body = doc.body || doc.documentElement;
875
- if (dirty && leadingWhitespace) {
876
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
877
- }
878
- /* Work on whole document or just its body */
879
- if (NAMESPACE === HTML_NAMESPACE) {
880
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
881
- }
882
- return WHOLE_DOCUMENT ? doc.documentElement : body;
883
- };
884
- /**
885
- * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
886
- *
887
- * @param root The root element or node to start traversing on.
888
- * @return The created NodeIterator
889
- */
890
- const _createNodeIterator = function _createNodeIterator(root) {
891
- return createNodeIterator.call(root.ownerDocument || root, root,
892
- // eslint-disable-next-line no-bitwise
893
- NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
894
- };
895
- /**
896
- * _isClobbered
897
- *
898
- * @param element element to check for clobbering attacks
899
- * @return true if clobbered, false if safe
900
- */
901
- const _isClobbered = function _isClobbered(element) {
902
- return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
903
- };
904
- /**
905
- * Checks whether the given object is a DOM node.
906
- *
907
- * @param value object to check whether it's a DOM node
908
- * @return true is object is a DOM node
909
- */
910
- const _isNode = function _isNode(value) {
911
- return typeof Node === 'function' && value instanceof Node;
912
- };
913
- function _executeHooks(hooks, currentNode, data) {
914
- arrayForEach(hooks, hook => {
915
- hook.call(DOMPurify, currentNode, data, CONFIG);
916
- });
917
- }
918
- /**
919
- * _sanitizeElements
920
- *
921
- * @protect nodeName
922
- * @protect textContent
923
- * @protect removeChild
924
- * @param currentNode to check for permission to exist
925
- * @return true if node was killed, false if left alive
926
- */
927
- const _sanitizeElements = function _sanitizeElements(currentNode) {
928
- let content = null;
929
- /* Execute a hook if present */
930
- _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
931
- /* Check if element is clobbered or can clobber */
932
- if (_isClobbered(currentNode)) {
933
- _forceRemove(currentNode);
934
- return true;
935
- }
936
- /* Now let's check the element's type and name */
937
- const tagName = transformCaseFunc(currentNode.nodeName);
938
- /* Execute a hook if present */
939
- _executeHooks(hooks.uponSanitizeElement, currentNode, {
940
- tagName,
941
- allowedTags: ALLOWED_TAGS
942
- });
943
- /* Detect mXSS attempts abusing namespace confusion */
944
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
945
- _forceRemove(currentNode);
946
- return true;
947
- }
948
- /* Remove any occurrence of processing instructions */
949
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
950
- _forceRemove(currentNode);
951
- return true;
952
- }
953
- /* Remove any kind of possibly harmful comments */
954
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
955
- _forceRemove(currentNode);
956
- return true;
957
- }
958
- /* Remove element if anything forbids its presence */
959
- if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
960
- /* Check if we have a custom element to handle */
961
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
962
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
963
- return false;
964
- }
965
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
966
- return false;
967
- }
968
- }
969
- /* Keep content except for bad-listed elements */
970
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
971
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
972
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
973
- if (childNodes && parentNode) {
974
- const childCount = childNodes.length;
975
- for (let i = childCount - 1; i >= 0; --i) {
976
- const childClone = cloneNode(childNodes[i], true);
977
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
978
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
979
- }
980
- }
981
- }
982
- _forceRemove(currentNode);
983
- return true;
984
- }
985
- /* Check whether element has a valid namespace */
986
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
987
- _forceRemove(currentNode);
988
- return true;
989
- }
990
- /* Make sure that older browsers don't get fallback-tag mXSS */
991
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
992
- _forceRemove(currentNode);
993
- return true;
994
- }
995
- /* Sanitize element content to be template-safe */
996
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
997
- /* Get the element's text content */
998
- content = currentNode.textContent;
999
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1000
- content = stringReplace(content, expr, ' ');
1001
- });
1002
- if (currentNode.textContent !== content) {
1003
- arrayPush(DOMPurify.removed, {
1004
- element: currentNode.cloneNode()
1005
- });
1006
- currentNode.textContent = content;
1007
- }
1008
- }
1009
- /* Execute a hook if present */
1010
- _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1011
- return false;
1012
- };
1013
- /**
1014
- * _isValidAttribute
1015
- *
1016
- * @param lcTag Lowercase tag name of containing element.
1017
- * @param lcName Lowercase attribute name.
1018
- * @param value Attribute value.
1019
- * @return Returns true if `value` is valid, otherwise false.
1020
- */
1021
- // eslint-disable-next-line complexity
1022
- const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1023
- /* Make sure attribute cannot clobber */
1024
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1025
- return false;
1026
- }
1027
- /* Allow valid data-* attributes: At least one character after "-"
1028
- (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1029
- XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1030
- We don't need to check the value; it's always URI safe. */
1031
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1032
- if (
1033
- // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1034
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1035
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1036
- _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||
1037
- // Alternative, second condition checks if it's an `is`-attribute, AND
1038
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1039
- lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1040
- return false;
1041
- }
1042
- /* Check value is safe. First, is attr inert? If so, is safe */
1043
- } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1044
- return false;
1045
- } else ;
1046
- return true;
1047
- };
1048
- /**
1049
- * _isBasicCustomElement
1050
- * checks if at least one dash is included in tagName, and it's not the first char
1051
- * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1052
- *
1053
- * @param tagName name of the tag of the node to sanitize
1054
- * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1055
- */
1056
- const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1057
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1058
- };
1059
- /**
1060
- * _sanitizeAttributes
1061
- *
1062
- * @protect attributes
1063
- * @protect nodeName
1064
- * @protect removeAttribute
1065
- * @protect setAttribute
1066
- *
1067
- * @param currentNode to sanitize
1068
- */
1069
- const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1070
- /* Execute a hook if present */
1071
- _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1072
- const {
1073
- attributes
1074
- } = currentNode;
1075
- /* Check if we have attributes; if not we might have a text node */
1076
- if (!attributes || _isClobbered(currentNode)) {
1077
- return;
1078
- }
1079
- const hookEvent = {
1080
- attrName: '',
1081
- attrValue: '',
1082
- keepAttr: true,
1083
- allowedAttributes: ALLOWED_ATTR,
1084
- forceKeepAttr: undefined
1085
- };
1086
- let l = attributes.length;
1087
- /* Go backwards over all attributes; safely remove bad ones */
1088
- while (l--) {
1089
- const attr = attributes[l];
1090
- const {
1091
- name,
1092
- namespaceURI,
1093
- value: attrValue
1094
- } = attr;
1095
- const lcName = transformCaseFunc(name);
1096
- const initValue = attrValue;
1097
- let value = name === 'value' ? initValue : stringTrim(initValue);
1098
- /* Execute a hook if present */
1099
- hookEvent.attrName = lcName;
1100
- hookEvent.attrValue = value;
1101
- hookEvent.keepAttr = true;
1102
- hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1103
- _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1104
- value = hookEvent.attrValue;
1105
- /* Full DOM Clobbering protection via namespace isolation,
1106
- * Prefix id and name attributes with `user-content-`
1107
- */
1108
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1109
- // Remove the attribute with this value
1110
- _removeAttribute(name, currentNode);
1111
- // Prefix the value and later re-create the attribute with the sanitized value
1112
- value = SANITIZE_NAMED_PROPS_PREFIX + value;
1113
- }
1114
- /* Work around a security issue with comments inside attributes */
1115
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
1116
- _removeAttribute(name, currentNode);
1117
- continue;
1118
- }
1119
- /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
1120
- if (lcName === 'attributename' && stringMatch(value, 'href')) {
1121
- _removeAttribute(name, currentNode);
1122
- continue;
1123
- }
1124
- /* Did the hooks approve of the attribute? */
1125
- if (hookEvent.forceKeepAttr) {
1126
- continue;
1127
- }
1128
- /* Did the hooks approve of the attribute? */
1129
- if (!hookEvent.keepAttr) {
1130
- _removeAttribute(name, currentNode);
1131
- continue;
1132
- }
1133
- /* Work around a security issue in jQuery 3.0 */
1134
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1135
- _removeAttribute(name, currentNode);
1136
- continue;
1137
- }
1138
- /* Sanitize attribute content to be template-safe */
1139
- if (SAFE_FOR_TEMPLATES) {
1140
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1141
- value = stringReplace(value, expr, ' ');
1142
- });
1143
- }
1144
- /* Is `value` valid for this attribute? */
1145
- const lcTag = transformCaseFunc(currentNode.nodeName);
1146
- if (!_isValidAttribute(lcTag, lcName, value)) {
1147
- _removeAttribute(name, currentNode);
1148
- continue;
1149
- }
1150
- /* Handle attributes that require Trusted Types */
1151
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1152
- if (namespaceURI) ; else {
1153
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1154
- case 'TrustedHTML':
1155
- {
1156
- value = trustedTypesPolicy.createHTML(value);
1157
- break;
1158
- }
1159
- case 'TrustedScriptURL':
1160
- {
1161
- value = trustedTypesPolicy.createScriptURL(value);
1162
- break;
1163
- }
1164
- }
1165
- }
1166
- }
1167
- /* Handle invalid data-* attribute set by try-catching it */
1168
- if (value !== initValue) {
1169
- try {
1170
- if (namespaceURI) {
1171
- currentNode.setAttributeNS(namespaceURI, name, value);
1172
- } else {
1173
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1174
- currentNode.setAttribute(name, value);
1175
- }
1176
- if (_isClobbered(currentNode)) {
1177
- _forceRemove(currentNode);
1178
- } else {
1179
- arrayPop(DOMPurify.removed);
1180
- }
1181
- } catch (_) {
1182
- _removeAttribute(name, currentNode);
1183
- }
1184
- }
1185
- }
1186
- /* Execute a hook if present */
1187
- _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1188
- };
1189
- /**
1190
- * _sanitizeShadowDOM
1191
- *
1192
- * @param fragment to iterate over recursively
1193
- */
1194
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1195
- let shadowNode = null;
1196
- const shadowIterator = _createNodeIterator(fragment);
1197
- /* Execute a hook if present */
1198
- _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1199
- while (shadowNode = shadowIterator.nextNode()) {
1200
- /* Execute a hook if present */
1201
- _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1202
- /* Sanitize tags and elements */
1203
- _sanitizeElements(shadowNode);
1204
- /* Check attributes next */
1205
- _sanitizeAttributes(shadowNode);
1206
- /* Deep shadow DOM detected */
1207
- if (shadowNode.content instanceof DocumentFragment) {
1208
- _sanitizeShadowDOM(shadowNode.content);
1209
- }
1210
- }
1211
- /* Execute a hook if present */
1212
- _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1213
- };
1214
- // eslint-disable-next-line complexity
1215
- DOMPurify.sanitize = function (dirty) {
1216
- let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1217
- let body = null;
1218
- let importedNode = null;
1219
- let currentNode = null;
1220
- let returnNode = null;
1221
- /* Make sure we have a string to sanitize.
1222
- DO NOT return early, as this will return the wrong type if
1223
- the user has requested a DOM object rather than a string */
1224
- IS_EMPTY_INPUT = !dirty;
1225
- if (IS_EMPTY_INPUT) {
1226
- dirty = '<!-->';
1227
- }
1228
- /* Stringify, in case dirty is an object */
1229
- if (typeof dirty !== 'string' && !_isNode(dirty)) {
1230
- if (typeof dirty.toString === 'function') {
1231
- dirty = dirty.toString();
1232
- if (typeof dirty !== 'string') {
1233
- throw typeErrorCreate('dirty is not a string, aborting');
1234
- }
1235
- } else {
1236
- throw typeErrorCreate('toString is not a function');
1237
- }
1238
- }
1239
- /* Return dirty HTML if DOMPurify cannot run */
1240
- if (!DOMPurify.isSupported) {
1241
- return dirty;
1242
- }
1243
- /* Assign config vars */
1244
- if (!SET_CONFIG) {
1245
- _parseConfig(cfg);
1246
- }
1247
- /* Clean up removed elements */
1248
- DOMPurify.removed = [];
1249
- /* Check if dirty is correctly typed for IN_PLACE */
1250
- if (typeof dirty === 'string') {
1251
- IN_PLACE = false;
1252
- }
1253
- if (IN_PLACE) {
1254
- /* Do some early pre-sanitization to avoid unsafe root nodes */
1255
- if (dirty.nodeName) {
1256
- const tagName = transformCaseFunc(dirty.nodeName);
1257
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1258
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1259
- }
1260
- }
1261
- } else if (dirty instanceof Node) {
1262
- /* If dirty is a DOM element, append to an empty document to avoid
1263
- elements being stripped by the parser */
1264
- body = _initDocument('<!---->');
1265
- importedNode = body.ownerDocument.importNode(dirty, true);
1266
- if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
1267
- /* Node is already a body, use as is */
1268
- body = importedNode;
1269
- } else if (importedNode.nodeName === 'HTML') {
1270
- body = importedNode;
1271
- } else {
1272
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1273
- body.appendChild(importedNode);
1274
- }
1275
- } else {
1276
- /* Exit directly if we have nothing to do */
1277
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1278
- // eslint-disable-next-line unicorn/prefer-includes
1279
- dirty.indexOf('<') === -1) {
1280
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1281
- }
1282
- /* Initialize the document to work on */
1283
- body = _initDocument(dirty);
1284
- /* Check we have a DOM node from the data */
1285
- if (!body) {
1286
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1287
- }
1288
- }
1289
- /* Remove first element node (ours) if FORCE_BODY is set */
1290
- if (body && FORCE_BODY) {
1291
- _forceRemove(body.firstChild);
1292
- }
1293
- /* Get node iterator */
1294
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1295
- /* Now start iterating over the created document */
1296
- while (currentNode = nodeIterator.nextNode()) {
1297
- /* Sanitize tags and elements */
1298
- _sanitizeElements(currentNode);
1299
- /* Check attributes next */
1300
- _sanitizeAttributes(currentNode);
1301
- /* Shadow DOM detected, sanitize it */
1302
- if (currentNode.content instanceof DocumentFragment) {
1303
- _sanitizeShadowDOM(currentNode.content);
1304
- }
1305
- }
1306
- /* If we sanitized `dirty` in-place, return it. */
1307
- if (IN_PLACE) {
1308
- return dirty;
1309
- }
1310
- /* Return sanitized string or DOM */
1311
- if (RETURN_DOM) {
1312
- if (RETURN_DOM_FRAGMENT) {
1313
- returnNode = createDocumentFragment.call(body.ownerDocument);
1314
- while (body.firstChild) {
1315
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1316
- returnNode.appendChild(body.firstChild);
1317
- }
1318
- } else {
1319
- returnNode = body;
1320
- }
1321
- if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1322
- /*
1323
- AdoptNode() is not used because internal state is not reset
1324
- (e.g. the past names map of a HTMLFormElement), this is safe
1325
- in theory but we would rather not risk another attack vector.
1326
- The state that is cloned by importNode() is explicitly defined
1327
- by the specs.
1328
- */
1329
- returnNode = importNode.call(originalDocument, returnNode, true);
1330
- }
1331
- return returnNode;
1332
- }
1333
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1334
- /* Serialize doctype if allowed */
1335
- if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1336
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1337
- }
1338
- /* Sanitize final string template-safe */
1339
- if (SAFE_FOR_TEMPLATES) {
1340
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1341
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
1342
- });
1343
- }
1344
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1345
- };
1346
- DOMPurify.setConfig = function () {
1347
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1348
- _parseConfig(cfg);
1349
- SET_CONFIG = true;
1350
- };
1351
- DOMPurify.clearConfig = function () {
1352
- CONFIG = null;
1353
- SET_CONFIG = false;
1354
- };
1355
- DOMPurify.isValidAttribute = function (tag, attr, value) {
1356
- /* Initialize shared config vars if necessary. */
1357
- if (!CONFIG) {
1358
- _parseConfig({});
1359
- }
1360
- const lcTag = transformCaseFunc(tag);
1361
- const lcName = transformCaseFunc(attr);
1362
- return _isValidAttribute(lcTag, lcName, value);
1363
- };
1364
- DOMPurify.addHook = function (entryPoint, hookFunction) {
1365
- if (typeof hookFunction !== 'function') {
1366
- return;
1367
- }
1368
- arrayPush(hooks[entryPoint], hookFunction);
1369
- };
1370
- DOMPurify.removeHook = function (entryPoint, hookFunction) {
1371
- if (hookFunction !== undefined) {
1372
- const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1373
- return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
1374
- }
1375
- return arrayPop(hooks[entryPoint]);
1376
- };
1377
- DOMPurify.removeHooks = function (entryPoint) {
1378
- hooks[entryPoint] = [];
1379
- };
1380
- DOMPurify.removeAllHooks = function () {
1381
- hooks = _createHooksMap();
1382
- };
1383
- return DOMPurify;
1384
- }
1385
- var purify = createDOMPurify();
1386
-
1387
- module.exports = purify;
1388
- //# sourceMappingURL=purify.cjs.js.map
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/dompurify/dist/purify.cjs.js.map DELETED
The diff for this file is too large to render. See raw diff
 
ui/node_modules/dompurify/dist/purify.es.d.mts DELETED
@@ -1,447 +0,0 @@
1
- /*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
2
-
3
- import { TrustedTypePolicy, TrustedHTML, TrustedTypesWindow } from 'trusted-types/lib/index.js';
4
-
5
- /**
6
- * Configuration to control DOMPurify behavior.
7
- */
8
- interface Config {
9
- /**
10
- * Extend the existing array of allowed attributes.
11
- * Can be an array of attribute names, or a function that receives
12
- * the attribute name and tag name to determine if the attribute is allowed.
13
- */
14
- ADD_ATTR?: string[] | ((attributeName: string, tagName: string) => boolean) | undefined;
15
- /**
16
- * Extend the existing array of elements that can use Data URIs.
17
- */
18
- ADD_DATA_URI_TAGS?: string[] | undefined;
19
- /**
20
- * Extend the existing array of allowed tags.
21
- * Can be an array of tag names, or a function that receives
22
- * the tag name to determine if the tag is allowed.
23
- */
24
- ADD_TAGS?: string[] | ((tagName: string) => boolean) | undefined;
25
- /**
26
- * Extend the existing array of elements that are safe for URI-like values (be careful, XSS risk).
27
- */
28
- ADD_URI_SAFE_ATTR?: string[] | undefined;
29
- /**
30
- * Allow ARIA attributes, leave other safe HTML as is (default is true).
31
- */
32
- ALLOW_ARIA_ATTR?: boolean | undefined;
33
- /**
34
- * Allow HTML5 data attributes, leave other safe HTML as is (default is true).
35
- */
36
- ALLOW_DATA_ATTR?: boolean | undefined;
37
- /**
38
- * Allow external protocol handlers in URL attributes (default is false, be careful, XSS risk).
39
- * By default only `http`, `https`, `ftp`, `ftps`, `tel`, `mailto`, `callto`, `sms`, `cid` and `xmpp` are allowed.
40
- */
41
- ALLOW_UNKNOWN_PROTOCOLS?: boolean | undefined;
42
- /**
43
- * Decide if self-closing tags in attributes are allowed.
44
- * Usually removed due to a mXSS issue in jQuery 3.0.
45
- */
46
- ALLOW_SELF_CLOSE_IN_ATTR?: boolean | undefined;
47
- /**
48
- * Allow only specific attributes.
49
- */
50
- ALLOWED_ATTR?: string[] | undefined;
51
- /**
52
- * Allow only specific elements.
53
- */
54
- ALLOWED_TAGS?: string[] | undefined;
55
- /**
56
- * Allow only specific namespaces. Defaults to:
57
- * - `http://www.w3.org/1999/xhtml`
58
- * - `http://www.w3.org/2000/svg`
59
- * - `http://www.w3.org/1998/Math/MathML`
60
- */
61
- ALLOWED_NAMESPACES?: string[] | undefined;
62
- /**
63
- * Allow specific protocols handlers in URL attributes via regex (be careful, XSS risk).
64
- * Default RegExp:
65
- * ```
66
- * /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
67
- * ```
68
- */
69
- ALLOWED_URI_REGEXP?: RegExp | undefined;
70
- /**
71
- * Define how custom elements are handled.
72
- */
73
- CUSTOM_ELEMENT_HANDLING?: {
74
- /**
75
- * Regular expression or function to match to allowed elements.
76
- * Default is null (disallow any custom elements).
77
- */
78
- tagNameCheck?: RegExp | ((tagName: string) => boolean) | null | undefined;
79
- /**
80
- * Regular expression or function to match to allowed attributes.
81
- * Default is null (disallow any attributes not on the allow list).
82
- */
83
- attributeNameCheck?: RegExp | ((attributeName: string, tagName?: string) => boolean) | null | undefined;
84
- /**
85
- * Allow custom elements derived from built-ins if they pass `tagNameCheck`. Default is false.
86
- */
87
- allowCustomizedBuiltInElements?: boolean | undefined;
88
- };
89
- /**
90
- * Add attributes to block-list.
91
- */
92
- FORBID_ATTR?: string[] | undefined;
93
- /**
94
- * Add child elements to be removed when their parent is removed.
95
- */
96
- FORBID_CONTENTS?: string[] | undefined;
97
- /**
98
- * Extend the existing or default array of forbidden content elements.
99
- */
100
- ADD_FORBID_CONTENTS?: string[] | undefined;
101
- /**
102
- * Add elements to block-list.
103
- */
104
- FORBID_TAGS?: string[] | undefined;
105
- /**
106
- * Glue elements like style, script or others to `document.body` and prevent unintuitive browser behavior in several edge-cases (default is false).
107
- */
108
- FORCE_BODY?: boolean | undefined;
109
- /**
110
- * Map of non-standard HTML element names to support. Map to true to enable support. For example:
111
- *
112
- * ```
113
- * HTML_INTEGRATION_POINTS: { foreignobject: true }
114
- * ```
115
- */
116
- HTML_INTEGRATION_POINTS?: Record<string, boolean> | undefined;
117
- /**
118
- * Sanitize a node "in place", which is much faster depending on how you use DOMPurify.
119
- */
120
- IN_PLACE?: boolean | undefined;
121
- /**
122
- * Keep an element's content when the element is removed (default is true).
123
- */
124
- KEEP_CONTENT?: boolean | undefined;
125
- /**
126
- * Map of MathML element names to support. Map to true to enable support. For example:
127
- *
128
- * ```
129
- * MATHML_TEXT_INTEGRATION_POINTS: { mtext: true }
130
- * ```
131
- */
132
- MATHML_TEXT_INTEGRATION_POINTS?: Record<string, boolean> | undefined;
133
- /**
134
- * Change the default namespace from HTML to something different.
135
- */
136
- NAMESPACE?: string | undefined;
137
- /**
138
- * Change the parser type so sanitized data is treated as XML and not as HTML, which is the default.
139
- */
140
- PARSER_MEDIA_TYPE?: DOMParserSupportedType | undefined;
141
- /**
142
- * Return a DOM `DocumentFragment` instead of an HTML string (default is false).
143
- */
144
- RETURN_DOM_FRAGMENT?: boolean | undefined;
145
- /**
146
- * Return a DOM `HTMLBodyElement` instead of an HTML string (default is false).
147
- */
148
- RETURN_DOM?: boolean | undefined;
149
- /**
150
- * Return a TrustedHTML object instead of a string if possible.
151
- */
152
- RETURN_TRUSTED_TYPE?: boolean | undefined;
153
- /**
154
- * Strip `{{ ... }}`, `${ ... }` and `<% ... %>` to make output safe for template systems.
155
- * Be careful please, this mode is not recommended for production usage.
156
- * Allowing template parsing in user-controlled HTML is not advised at all.
157
- * Only use this mode if there is really no alternative.
158
- */
159
- SAFE_FOR_TEMPLATES?: boolean | undefined;
160
- /**
161
- * Change how e.g. comments containing risky HTML characters are treated.
162
- * Be very careful, this setting should only be set to `false` if you really only handle
163
- * HTML and nothing else, no SVG, MathML or the like.
164
- * Otherwise, changing from `true` to `false` will lead to XSS in this or some other way.
165
- */
166
- SAFE_FOR_XML?: boolean | undefined;
167
- /**
168
- * Use DOM Clobbering protection on output (default is true, handle with care, minor XSS risks here).
169
- */
170
- SANITIZE_DOM?: boolean | undefined;
171
- /**
172
- * Enforce strict DOM Clobbering protection via namespace isolation (default is false).
173
- * When enabled, isolates the namespace of named properties (i.e., `id` and `name` attributes)
174
- * from JS variables by prefixing them with the string `user-content-`
175
- */
176
- SANITIZE_NAMED_PROPS?: boolean | undefined;
177
- /**
178
- * Supplied policy must define `createHTML` and `createScriptURL`.
179
- */
180
- TRUSTED_TYPES_POLICY?: TrustedTypePolicy | undefined;
181
- /**
182
- * Controls categories of allowed elements.
183
- *
184
- * Note that the `USE_PROFILES` setting will override the `ALLOWED_TAGS` setting
185
- * so don't use them together.
186
- */
187
- USE_PROFILES?: false | UseProfilesConfig | undefined;
188
- /**
189
- * Return entire document including <html> tags (default is false).
190
- */
191
- WHOLE_DOCUMENT?: boolean | undefined;
192
- }
193
- /**
194
- * Defines categories of allowed elements.
195
- */
196
- interface UseProfilesConfig {
197
- /**
198
- * Allow all safe MathML elements.
199
- */
200
- mathMl?: boolean | undefined;
201
- /**
202
- * Allow all safe SVG elements.
203
- */
204
- svg?: boolean | undefined;
205
- /**
206
- * Allow all save SVG Filters.
207
- */
208
- svgFilters?: boolean | undefined;
209
- /**
210
- * Allow all safe HTML elements.
211
- */
212
- html?: boolean | undefined;
213
- }
214
-
215
- declare const _default: DOMPurify;
216
-
217
- interface DOMPurify {
218
- /**
219
- * Creates a DOMPurify instance using the given window-like object. Defaults to `window`.
220
- */
221
- (root?: WindowLike): DOMPurify;
222
- /**
223
- * Version label, exposed for easier checks
224
- * if DOMPurify is up to date or not
225
- */
226
- version: string;
227
- /**
228
- * Array of elements that DOMPurify removed during sanitation.
229
- * Empty if nothing was removed.
230
- */
231
- removed: Array<RemovedElement | RemovedAttribute>;
232
- /**
233
- * Expose whether this browser supports running the full DOMPurify.
234
- */
235
- isSupported: boolean;
236
- /**
237
- * Set the configuration once.
238
- *
239
- * @param cfg configuration object
240
- */
241
- setConfig(cfg?: Config): void;
242
- /**
243
- * Removes the configuration.
244
- */
245
- clearConfig(): void;
246
- /**
247
- * Provides core sanitation functionality.
248
- *
249
- * @param dirty string or DOM node
250
- * @param cfg object
251
- * @returns Sanitized TrustedHTML.
252
- */
253
- sanitize(dirty: string | Node, cfg: Config & {
254
- RETURN_TRUSTED_TYPE: true;
255
- }): TrustedHTML;
256
- /**
257
- * Provides core sanitation functionality.
258
- *
259
- * @param dirty DOM node
260
- * @param cfg object
261
- * @returns Sanitized DOM node.
262
- */
263
- sanitize(dirty: Node, cfg: Config & {
264
- IN_PLACE: true;
265
- }): Node;
266
- /**
267
- * Provides core sanitation functionality.
268
- *
269
- * @param dirty string or DOM node
270
- * @param cfg object
271
- * @returns Sanitized DOM node.
272
- */
273
- sanitize(dirty: string | Node, cfg: Config & {
274
- RETURN_DOM: true;
275
- }): Node;
276
- /**
277
- * Provides core sanitation functionality.
278
- *
279
- * @param dirty string or DOM node
280
- * @param cfg object
281
- * @returns Sanitized document fragment.
282
- */
283
- sanitize(dirty: string | Node, cfg: Config & {
284
- RETURN_DOM_FRAGMENT: true;
285
- }): DocumentFragment;
286
- /**
287
- * Provides core sanitation functionality.
288
- *
289
- * @param dirty string or DOM node
290
- * @param cfg object
291
- * @returns Sanitized string.
292
- */
293
- sanitize(dirty: string | Node, cfg?: Config): string;
294
- /**
295
- * Checks if an attribute value is valid.
296
- * Uses last set config, if any. Otherwise, uses config defaults.
297
- *
298
- * @param tag Tag name of containing element.
299
- * @param attr Attribute name.
300
- * @param value Attribute value.
301
- * @returns Returns true if `value` is valid. Otherwise, returns false.
302
- */
303
- isValidAttribute(tag: string, attr: string, value: string): boolean;
304
- /**
305
- * Adds a DOMPurify hook.
306
- *
307
- * @param entryPoint entry point for the hook to add
308
- * @param hookFunction function to execute
309
- */
310
- addHook(entryPoint: BasicHookName, hookFunction: NodeHook): void;
311
- /**
312
- * Adds a DOMPurify hook.
313
- *
314
- * @param entryPoint entry point for the hook to add
315
- * @param hookFunction function to execute
316
- */
317
- addHook(entryPoint: ElementHookName, hookFunction: ElementHook): void;
318
- /**
319
- * Adds a DOMPurify hook.
320
- *
321
- * @param entryPoint entry point for the hook to add
322
- * @param hookFunction function to execute
323
- */
324
- addHook(entryPoint: DocumentFragmentHookName, hookFunction: DocumentFragmentHook): void;
325
- /**
326
- * Adds a DOMPurify hook.
327
- *
328
- * @param entryPoint entry point for the hook to add
329
- * @param hookFunction function to execute
330
- */
331
- addHook(entryPoint: 'uponSanitizeElement', hookFunction: UponSanitizeElementHook): void;
332
- /**
333
- * Adds a DOMPurify hook.
334
- *
335
- * @param entryPoint entry point for the hook to add
336
- * @param hookFunction function to execute
337
- */
338
- addHook(entryPoint: 'uponSanitizeAttribute', hookFunction: UponSanitizeAttributeHook): void;
339
- /**
340
- * Remove a DOMPurify hook at a given entryPoint
341
- * (pops it from the stack of hooks if hook not specified)
342
- *
343
- * @param entryPoint entry point for the hook to remove
344
- * @param hookFunction optional specific hook to remove
345
- * @returns removed hook
346
- */
347
- removeHook(entryPoint: BasicHookName, hookFunction?: NodeHook): NodeHook | undefined;
348
- /**
349
- * Remove a DOMPurify hook at a given entryPoint
350
- * (pops it from the stack of hooks if hook not specified)
351
- *
352
- * @param entryPoint entry point for the hook to remove
353
- * @param hookFunction optional specific hook to remove
354
- * @returns removed hook
355
- */
356
- removeHook(entryPoint: ElementHookName, hookFunction?: ElementHook): ElementHook | undefined;
357
- /**
358
- * Remove a DOMPurify hook at a given entryPoint
359
- * (pops it from the stack of hooks if hook not specified)
360
- *
361
- * @param entryPoint entry point for the hook to remove
362
- * @param hookFunction optional specific hook to remove
363
- * @returns removed hook
364
- */
365
- removeHook(entryPoint: DocumentFragmentHookName, hookFunction?: DocumentFragmentHook): DocumentFragmentHook | undefined;
366
- /**
367
- * Remove a DOMPurify hook at a given entryPoint
368
- * (pops it from the stack of hooks if hook not specified)
369
- *
370
- * @param entryPoint entry point for the hook to remove
371
- * @param hookFunction optional specific hook to remove
372
- * @returns removed hook
373
- */
374
- removeHook(entryPoint: 'uponSanitizeElement', hookFunction?: UponSanitizeElementHook): UponSanitizeElementHook | undefined;
375
- /**
376
- * Remove a DOMPurify hook at a given entryPoint
377
- * (pops it from the stack of hooks if hook not specified)
378
- *
379
- * @param entryPoint entry point for the hook to remove
380
- * @param hookFunction optional specific hook to remove
381
- * @returns removed hook
382
- */
383
- removeHook(entryPoint: 'uponSanitizeAttribute', hookFunction?: UponSanitizeAttributeHook): UponSanitizeAttributeHook | undefined;
384
- /**
385
- * Removes all DOMPurify hooks at a given entryPoint
386
- *
387
- * @param entryPoint entry point for the hooks to remove
388
- */
389
- removeHooks(entryPoint: HookName): void;
390
- /**
391
- * Removes all DOMPurify hooks.
392
- */
393
- removeAllHooks(): void;
394
- }
395
- /**
396
- * An element removed by DOMPurify.
397
- */
398
- interface RemovedElement {
399
- /**
400
- * The element that was removed.
401
- */
402
- element: Node;
403
- }
404
- /**
405
- * An element removed by DOMPurify.
406
- */
407
- interface RemovedAttribute {
408
- /**
409
- * The attribute that was removed.
410
- */
411
- attribute: Attr | null;
412
- /**
413
- * The element that the attribute was removed.
414
- */
415
- from: Node;
416
- }
417
- type BasicHookName = 'beforeSanitizeElements' | 'afterSanitizeElements' | 'uponSanitizeShadowNode';
418
- type ElementHookName = 'beforeSanitizeAttributes' | 'afterSanitizeAttributes';
419
- type DocumentFragmentHookName = 'beforeSanitizeShadowDOM' | 'afterSanitizeShadowDOM';
420
- type UponSanitizeElementHookName = 'uponSanitizeElement';
421
- type UponSanitizeAttributeHookName = 'uponSanitizeAttribute';
422
- type HookName = BasicHookName | ElementHookName | DocumentFragmentHookName | UponSanitizeElementHookName | UponSanitizeAttributeHookName;
423
- type NodeHook = (this: DOMPurify, currentNode: Node, hookEvent: null, config: Config) => void;
424
- type ElementHook = (this: DOMPurify, currentNode: Element, hookEvent: null, config: Config) => void;
425
- type DocumentFragmentHook = (this: DOMPurify, currentNode: DocumentFragment, hookEvent: null, config: Config) => void;
426
- type UponSanitizeElementHook = (this: DOMPurify, currentNode: Node, hookEvent: UponSanitizeElementHookEvent, config: Config) => void;
427
- type UponSanitizeAttributeHook = (this: DOMPurify, currentNode: Element, hookEvent: UponSanitizeAttributeHookEvent, config: Config) => void;
428
- interface UponSanitizeElementHookEvent {
429
- tagName: string;
430
- allowedTags: Record<string, boolean>;
431
- }
432
- interface UponSanitizeAttributeHookEvent {
433
- attrName: string;
434
- attrValue: string;
435
- keepAttr: boolean;
436
- allowedAttributes: Record<string, boolean>;
437
- forceKeepAttr: boolean | undefined;
438
- }
439
- /**
440
- * A `Window`-like object containing the properties and types that DOMPurify requires.
441
- */
442
- type WindowLike = Pick<typeof globalThis, 'DocumentFragment' | 'HTMLTemplateElement' | 'Node' | 'Element' | 'NodeFilter' | 'NamedNodeMap' | 'HTMLFormElement' | 'DOMParser'> & {
443
- document?: Document;
444
- MozNamedAttrMap?: typeof window.NamedNodeMap;
445
- } & Pick<TrustedTypesWindow, 'trustedTypes'>;
446
-
447
- export { type Config, type DOMPurify, type DocumentFragmentHook, type ElementHook, type HookName, type NodeHook, type RemovedAttribute, type RemovedElement, type UponSanitizeAttributeHook, type UponSanitizeAttributeHookEvent, type UponSanitizeElementHook, type UponSanitizeElementHookEvent, type WindowLike, _default as default };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/dompurify/dist/purify.es.mjs DELETED
@@ -1,1386 +0,0 @@
1
- /*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
2
-
3
- const {
4
- entries,
5
- setPrototypeOf,
6
- isFrozen,
7
- getPrototypeOf,
8
- getOwnPropertyDescriptor
9
- } = Object;
10
- let {
11
- freeze,
12
- seal,
13
- create
14
- } = Object; // eslint-disable-line import/no-mutable-exports
15
- let {
16
- apply,
17
- construct
18
- } = typeof Reflect !== 'undefined' && Reflect;
19
- if (!freeze) {
20
- freeze = function freeze(x) {
21
- return x;
22
- };
23
- }
24
- if (!seal) {
25
- seal = function seal(x) {
26
- return x;
27
- };
28
- }
29
- if (!apply) {
30
- apply = function apply(func, thisArg) {
31
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
32
- args[_key - 2] = arguments[_key];
33
- }
34
- return func.apply(thisArg, args);
35
- };
36
- }
37
- if (!construct) {
38
- construct = function construct(Func) {
39
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
40
- args[_key2 - 1] = arguments[_key2];
41
- }
42
- return new Func(...args);
43
- };
44
- }
45
- const arrayForEach = unapply(Array.prototype.forEach);
46
- const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
47
- const arrayPop = unapply(Array.prototype.pop);
48
- const arrayPush = unapply(Array.prototype.push);
49
- const arraySplice = unapply(Array.prototype.splice);
50
- const stringToLowerCase = unapply(String.prototype.toLowerCase);
51
- const stringToString = unapply(String.prototype.toString);
52
- const stringMatch = unapply(String.prototype.match);
53
- const stringReplace = unapply(String.prototype.replace);
54
- const stringIndexOf = unapply(String.prototype.indexOf);
55
- const stringTrim = unapply(String.prototype.trim);
56
- const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
57
- const regExpTest = unapply(RegExp.prototype.test);
58
- const typeErrorCreate = unconstruct(TypeError);
59
- /**
60
- * Creates a new function that calls the given function with a specified thisArg and arguments.
61
- *
62
- * @param func - The function to be wrapped and called.
63
- * @returns A new function that calls the given function with a specified thisArg and arguments.
64
- */
65
- function unapply(func) {
66
- return function (thisArg) {
67
- if (thisArg instanceof RegExp) {
68
- thisArg.lastIndex = 0;
69
- }
70
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
71
- args[_key3 - 1] = arguments[_key3];
72
- }
73
- return apply(func, thisArg, args);
74
- };
75
- }
76
- /**
77
- * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
78
- *
79
- * @param func - The constructor function to be wrapped and called.
80
- * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
81
- */
82
- function unconstruct(Func) {
83
- return function () {
84
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
85
- args[_key4] = arguments[_key4];
86
- }
87
- return construct(Func, args);
88
- };
89
- }
90
- /**
91
- * Add properties to a lookup table
92
- *
93
- * @param set - The set to which elements will be added.
94
- * @param array - The array containing elements to be added to the set.
95
- * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
96
- * @returns The modified set with added elements.
97
- */
98
- function addToSet(set, array) {
99
- let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
100
- if (setPrototypeOf) {
101
- // Make 'in' and truthy checks like Boolean(set.constructor)
102
- // independent of any properties defined on Object.prototype.
103
- // Prevent prototype setters from intercepting set as a this value.
104
- setPrototypeOf(set, null);
105
- }
106
- let l = array.length;
107
- while (l--) {
108
- let element = array[l];
109
- if (typeof element === 'string') {
110
- const lcElement = transformCaseFunc(element);
111
- if (lcElement !== element) {
112
- // Config presets (e.g. tags.js, attrs.js) are immutable.
113
- if (!isFrozen(array)) {
114
- array[l] = lcElement;
115
- }
116
- element = lcElement;
117
- }
118
- }
119
- set[element] = true;
120
- }
121
- return set;
122
- }
123
- /**
124
- * Clean up an array to harden against CSPP
125
- *
126
- * @param array - The array to be cleaned.
127
- * @returns The cleaned version of the array
128
- */
129
- function cleanArray(array) {
130
- for (let index = 0; index < array.length; index++) {
131
- const isPropertyExist = objectHasOwnProperty(array, index);
132
- if (!isPropertyExist) {
133
- array[index] = null;
134
- }
135
- }
136
- return array;
137
- }
138
- /**
139
- * Shallow clone an object
140
- *
141
- * @param object - The object to be cloned.
142
- * @returns A new object that copies the original.
143
- */
144
- function clone(object) {
145
- const newObject = create(null);
146
- for (const [property, value] of entries(object)) {
147
- const isPropertyExist = objectHasOwnProperty(object, property);
148
- if (isPropertyExist) {
149
- if (Array.isArray(value)) {
150
- newObject[property] = cleanArray(value);
151
- } else if (value && typeof value === 'object' && value.constructor === Object) {
152
- newObject[property] = clone(value);
153
- } else {
154
- newObject[property] = value;
155
- }
156
- }
157
- }
158
- return newObject;
159
- }
160
- /**
161
- * This method automatically checks if the prop is function or getter and behaves accordingly.
162
- *
163
- * @param object - The object to look up the getter function in its prototype chain.
164
- * @param prop - The property name for which to find the getter function.
165
- * @returns The getter function found in the prototype chain or a fallback function.
166
- */
167
- function lookupGetter(object, prop) {
168
- while (object !== null) {
169
- const desc = getOwnPropertyDescriptor(object, prop);
170
- if (desc) {
171
- if (desc.get) {
172
- return unapply(desc.get);
173
- }
174
- if (typeof desc.value === 'function') {
175
- return unapply(desc.value);
176
- }
177
- }
178
- object = getPrototypeOf(object);
179
- }
180
- function fallbackValue() {
181
- return null;
182
- }
183
- return fallbackValue;
184
- }
185
-
186
- const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
187
- const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
188
- const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
189
- // List of SVG elements that are disallowed by default.
190
- // We still need to know them so that we can do namespace
191
- // checks properly in case one wants to add them to
192
- // allow-list.
193
- const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
194
- const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
195
- // Similarly to SVG, we want to know all MathML elements,
196
- // even those that we disallow by default.
197
- const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
198
- const text = freeze(['#text']);
199
-
200
- const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
201
- const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
202
- const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
203
- const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
204
-
205
- // eslint-disable-next-line unicorn/better-regex
206
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
207
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
208
- const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
209
- const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
210
- const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
211
- const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
212
- );
213
- const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
214
- const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
215
- );
216
- const DOCTYPE_NAME = seal(/^html$/i);
217
- const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
218
-
219
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
220
- __proto__: null,
221
- ARIA_ATTR: ARIA_ATTR,
222
- ATTR_WHITESPACE: ATTR_WHITESPACE,
223
- CUSTOM_ELEMENT: CUSTOM_ELEMENT,
224
- DATA_ATTR: DATA_ATTR,
225
- DOCTYPE_NAME: DOCTYPE_NAME,
226
- ERB_EXPR: ERB_EXPR,
227
- IS_ALLOWED_URI: IS_ALLOWED_URI,
228
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
229
- MUSTACHE_EXPR: MUSTACHE_EXPR,
230
- TMPLIT_EXPR: TMPLIT_EXPR
231
- });
232
-
233
- /* eslint-disable @typescript-eslint/indent */
234
- // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
235
- const NODE_TYPE = {
236
- element: 1,
237
- attribute: 2,
238
- text: 3,
239
- cdataSection: 4,
240
- entityReference: 5,
241
- // Deprecated
242
- entityNode: 6,
243
- // Deprecated
244
- progressingInstruction: 7,
245
- comment: 8,
246
- document: 9,
247
- documentType: 10,
248
- documentFragment: 11,
249
- notation: 12 // Deprecated
250
- };
251
- const getGlobal = function getGlobal() {
252
- return typeof window === 'undefined' ? null : window;
253
- };
254
- /**
255
- * Creates a no-op policy for internal use only.
256
- * Don't export this function outside this module!
257
- * @param trustedTypes The policy factory.
258
- * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
259
- * @return The policy created (or null, if Trusted Types
260
- * are not supported or creating the policy failed).
261
- */
262
- const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
263
- if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
264
- return null;
265
- }
266
- // Allow the callers to control the unique policy name
267
- // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
268
- // Policy creation with duplicate names throws in Trusted Types.
269
- let suffix = null;
270
- const ATTR_NAME = 'data-tt-policy-suffix';
271
- if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
272
- suffix = purifyHostElement.getAttribute(ATTR_NAME);
273
- }
274
- const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
275
- try {
276
- return trustedTypes.createPolicy(policyName, {
277
- createHTML(html) {
278
- return html;
279
- },
280
- createScriptURL(scriptUrl) {
281
- return scriptUrl;
282
- }
283
- });
284
- } catch (_) {
285
- // Policy creation failed (most likely another DOMPurify script has
286
- // already run). Skip creating the policy, as this will only cause errors
287
- // if TT are enforced.
288
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
289
- return null;
290
- }
291
- };
292
- const _createHooksMap = function _createHooksMap() {
293
- return {
294
- afterSanitizeAttributes: [],
295
- afterSanitizeElements: [],
296
- afterSanitizeShadowDOM: [],
297
- beforeSanitizeAttributes: [],
298
- beforeSanitizeElements: [],
299
- beforeSanitizeShadowDOM: [],
300
- uponSanitizeAttribute: [],
301
- uponSanitizeElement: [],
302
- uponSanitizeShadowNode: []
303
- };
304
- };
305
- function createDOMPurify() {
306
- let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
307
- const DOMPurify = root => createDOMPurify(root);
308
- DOMPurify.version = '3.3.1';
309
- DOMPurify.removed = [];
310
- if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
311
- // Not running in a browser, provide a factory function
312
- // so that you can pass your own Window
313
- DOMPurify.isSupported = false;
314
- return DOMPurify;
315
- }
316
- let {
317
- document
318
- } = window;
319
- const originalDocument = document;
320
- const currentScript = originalDocument.currentScript;
321
- const {
322
- DocumentFragment,
323
- HTMLTemplateElement,
324
- Node,
325
- Element,
326
- NodeFilter,
327
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
328
- HTMLFormElement,
329
- DOMParser,
330
- trustedTypes
331
- } = window;
332
- const ElementPrototype = Element.prototype;
333
- const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
334
- const remove = lookupGetter(ElementPrototype, 'remove');
335
- const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
336
- const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
337
- const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
338
- // As per issue #47, the web-components registry is inherited by a
339
- // new document created via createHTMLDocument. As per the spec
340
- // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
341
- // a new empty registry is used when creating a template contents owner
342
- // document, so we use that as our parent document to ensure nothing
343
- // is inherited.
344
- if (typeof HTMLTemplateElement === 'function') {
345
- const template = document.createElement('template');
346
- if (template.content && template.content.ownerDocument) {
347
- document = template.content.ownerDocument;
348
- }
349
- }
350
- let trustedTypesPolicy;
351
- let emptyHTML = '';
352
- const {
353
- implementation,
354
- createNodeIterator,
355
- createDocumentFragment,
356
- getElementsByTagName
357
- } = document;
358
- const {
359
- importNode
360
- } = originalDocument;
361
- let hooks = _createHooksMap();
362
- /**
363
- * Expose whether this browser supports running the full DOMPurify.
364
- */
365
- DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
366
- const {
367
- MUSTACHE_EXPR,
368
- ERB_EXPR,
369
- TMPLIT_EXPR,
370
- DATA_ATTR,
371
- ARIA_ATTR,
372
- IS_SCRIPT_OR_DATA,
373
- ATTR_WHITESPACE,
374
- CUSTOM_ELEMENT
375
- } = EXPRESSIONS;
376
- let {
377
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
378
- } = EXPRESSIONS;
379
- /**
380
- * We consider the elements and attributes below to be safe. Ideally
381
- * don't add any new ones but feel free to remove unwanted ones.
382
- */
383
- /* allowed element names */
384
- let ALLOWED_TAGS = null;
385
- const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
386
- /* Allowed attribute names */
387
- let ALLOWED_ATTR = null;
388
- const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
389
- /*
390
- * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
391
- * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
392
- * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
393
- * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
394
- */
395
- let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
396
- tagNameCheck: {
397
- writable: true,
398
- configurable: false,
399
- enumerable: true,
400
- value: null
401
- },
402
- attributeNameCheck: {
403
- writable: true,
404
- configurable: false,
405
- enumerable: true,
406
- value: null
407
- },
408
- allowCustomizedBuiltInElements: {
409
- writable: true,
410
- configurable: false,
411
- enumerable: true,
412
- value: false
413
- }
414
- }));
415
- /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
416
- let FORBID_TAGS = null;
417
- /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
418
- let FORBID_ATTR = null;
419
- /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
420
- const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
421
- tagCheck: {
422
- writable: true,
423
- configurable: false,
424
- enumerable: true,
425
- value: null
426
- },
427
- attributeCheck: {
428
- writable: true,
429
- configurable: false,
430
- enumerable: true,
431
- value: null
432
- }
433
- }));
434
- /* Decide if ARIA attributes are okay */
435
- let ALLOW_ARIA_ATTR = true;
436
- /* Decide if custom data attributes are okay */
437
- let ALLOW_DATA_ATTR = true;
438
- /* Decide if unknown protocols are okay */
439
- let ALLOW_UNKNOWN_PROTOCOLS = false;
440
- /* Decide if self-closing tags in attributes are allowed.
441
- * Usually removed due to a mXSS issue in jQuery 3.0 */
442
- let ALLOW_SELF_CLOSE_IN_ATTR = true;
443
- /* Output should be safe for common template engines.
444
- * This means, DOMPurify removes data attributes, mustaches and ERB
445
- */
446
- let SAFE_FOR_TEMPLATES = false;
447
- /* Output should be safe even for XML used within HTML and alike.
448
- * This means, DOMPurify removes comments when containing risky content.
449
- */
450
- let SAFE_FOR_XML = true;
451
- /* Decide if document with <html>... should be returned */
452
- let WHOLE_DOCUMENT = false;
453
- /* Track whether config is already set on this instance of DOMPurify. */
454
- let SET_CONFIG = false;
455
- /* Decide if all elements (e.g. style, script) must be children of
456
- * document.body. By default, browsers might move them to document.head */
457
- let FORCE_BODY = false;
458
- /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
459
- * string (or a TrustedHTML object if Trusted Types are supported).
460
- * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
461
- */
462
- let RETURN_DOM = false;
463
- /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
464
- * string (or a TrustedHTML object if Trusted Types are supported) */
465
- let RETURN_DOM_FRAGMENT = false;
466
- /* Try to return a Trusted Type object instead of a string, return a string in
467
- * case Trusted Types are not supported */
468
- let RETURN_TRUSTED_TYPE = false;
469
- /* Output should be free from DOM clobbering attacks?
470
- * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
471
- */
472
- let SANITIZE_DOM = true;
473
- /* Achieve full DOM Clobbering protection by isolating the namespace of named
474
- * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
475
- *
476
- * HTML/DOM spec rules that enable DOM Clobbering:
477
- * - Named Access on Window (§7.3.3)
478
- * - DOM Tree Accessors (§3.1.5)
479
- * - Form Element Parent-Child Relations (§4.10.3)
480
- * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
481
- * - HTMLCollection (§4.2.10.2)
482
- *
483
- * Namespace isolation is implemented by prefixing `id` and `name` attributes
484
- * with a constant string, i.e., `user-content-`
485
- */
486
- let SANITIZE_NAMED_PROPS = false;
487
- const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
488
- /* Keep element content when removing element? */
489
- let KEEP_CONTENT = true;
490
- /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
491
- * of importing it into a new Document and returning a sanitized copy */
492
- let IN_PLACE = false;
493
- /* Allow usage of profiles like html, svg and mathMl */
494
- let USE_PROFILES = {};
495
- /* Tags to ignore content of when KEEP_CONTENT is true */
496
- let FORBID_CONTENTS = null;
497
- const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
498
- /* Tags that are safe for data: URIs */
499
- let DATA_URI_TAGS = null;
500
- const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
501
- /* Attributes safe for values like "javascript:" */
502
- let URI_SAFE_ATTRIBUTES = null;
503
- const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
504
- const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
505
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
506
- const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
507
- /* Document namespace */
508
- let NAMESPACE = HTML_NAMESPACE;
509
- let IS_EMPTY_INPUT = false;
510
- /* Allowed XHTML+XML namespaces */
511
- let ALLOWED_NAMESPACES = null;
512
- const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
513
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
514
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
515
- // Certain elements are allowed in both SVG and HTML
516
- // namespace. We need to specify them explicitly
517
- // so that they don't get erroneously deleted from
518
- // HTML namespace.
519
- const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
520
- /* Parsing of strict XHTML documents */
521
- let PARSER_MEDIA_TYPE = null;
522
- const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
523
- const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
524
- let transformCaseFunc = null;
525
- /* Keep a reference to config to pass to hooks */
526
- let CONFIG = null;
527
- /* Ideally, do not touch anything below this line */
528
- /* ______________________________________________ */
529
- const formElement = document.createElement('form');
530
- const isRegexOrFunction = function isRegexOrFunction(testValue) {
531
- return testValue instanceof RegExp || testValue instanceof Function;
532
- };
533
- /**
534
- * _parseConfig
535
- *
536
- * @param cfg optional config literal
537
- */
538
- // eslint-disable-next-line complexity
539
- const _parseConfig = function _parseConfig() {
540
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
541
- if (CONFIG && CONFIG === cfg) {
542
- return;
543
- }
544
- /* Shield configuration object from tampering */
545
- if (!cfg || typeof cfg !== 'object') {
546
- cfg = {};
547
- }
548
- /* Shield configuration object from prototype pollution */
549
- cfg = clone(cfg);
550
- PARSER_MEDIA_TYPE =
551
- // eslint-disable-next-line unicorn/prefer-includes
552
- SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
553
- // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
554
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
555
- /* Set configuration parameters */
556
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
557
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
558
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
559
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
560
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
561
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
562
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
563
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
564
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
565
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
566
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
567
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
568
- ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
569
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
570
- SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
571
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
572
- RETURN_DOM = cfg.RETURN_DOM || false; // Default false
573
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
574
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
575
- FORCE_BODY = cfg.FORCE_BODY || false; // Default false
576
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
577
- SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
578
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
579
- IN_PLACE = cfg.IN_PLACE || false; // Default false
580
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
581
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
582
- MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
583
- HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
584
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
585
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
586
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
587
- }
588
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
589
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
590
- }
591
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
592
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
593
- }
594
- if (SAFE_FOR_TEMPLATES) {
595
- ALLOW_DATA_ATTR = false;
596
- }
597
- if (RETURN_DOM_FRAGMENT) {
598
- RETURN_DOM = true;
599
- }
600
- /* Parse profile info */
601
- if (USE_PROFILES) {
602
- ALLOWED_TAGS = addToSet({}, text);
603
- ALLOWED_ATTR = [];
604
- if (USE_PROFILES.html === true) {
605
- addToSet(ALLOWED_TAGS, html$1);
606
- addToSet(ALLOWED_ATTR, html);
607
- }
608
- if (USE_PROFILES.svg === true) {
609
- addToSet(ALLOWED_TAGS, svg$1);
610
- addToSet(ALLOWED_ATTR, svg);
611
- addToSet(ALLOWED_ATTR, xml);
612
- }
613
- if (USE_PROFILES.svgFilters === true) {
614
- addToSet(ALLOWED_TAGS, svgFilters);
615
- addToSet(ALLOWED_ATTR, svg);
616
- addToSet(ALLOWED_ATTR, xml);
617
- }
618
- if (USE_PROFILES.mathMl === true) {
619
- addToSet(ALLOWED_TAGS, mathMl$1);
620
- addToSet(ALLOWED_ATTR, mathMl);
621
- addToSet(ALLOWED_ATTR, xml);
622
- }
623
- }
624
- /* Merge configuration parameters */
625
- if (cfg.ADD_TAGS) {
626
- if (typeof cfg.ADD_TAGS === 'function') {
627
- EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
628
- } else {
629
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
630
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
631
- }
632
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
633
- }
634
- }
635
- if (cfg.ADD_ATTR) {
636
- if (typeof cfg.ADD_ATTR === 'function') {
637
- EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
638
- } else {
639
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
640
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
641
- }
642
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
643
- }
644
- }
645
- if (cfg.ADD_URI_SAFE_ATTR) {
646
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
647
- }
648
- if (cfg.FORBID_CONTENTS) {
649
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
650
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
651
- }
652
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
653
- }
654
- if (cfg.ADD_FORBID_CONTENTS) {
655
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
656
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
657
- }
658
- addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
659
- }
660
- /* Add #text in case KEEP_CONTENT is set to true */
661
- if (KEEP_CONTENT) {
662
- ALLOWED_TAGS['#text'] = true;
663
- }
664
- /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
665
- if (WHOLE_DOCUMENT) {
666
- addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
667
- }
668
- /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
669
- if (ALLOWED_TAGS.table) {
670
- addToSet(ALLOWED_TAGS, ['tbody']);
671
- delete FORBID_TAGS.tbody;
672
- }
673
- if (cfg.TRUSTED_TYPES_POLICY) {
674
- if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
675
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
676
- }
677
- if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
678
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
679
- }
680
- // Overwrite existing TrustedTypes policy.
681
- trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
682
- // Sign local variables required by `sanitize`.
683
- emptyHTML = trustedTypesPolicy.createHTML('');
684
- } else {
685
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
686
- if (trustedTypesPolicy === undefined) {
687
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
688
- }
689
- // If creating the internal policy succeeded sign internal variables.
690
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
691
- emptyHTML = trustedTypesPolicy.createHTML('');
692
- }
693
- }
694
- // Prevent further manipulation of configuration.
695
- // Not available in IE8, Safari 5, etc.
696
- if (freeze) {
697
- freeze(cfg);
698
- }
699
- CONFIG = cfg;
700
- };
701
- /* Keep track of all possible SVG and MathML tags
702
- * so that we can perform the namespace checks
703
- * correctly. */
704
- const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
705
- const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
706
- /**
707
- * @param element a DOM element whose namespace is being checked
708
- * @returns Return false if the element has a
709
- * namespace that a spec-compliant parser would never
710
- * return. Return true otherwise.
711
- */
712
- const _checkValidNamespace = function _checkValidNamespace(element) {
713
- let parent = getParentNode(element);
714
- // In JSDOM, if we're inside shadow DOM, then parentNode
715
- // can be null. We just simulate parent in this case.
716
- if (!parent || !parent.tagName) {
717
- parent = {
718
- namespaceURI: NAMESPACE,
719
- tagName: 'template'
720
- };
721
- }
722
- const tagName = stringToLowerCase(element.tagName);
723
- const parentTagName = stringToLowerCase(parent.tagName);
724
- if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
725
- return false;
726
- }
727
- if (element.namespaceURI === SVG_NAMESPACE) {
728
- // The only way to switch from HTML namespace to SVG
729
- // is via <svg>. If it happens via any other tag, then
730
- // it should be killed.
731
- if (parent.namespaceURI === HTML_NAMESPACE) {
732
- return tagName === 'svg';
733
- }
734
- // The only way to switch from MathML to SVG is via`
735
- // svg if parent is either <annotation-xml> or MathML
736
- // text integration points.
737
- if (parent.namespaceURI === MATHML_NAMESPACE) {
738
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
739
- }
740
- // We only allow elements that are defined in SVG
741
- // spec. All others are disallowed in SVG namespace.
742
- return Boolean(ALL_SVG_TAGS[tagName]);
743
- }
744
- if (element.namespaceURI === MATHML_NAMESPACE) {
745
- // The only way to switch from HTML namespace to MathML
746
- // is via <math>. If it happens via any other tag, then
747
- // it should be killed.
748
- if (parent.namespaceURI === HTML_NAMESPACE) {
749
- return tagName === 'math';
750
- }
751
- // The only way to switch from SVG to MathML is via
752
- // <math> and HTML integration points
753
- if (parent.namespaceURI === SVG_NAMESPACE) {
754
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
755
- }
756
- // We only allow elements that are defined in MathML
757
- // spec. All others are disallowed in MathML namespace.
758
- return Boolean(ALL_MATHML_TAGS[tagName]);
759
- }
760
- if (element.namespaceURI === HTML_NAMESPACE) {
761
- // The only way to switch from SVG to HTML is via
762
- // HTML integration points, and from MathML to HTML
763
- // is via MathML text integration points
764
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
765
- return false;
766
- }
767
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
768
- return false;
769
- }
770
- // We disallow tags that are specific for MathML
771
- // or SVG and should never appear in HTML namespace
772
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
773
- }
774
- // For XHTML and XML documents that support custom namespaces
775
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
776
- return true;
777
- }
778
- // The code should never reach this place (this means
779
- // that the element somehow got namespace that is not
780
- // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
781
- // Return false just in case.
782
- return false;
783
- };
784
- /**
785
- * _forceRemove
786
- *
787
- * @param node a DOM node
788
- */
789
- const _forceRemove = function _forceRemove(node) {
790
- arrayPush(DOMPurify.removed, {
791
- element: node
792
- });
793
- try {
794
- // eslint-disable-next-line unicorn/prefer-dom-node-remove
795
- getParentNode(node).removeChild(node);
796
- } catch (_) {
797
- remove(node);
798
- }
799
- };
800
- /**
801
- * _removeAttribute
802
- *
803
- * @param name an Attribute name
804
- * @param element a DOM node
805
- */
806
- const _removeAttribute = function _removeAttribute(name, element) {
807
- try {
808
- arrayPush(DOMPurify.removed, {
809
- attribute: element.getAttributeNode(name),
810
- from: element
811
- });
812
- } catch (_) {
813
- arrayPush(DOMPurify.removed, {
814
- attribute: null,
815
- from: element
816
- });
817
- }
818
- element.removeAttribute(name);
819
- // We void attribute values for unremovable "is" attributes
820
- if (name === 'is') {
821
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
822
- try {
823
- _forceRemove(element);
824
- } catch (_) {}
825
- } else {
826
- try {
827
- element.setAttribute(name, '');
828
- } catch (_) {}
829
- }
830
- }
831
- };
832
- /**
833
- * _initDocument
834
- *
835
- * @param dirty - a string of dirty markup
836
- * @return a DOM, filled with the dirty markup
837
- */
838
- const _initDocument = function _initDocument(dirty) {
839
- /* Create a HTML document */
840
- let doc = null;
841
- let leadingWhitespace = null;
842
- if (FORCE_BODY) {
843
- dirty = '<remove></remove>' + dirty;
844
- } else {
845
- /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
846
- const matches = stringMatch(dirty, /^[\r\n\t ]+/);
847
- leadingWhitespace = matches && matches[0];
848
- }
849
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
850
- // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
851
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
852
- }
853
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
854
- /*
855
- * Use the DOMParser API by default, fallback later if needs be
856
- * DOMParser not work for svg when has multiple root element.
857
- */
858
- if (NAMESPACE === HTML_NAMESPACE) {
859
- try {
860
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
861
- } catch (_) {}
862
- }
863
- /* Use createHTMLDocument in case DOMParser is not available */
864
- if (!doc || !doc.documentElement) {
865
- doc = implementation.createDocument(NAMESPACE, 'template', null);
866
- try {
867
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
868
- } catch (_) {
869
- // Syntax error if dirtyPayload is invalid xml
870
- }
871
- }
872
- const body = doc.body || doc.documentElement;
873
- if (dirty && leadingWhitespace) {
874
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
875
- }
876
- /* Work on whole document or just its body */
877
- if (NAMESPACE === HTML_NAMESPACE) {
878
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
879
- }
880
- return WHOLE_DOCUMENT ? doc.documentElement : body;
881
- };
882
- /**
883
- * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
884
- *
885
- * @param root The root element or node to start traversing on.
886
- * @return The created NodeIterator
887
- */
888
- const _createNodeIterator = function _createNodeIterator(root) {
889
- return createNodeIterator.call(root.ownerDocument || root, root,
890
- // eslint-disable-next-line no-bitwise
891
- NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
892
- };
893
- /**
894
- * _isClobbered
895
- *
896
- * @param element element to check for clobbering attacks
897
- * @return true if clobbered, false if safe
898
- */
899
- const _isClobbered = function _isClobbered(element) {
900
- return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
901
- };
902
- /**
903
- * Checks whether the given object is a DOM node.
904
- *
905
- * @param value object to check whether it's a DOM node
906
- * @return true is object is a DOM node
907
- */
908
- const _isNode = function _isNode(value) {
909
- return typeof Node === 'function' && value instanceof Node;
910
- };
911
- function _executeHooks(hooks, currentNode, data) {
912
- arrayForEach(hooks, hook => {
913
- hook.call(DOMPurify, currentNode, data, CONFIG);
914
- });
915
- }
916
- /**
917
- * _sanitizeElements
918
- *
919
- * @protect nodeName
920
- * @protect textContent
921
- * @protect removeChild
922
- * @param currentNode to check for permission to exist
923
- * @return true if node was killed, false if left alive
924
- */
925
- const _sanitizeElements = function _sanitizeElements(currentNode) {
926
- let content = null;
927
- /* Execute a hook if present */
928
- _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
929
- /* Check if element is clobbered or can clobber */
930
- if (_isClobbered(currentNode)) {
931
- _forceRemove(currentNode);
932
- return true;
933
- }
934
- /* Now let's check the element's type and name */
935
- const tagName = transformCaseFunc(currentNode.nodeName);
936
- /* Execute a hook if present */
937
- _executeHooks(hooks.uponSanitizeElement, currentNode, {
938
- tagName,
939
- allowedTags: ALLOWED_TAGS
940
- });
941
- /* Detect mXSS attempts abusing namespace confusion */
942
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
943
- _forceRemove(currentNode);
944
- return true;
945
- }
946
- /* Remove any occurrence of processing instructions */
947
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
948
- _forceRemove(currentNode);
949
- return true;
950
- }
951
- /* Remove any kind of possibly harmful comments */
952
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
953
- _forceRemove(currentNode);
954
- return true;
955
- }
956
- /* Remove element if anything forbids its presence */
957
- if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
958
- /* Check if we have a custom element to handle */
959
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
960
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
961
- return false;
962
- }
963
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
964
- return false;
965
- }
966
- }
967
- /* Keep content except for bad-listed elements */
968
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
969
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
970
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
971
- if (childNodes && parentNode) {
972
- const childCount = childNodes.length;
973
- for (let i = childCount - 1; i >= 0; --i) {
974
- const childClone = cloneNode(childNodes[i], true);
975
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
976
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
977
- }
978
- }
979
- }
980
- _forceRemove(currentNode);
981
- return true;
982
- }
983
- /* Check whether element has a valid namespace */
984
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
985
- _forceRemove(currentNode);
986
- return true;
987
- }
988
- /* Make sure that older browsers don't get fallback-tag mXSS */
989
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
990
- _forceRemove(currentNode);
991
- return true;
992
- }
993
- /* Sanitize element content to be template-safe */
994
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
995
- /* Get the element's text content */
996
- content = currentNode.textContent;
997
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
998
- content = stringReplace(content, expr, ' ');
999
- });
1000
- if (currentNode.textContent !== content) {
1001
- arrayPush(DOMPurify.removed, {
1002
- element: currentNode.cloneNode()
1003
- });
1004
- currentNode.textContent = content;
1005
- }
1006
- }
1007
- /* Execute a hook if present */
1008
- _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1009
- return false;
1010
- };
1011
- /**
1012
- * _isValidAttribute
1013
- *
1014
- * @param lcTag Lowercase tag name of containing element.
1015
- * @param lcName Lowercase attribute name.
1016
- * @param value Attribute value.
1017
- * @return Returns true if `value` is valid, otherwise false.
1018
- */
1019
- // eslint-disable-next-line complexity
1020
- const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1021
- /* Make sure attribute cannot clobber */
1022
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1023
- return false;
1024
- }
1025
- /* Allow valid data-* attributes: At least one character after "-"
1026
- (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1027
- XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1028
- We don't need to check the value; it's always URI safe. */
1029
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1030
- if (
1031
- // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1032
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1033
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1034
- _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||
1035
- // Alternative, second condition checks if it's an `is`-attribute, AND
1036
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1037
- lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1038
- return false;
1039
- }
1040
- /* Check value is safe. First, is attr inert? If so, is safe */
1041
- } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1042
- return false;
1043
- } else ;
1044
- return true;
1045
- };
1046
- /**
1047
- * _isBasicCustomElement
1048
- * checks if at least one dash is included in tagName, and it's not the first char
1049
- * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1050
- *
1051
- * @param tagName name of the tag of the node to sanitize
1052
- * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1053
- */
1054
- const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1055
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1056
- };
1057
- /**
1058
- * _sanitizeAttributes
1059
- *
1060
- * @protect attributes
1061
- * @protect nodeName
1062
- * @protect removeAttribute
1063
- * @protect setAttribute
1064
- *
1065
- * @param currentNode to sanitize
1066
- */
1067
- const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1068
- /* Execute a hook if present */
1069
- _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1070
- const {
1071
- attributes
1072
- } = currentNode;
1073
- /* Check if we have attributes; if not we might have a text node */
1074
- if (!attributes || _isClobbered(currentNode)) {
1075
- return;
1076
- }
1077
- const hookEvent = {
1078
- attrName: '',
1079
- attrValue: '',
1080
- keepAttr: true,
1081
- allowedAttributes: ALLOWED_ATTR,
1082
- forceKeepAttr: undefined
1083
- };
1084
- let l = attributes.length;
1085
- /* Go backwards over all attributes; safely remove bad ones */
1086
- while (l--) {
1087
- const attr = attributes[l];
1088
- const {
1089
- name,
1090
- namespaceURI,
1091
- value: attrValue
1092
- } = attr;
1093
- const lcName = transformCaseFunc(name);
1094
- const initValue = attrValue;
1095
- let value = name === 'value' ? initValue : stringTrim(initValue);
1096
- /* Execute a hook if present */
1097
- hookEvent.attrName = lcName;
1098
- hookEvent.attrValue = value;
1099
- hookEvent.keepAttr = true;
1100
- hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1101
- _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1102
- value = hookEvent.attrValue;
1103
- /* Full DOM Clobbering protection via namespace isolation,
1104
- * Prefix id and name attributes with `user-content-`
1105
- */
1106
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1107
- // Remove the attribute with this value
1108
- _removeAttribute(name, currentNode);
1109
- // Prefix the value and later re-create the attribute with the sanitized value
1110
- value = SANITIZE_NAMED_PROPS_PREFIX + value;
1111
- }
1112
- /* Work around a security issue with comments inside attributes */
1113
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
1114
- _removeAttribute(name, currentNode);
1115
- continue;
1116
- }
1117
- /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
1118
- if (lcName === 'attributename' && stringMatch(value, 'href')) {
1119
- _removeAttribute(name, currentNode);
1120
- continue;
1121
- }
1122
- /* Did the hooks approve of the attribute? */
1123
- if (hookEvent.forceKeepAttr) {
1124
- continue;
1125
- }
1126
- /* Did the hooks approve of the attribute? */
1127
- if (!hookEvent.keepAttr) {
1128
- _removeAttribute(name, currentNode);
1129
- continue;
1130
- }
1131
- /* Work around a security issue in jQuery 3.0 */
1132
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1133
- _removeAttribute(name, currentNode);
1134
- continue;
1135
- }
1136
- /* Sanitize attribute content to be template-safe */
1137
- if (SAFE_FOR_TEMPLATES) {
1138
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1139
- value = stringReplace(value, expr, ' ');
1140
- });
1141
- }
1142
- /* Is `value` valid for this attribute? */
1143
- const lcTag = transformCaseFunc(currentNode.nodeName);
1144
- if (!_isValidAttribute(lcTag, lcName, value)) {
1145
- _removeAttribute(name, currentNode);
1146
- continue;
1147
- }
1148
- /* Handle attributes that require Trusted Types */
1149
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1150
- if (namespaceURI) ; else {
1151
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1152
- case 'TrustedHTML':
1153
- {
1154
- value = trustedTypesPolicy.createHTML(value);
1155
- break;
1156
- }
1157
- case 'TrustedScriptURL':
1158
- {
1159
- value = trustedTypesPolicy.createScriptURL(value);
1160
- break;
1161
- }
1162
- }
1163
- }
1164
- }
1165
- /* Handle invalid data-* attribute set by try-catching it */
1166
- if (value !== initValue) {
1167
- try {
1168
- if (namespaceURI) {
1169
- currentNode.setAttributeNS(namespaceURI, name, value);
1170
- } else {
1171
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1172
- currentNode.setAttribute(name, value);
1173
- }
1174
- if (_isClobbered(currentNode)) {
1175
- _forceRemove(currentNode);
1176
- } else {
1177
- arrayPop(DOMPurify.removed);
1178
- }
1179
- } catch (_) {
1180
- _removeAttribute(name, currentNode);
1181
- }
1182
- }
1183
- }
1184
- /* Execute a hook if present */
1185
- _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1186
- };
1187
- /**
1188
- * _sanitizeShadowDOM
1189
- *
1190
- * @param fragment to iterate over recursively
1191
- */
1192
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1193
- let shadowNode = null;
1194
- const shadowIterator = _createNodeIterator(fragment);
1195
- /* Execute a hook if present */
1196
- _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1197
- while (shadowNode = shadowIterator.nextNode()) {
1198
- /* Execute a hook if present */
1199
- _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1200
- /* Sanitize tags and elements */
1201
- _sanitizeElements(shadowNode);
1202
- /* Check attributes next */
1203
- _sanitizeAttributes(shadowNode);
1204
- /* Deep shadow DOM detected */
1205
- if (shadowNode.content instanceof DocumentFragment) {
1206
- _sanitizeShadowDOM(shadowNode.content);
1207
- }
1208
- }
1209
- /* Execute a hook if present */
1210
- _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1211
- };
1212
- // eslint-disable-next-line complexity
1213
- DOMPurify.sanitize = function (dirty) {
1214
- let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1215
- let body = null;
1216
- let importedNode = null;
1217
- let currentNode = null;
1218
- let returnNode = null;
1219
- /* Make sure we have a string to sanitize.
1220
- DO NOT return early, as this will return the wrong type if
1221
- the user has requested a DOM object rather than a string */
1222
- IS_EMPTY_INPUT = !dirty;
1223
- if (IS_EMPTY_INPUT) {
1224
- dirty = '<!-->';
1225
- }
1226
- /* Stringify, in case dirty is an object */
1227
- if (typeof dirty !== 'string' && !_isNode(dirty)) {
1228
- if (typeof dirty.toString === 'function') {
1229
- dirty = dirty.toString();
1230
- if (typeof dirty !== 'string') {
1231
- throw typeErrorCreate('dirty is not a string, aborting');
1232
- }
1233
- } else {
1234
- throw typeErrorCreate('toString is not a function');
1235
- }
1236
- }
1237
- /* Return dirty HTML if DOMPurify cannot run */
1238
- if (!DOMPurify.isSupported) {
1239
- return dirty;
1240
- }
1241
- /* Assign config vars */
1242
- if (!SET_CONFIG) {
1243
- _parseConfig(cfg);
1244
- }
1245
- /* Clean up removed elements */
1246
- DOMPurify.removed = [];
1247
- /* Check if dirty is correctly typed for IN_PLACE */
1248
- if (typeof dirty === 'string') {
1249
- IN_PLACE = false;
1250
- }
1251
- if (IN_PLACE) {
1252
- /* Do some early pre-sanitization to avoid unsafe root nodes */
1253
- if (dirty.nodeName) {
1254
- const tagName = transformCaseFunc(dirty.nodeName);
1255
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1256
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1257
- }
1258
- }
1259
- } else if (dirty instanceof Node) {
1260
- /* If dirty is a DOM element, append to an empty document to avoid
1261
- elements being stripped by the parser */
1262
- body = _initDocument('<!---->');
1263
- importedNode = body.ownerDocument.importNode(dirty, true);
1264
- if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
1265
- /* Node is already a body, use as is */
1266
- body = importedNode;
1267
- } else if (importedNode.nodeName === 'HTML') {
1268
- body = importedNode;
1269
- } else {
1270
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1271
- body.appendChild(importedNode);
1272
- }
1273
- } else {
1274
- /* Exit directly if we have nothing to do */
1275
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1276
- // eslint-disable-next-line unicorn/prefer-includes
1277
- dirty.indexOf('<') === -1) {
1278
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1279
- }
1280
- /* Initialize the document to work on */
1281
- body = _initDocument(dirty);
1282
- /* Check we have a DOM node from the data */
1283
- if (!body) {
1284
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1285
- }
1286
- }
1287
- /* Remove first element node (ours) if FORCE_BODY is set */
1288
- if (body && FORCE_BODY) {
1289
- _forceRemove(body.firstChild);
1290
- }
1291
- /* Get node iterator */
1292
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1293
- /* Now start iterating over the created document */
1294
- while (currentNode = nodeIterator.nextNode()) {
1295
- /* Sanitize tags and elements */
1296
- _sanitizeElements(currentNode);
1297
- /* Check attributes next */
1298
- _sanitizeAttributes(currentNode);
1299
- /* Shadow DOM detected, sanitize it */
1300
- if (currentNode.content instanceof DocumentFragment) {
1301
- _sanitizeShadowDOM(currentNode.content);
1302
- }
1303
- }
1304
- /* If we sanitized `dirty` in-place, return it. */
1305
- if (IN_PLACE) {
1306
- return dirty;
1307
- }
1308
- /* Return sanitized string or DOM */
1309
- if (RETURN_DOM) {
1310
- if (RETURN_DOM_FRAGMENT) {
1311
- returnNode = createDocumentFragment.call(body.ownerDocument);
1312
- while (body.firstChild) {
1313
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1314
- returnNode.appendChild(body.firstChild);
1315
- }
1316
- } else {
1317
- returnNode = body;
1318
- }
1319
- if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1320
- /*
1321
- AdoptNode() is not used because internal state is not reset
1322
- (e.g. the past names map of a HTMLFormElement), this is safe
1323
- in theory but we would rather not risk another attack vector.
1324
- The state that is cloned by importNode() is explicitly defined
1325
- by the specs.
1326
- */
1327
- returnNode = importNode.call(originalDocument, returnNode, true);
1328
- }
1329
- return returnNode;
1330
- }
1331
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1332
- /* Serialize doctype if allowed */
1333
- if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1334
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1335
- }
1336
- /* Sanitize final string template-safe */
1337
- if (SAFE_FOR_TEMPLATES) {
1338
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1339
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
1340
- });
1341
- }
1342
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1343
- };
1344
- DOMPurify.setConfig = function () {
1345
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1346
- _parseConfig(cfg);
1347
- SET_CONFIG = true;
1348
- };
1349
- DOMPurify.clearConfig = function () {
1350
- CONFIG = null;
1351
- SET_CONFIG = false;
1352
- };
1353
- DOMPurify.isValidAttribute = function (tag, attr, value) {
1354
- /* Initialize shared config vars if necessary. */
1355
- if (!CONFIG) {
1356
- _parseConfig({});
1357
- }
1358
- const lcTag = transformCaseFunc(tag);
1359
- const lcName = transformCaseFunc(attr);
1360
- return _isValidAttribute(lcTag, lcName, value);
1361
- };
1362
- DOMPurify.addHook = function (entryPoint, hookFunction) {
1363
- if (typeof hookFunction !== 'function') {
1364
- return;
1365
- }
1366
- arrayPush(hooks[entryPoint], hookFunction);
1367
- };
1368
- DOMPurify.removeHook = function (entryPoint, hookFunction) {
1369
- if (hookFunction !== undefined) {
1370
- const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1371
- return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
1372
- }
1373
- return arrayPop(hooks[entryPoint]);
1374
- };
1375
- DOMPurify.removeHooks = function (entryPoint) {
1376
- hooks[entryPoint] = [];
1377
- };
1378
- DOMPurify.removeAllHooks = function () {
1379
- hooks = _createHooksMap();
1380
- };
1381
- return DOMPurify;
1382
- }
1383
- var purify = createDOMPurify();
1384
-
1385
- export { purify as default };
1386
- //# sourceMappingURL=purify.es.mjs.map
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/dompurify/dist/purify.es.mjs.map DELETED
The diff for this file is too large to render. See raw diff
 
ui/node_modules/dompurify/dist/purify.js DELETED
@@ -1,1394 +0,0 @@
1
- /*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
2
-
3
- (function (global, factory) {
4
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
5
- typeof define === 'function' && define.amd ? define(factory) :
6
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DOMPurify = factory());
7
- })(this, (function () { 'use strict';
8
-
9
- const {
10
- entries,
11
- setPrototypeOf,
12
- isFrozen,
13
- getPrototypeOf,
14
- getOwnPropertyDescriptor
15
- } = Object;
16
- let {
17
- freeze,
18
- seal,
19
- create
20
- } = Object; // eslint-disable-line import/no-mutable-exports
21
- let {
22
- apply,
23
- construct
24
- } = typeof Reflect !== 'undefined' && Reflect;
25
- if (!freeze) {
26
- freeze = function freeze(x) {
27
- return x;
28
- };
29
- }
30
- if (!seal) {
31
- seal = function seal(x) {
32
- return x;
33
- };
34
- }
35
- if (!apply) {
36
- apply = function apply(func, thisArg) {
37
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
38
- args[_key - 2] = arguments[_key];
39
- }
40
- return func.apply(thisArg, args);
41
- };
42
- }
43
- if (!construct) {
44
- construct = function construct(Func) {
45
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
46
- args[_key2 - 1] = arguments[_key2];
47
- }
48
- return new Func(...args);
49
- };
50
- }
51
- const arrayForEach = unapply(Array.prototype.forEach);
52
- const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
53
- const arrayPop = unapply(Array.prototype.pop);
54
- const arrayPush = unapply(Array.prototype.push);
55
- const arraySplice = unapply(Array.prototype.splice);
56
- const stringToLowerCase = unapply(String.prototype.toLowerCase);
57
- const stringToString = unapply(String.prototype.toString);
58
- const stringMatch = unapply(String.prototype.match);
59
- const stringReplace = unapply(String.prototype.replace);
60
- const stringIndexOf = unapply(String.prototype.indexOf);
61
- const stringTrim = unapply(String.prototype.trim);
62
- const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
63
- const regExpTest = unapply(RegExp.prototype.test);
64
- const typeErrorCreate = unconstruct(TypeError);
65
- /**
66
- * Creates a new function that calls the given function with a specified thisArg and arguments.
67
- *
68
- * @param func - The function to be wrapped and called.
69
- * @returns A new function that calls the given function with a specified thisArg and arguments.
70
- */
71
- function unapply(func) {
72
- return function (thisArg) {
73
- if (thisArg instanceof RegExp) {
74
- thisArg.lastIndex = 0;
75
- }
76
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
77
- args[_key3 - 1] = arguments[_key3];
78
- }
79
- return apply(func, thisArg, args);
80
- };
81
- }
82
- /**
83
- * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
84
- *
85
- * @param func - The constructor function to be wrapped and called.
86
- * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
87
- */
88
- function unconstruct(Func) {
89
- return function () {
90
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
91
- args[_key4] = arguments[_key4];
92
- }
93
- return construct(Func, args);
94
- };
95
- }
96
- /**
97
- * Add properties to a lookup table
98
- *
99
- * @param set - The set to which elements will be added.
100
- * @param array - The array containing elements to be added to the set.
101
- * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
102
- * @returns The modified set with added elements.
103
- */
104
- function addToSet(set, array) {
105
- let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
106
- if (setPrototypeOf) {
107
- // Make 'in' and truthy checks like Boolean(set.constructor)
108
- // independent of any properties defined on Object.prototype.
109
- // Prevent prototype setters from intercepting set as a this value.
110
- setPrototypeOf(set, null);
111
- }
112
- let l = array.length;
113
- while (l--) {
114
- let element = array[l];
115
- if (typeof element === 'string') {
116
- const lcElement = transformCaseFunc(element);
117
- if (lcElement !== element) {
118
- // Config presets (e.g. tags.js, attrs.js) are immutable.
119
- if (!isFrozen(array)) {
120
- array[l] = lcElement;
121
- }
122
- element = lcElement;
123
- }
124
- }
125
- set[element] = true;
126
- }
127
- return set;
128
- }
129
- /**
130
- * Clean up an array to harden against CSPP
131
- *
132
- * @param array - The array to be cleaned.
133
- * @returns The cleaned version of the array
134
- */
135
- function cleanArray(array) {
136
- for (let index = 0; index < array.length; index++) {
137
- const isPropertyExist = objectHasOwnProperty(array, index);
138
- if (!isPropertyExist) {
139
- array[index] = null;
140
- }
141
- }
142
- return array;
143
- }
144
- /**
145
- * Shallow clone an object
146
- *
147
- * @param object - The object to be cloned.
148
- * @returns A new object that copies the original.
149
- */
150
- function clone(object) {
151
- const newObject = create(null);
152
- for (const [property, value] of entries(object)) {
153
- const isPropertyExist = objectHasOwnProperty(object, property);
154
- if (isPropertyExist) {
155
- if (Array.isArray(value)) {
156
- newObject[property] = cleanArray(value);
157
- } else if (value && typeof value === 'object' && value.constructor === Object) {
158
- newObject[property] = clone(value);
159
- } else {
160
- newObject[property] = value;
161
- }
162
- }
163
- }
164
- return newObject;
165
- }
166
- /**
167
- * This method automatically checks if the prop is function or getter and behaves accordingly.
168
- *
169
- * @param object - The object to look up the getter function in its prototype chain.
170
- * @param prop - The property name for which to find the getter function.
171
- * @returns The getter function found in the prototype chain or a fallback function.
172
- */
173
- function lookupGetter(object, prop) {
174
- while (object !== null) {
175
- const desc = getOwnPropertyDescriptor(object, prop);
176
- if (desc) {
177
- if (desc.get) {
178
- return unapply(desc.get);
179
- }
180
- if (typeof desc.value === 'function') {
181
- return unapply(desc.value);
182
- }
183
- }
184
- object = getPrototypeOf(object);
185
- }
186
- function fallbackValue() {
187
- return null;
188
- }
189
- return fallbackValue;
190
- }
191
-
192
- const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
193
- const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
194
- const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
195
- // List of SVG elements that are disallowed by default.
196
- // We still need to know them so that we can do namespace
197
- // checks properly in case one wants to add them to
198
- // allow-list.
199
- const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
200
- const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
201
- // Similarly to SVG, we want to know all MathML elements,
202
- // even those that we disallow by default.
203
- const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
204
- const text = freeze(['#text']);
205
-
206
- const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
207
- const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
208
- const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
209
- const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
210
-
211
- // eslint-disable-next-line unicorn/better-regex
212
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
213
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
214
- const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
215
- const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
216
- const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
217
- const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
218
- );
219
- const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
220
- const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
221
- );
222
- const DOCTYPE_NAME = seal(/^html$/i);
223
- const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
224
-
225
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
226
- __proto__: null,
227
- ARIA_ATTR: ARIA_ATTR,
228
- ATTR_WHITESPACE: ATTR_WHITESPACE,
229
- CUSTOM_ELEMENT: CUSTOM_ELEMENT,
230
- DATA_ATTR: DATA_ATTR,
231
- DOCTYPE_NAME: DOCTYPE_NAME,
232
- ERB_EXPR: ERB_EXPR,
233
- IS_ALLOWED_URI: IS_ALLOWED_URI,
234
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
235
- MUSTACHE_EXPR: MUSTACHE_EXPR,
236
- TMPLIT_EXPR: TMPLIT_EXPR
237
- });
238
-
239
- /* eslint-disable @typescript-eslint/indent */
240
- // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
241
- const NODE_TYPE = {
242
- element: 1,
243
- attribute: 2,
244
- text: 3,
245
- cdataSection: 4,
246
- entityReference: 5,
247
- // Deprecated
248
- entityNode: 6,
249
- // Deprecated
250
- progressingInstruction: 7,
251
- comment: 8,
252
- document: 9,
253
- documentType: 10,
254
- documentFragment: 11,
255
- notation: 12 // Deprecated
256
- };
257
- const getGlobal = function getGlobal() {
258
- return typeof window === 'undefined' ? null : window;
259
- };
260
- /**
261
- * Creates a no-op policy for internal use only.
262
- * Don't export this function outside this module!
263
- * @param trustedTypes The policy factory.
264
- * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
265
- * @return The policy created (or null, if Trusted Types
266
- * are not supported or creating the policy failed).
267
- */
268
- const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
269
- if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
270
- return null;
271
- }
272
- // Allow the callers to control the unique policy name
273
- // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
274
- // Policy creation with duplicate names throws in Trusted Types.
275
- let suffix = null;
276
- const ATTR_NAME = 'data-tt-policy-suffix';
277
- if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
278
- suffix = purifyHostElement.getAttribute(ATTR_NAME);
279
- }
280
- const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
281
- try {
282
- return trustedTypes.createPolicy(policyName, {
283
- createHTML(html) {
284
- return html;
285
- },
286
- createScriptURL(scriptUrl) {
287
- return scriptUrl;
288
- }
289
- });
290
- } catch (_) {
291
- // Policy creation failed (most likely another DOMPurify script has
292
- // already run). Skip creating the policy, as this will only cause errors
293
- // if TT are enforced.
294
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
295
- return null;
296
- }
297
- };
298
- const _createHooksMap = function _createHooksMap() {
299
- return {
300
- afterSanitizeAttributes: [],
301
- afterSanitizeElements: [],
302
- afterSanitizeShadowDOM: [],
303
- beforeSanitizeAttributes: [],
304
- beforeSanitizeElements: [],
305
- beforeSanitizeShadowDOM: [],
306
- uponSanitizeAttribute: [],
307
- uponSanitizeElement: [],
308
- uponSanitizeShadowNode: []
309
- };
310
- };
311
- function createDOMPurify() {
312
- let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
313
- const DOMPurify = root => createDOMPurify(root);
314
- DOMPurify.version = '3.3.1';
315
- DOMPurify.removed = [];
316
- if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
317
- // Not running in a browser, provide a factory function
318
- // so that you can pass your own Window
319
- DOMPurify.isSupported = false;
320
- return DOMPurify;
321
- }
322
- let {
323
- document
324
- } = window;
325
- const originalDocument = document;
326
- const currentScript = originalDocument.currentScript;
327
- const {
328
- DocumentFragment,
329
- HTMLTemplateElement,
330
- Node,
331
- Element,
332
- NodeFilter,
333
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
334
- HTMLFormElement,
335
- DOMParser,
336
- trustedTypes
337
- } = window;
338
- const ElementPrototype = Element.prototype;
339
- const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
340
- const remove = lookupGetter(ElementPrototype, 'remove');
341
- const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
342
- const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
343
- const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
344
- // As per issue #47, the web-components registry is inherited by a
345
- // new document created via createHTMLDocument. As per the spec
346
- // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
347
- // a new empty registry is used when creating a template contents owner
348
- // document, so we use that as our parent document to ensure nothing
349
- // is inherited.
350
- if (typeof HTMLTemplateElement === 'function') {
351
- const template = document.createElement('template');
352
- if (template.content && template.content.ownerDocument) {
353
- document = template.content.ownerDocument;
354
- }
355
- }
356
- let trustedTypesPolicy;
357
- let emptyHTML = '';
358
- const {
359
- implementation,
360
- createNodeIterator,
361
- createDocumentFragment,
362
- getElementsByTagName
363
- } = document;
364
- const {
365
- importNode
366
- } = originalDocument;
367
- let hooks = _createHooksMap();
368
- /**
369
- * Expose whether this browser supports running the full DOMPurify.
370
- */
371
- DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
372
- const {
373
- MUSTACHE_EXPR,
374
- ERB_EXPR,
375
- TMPLIT_EXPR,
376
- DATA_ATTR,
377
- ARIA_ATTR,
378
- IS_SCRIPT_OR_DATA,
379
- ATTR_WHITESPACE,
380
- CUSTOM_ELEMENT
381
- } = EXPRESSIONS;
382
- let {
383
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
384
- } = EXPRESSIONS;
385
- /**
386
- * We consider the elements and attributes below to be safe. Ideally
387
- * don't add any new ones but feel free to remove unwanted ones.
388
- */
389
- /* allowed element names */
390
- let ALLOWED_TAGS = null;
391
- const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
392
- /* Allowed attribute names */
393
- let ALLOWED_ATTR = null;
394
- const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
395
- /*
396
- * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
397
- * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
398
- * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
399
- * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
400
- */
401
- let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
402
- tagNameCheck: {
403
- writable: true,
404
- configurable: false,
405
- enumerable: true,
406
- value: null
407
- },
408
- attributeNameCheck: {
409
- writable: true,
410
- configurable: false,
411
- enumerable: true,
412
- value: null
413
- },
414
- allowCustomizedBuiltInElements: {
415
- writable: true,
416
- configurable: false,
417
- enumerable: true,
418
- value: false
419
- }
420
- }));
421
- /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
422
- let FORBID_TAGS = null;
423
- /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
424
- let FORBID_ATTR = null;
425
- /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
426
- const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
427
- tagCheck: {
428
- writable: true,
429
- configurable: false,
430
- enumerable: true,
431
- value: null
432
- },
433
- attributeCheck: {
434
- writable: true,
435
- configurable: false,
436
- enumerable: true,
437
- value: null
438
- }
439
- }));
440
- /* Decide if ARIA attributes are okay */
441
- let ALLOW_ARIA_ATTR = true;
442
- /* Decide if custom data attributes are okay */
443
- let ALLOW_DATA_ATTR = true;
444
- /* Decide if unknown protocols are okay */
445
- let ALLOW_UNKNOWN_PROTOCOLS = false;
446
- /* Decide if self-closing tags in attributes are allowed.
447
- * Usually removed due to a mXSS issue in jQuery 3.0 */
448
- let ALLOW_SELF_CLOSE_IN_ATTR = true;
449
- /* Output should be safe for common template engines.
450
- * This means, DOMPurify removes data attributes, mustaches and ERB
451
- */
452
- let SAFE_FOR_TEMPLATES = false;
453
- /* Output should be safe even for XML used within HTML and alike.
454
- * This means, DOMPurify removes comments when containing risky content.
455
- */
456
- let SAFE_FOR_XML = true;
457
- /* Decide if document with <html>... should be returned */
458
- let WHOLE_DOCUMENT = false;
459
- /* Track whether config is already set on this instance of DOMPurify. */
460
- let SET_CONFIG = false;
461
- /* Decide if all elements (e.g. style, script) must be children of
462
- * document.body. By default, browsers might move them to document.head */
463
- let FORCE_BODY = false;
464
- /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
465
- * string (or a TrustedHTML object if Trusted Types are supported).
466
- * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
467
- */
468
- let RETURN_DOM = false;
469
- /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
470
- * string (or a TrustedHTML object if Trusted Types are supported) */
471
- let RETURN_DOM_FRAGMENT = false;
472
- /* Try to return a Trusted Type object instead of a string, return a string in
473
- * case Trusted Types are not supported */
474
- let RETURN_TRUSTED_TYPE = false;
475
- /* Output should be free from DOM clobbering attacks?
476
- * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
477
- */
478
- let SANITIZE_DOM = true;
479
- /* Achieve full DOM Clobbering protection by isolating the namespace of named
480
- * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
481
- *
482
- * HTML/DOM spec rules that enable DOM Clobbering:
483
- * - Named Access on Window (§7.3.3)
484
- * - DOM Tree Accessors (§3.1.5)
485
- * - Form Element Parent-Child Relations (§4.10.3)
486
- * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
487
- * - HTMLCollection (§4.2.10.2)
488
- *
489
- * Namespace isolation is implemented by prefixing `id` and `name` attributes
490
- * with a constant string, i.e., `user-content-`
491
- */
492
- let SANITIZE_NAMED_PROPS = false;
493
- const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
494
- /* Keep element content when removing element? */
495
- let KEEP_CONTENT = true;
496
- /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
497
- * of importing it into a new Document and returning a sanitized copy */
498
- let IN_PLACE = false;
499
- /* Allow usage of profiles like html, svg and mathMl */
500
- let USE_PROFILES = {};
501
- /* Tags to ignore content of when KEEP_CONTENT is true */
502
- let FORBID_CONTENTS = null;
503
- const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
504
- /* Tags that are safe for data: URIs */
505
- let DATA_URI_TAGS = null;
506
- const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
507
- /* Attributes safe for values like "javascript:" */
508
- let URI_SAFE_ATTRIBUTES = null;
509
- const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
510
- const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
511
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
512
- const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
513
- /* Document namespace */
514
- let NAMESPACE = HTML_NAMESPACE;
515
- let IS_EMPTY_INPUT = false;
516
- /* Allowed XHTML+XML namespaces */
517
- let ALLOWED_NAMESPACES = null;
518
- const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
519
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
520
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
521
- // Certain elements are allowed in both SVG and HTML
522
- // namespace. We need to specify them explicitly
523
- // so that they don't get erroneously deleted from
524
- // HTML namespace.
525
- const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
526
- /* Parsing of strict XHTML documents */
527
- let PARSER_MEDIA_TYPE = null;
528
- const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
529
- const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
530
- let transformCaseFunc = null;
531
- /* Keep a reference to config to pass to hooks */
532
- let CONFIG = null;
533
- /* Ideally, do not touch anything below this line */
534
- /* ______________________________________________ */
535
- const formElement = document.createElement('form');
536
- const isRegexOrFunction = function isRegexOrFunction(testValue) {
537
- return testValue instanceof RegExp || testValue instanceof Function;
538
- };
539
- /**
540
- * _parseConfig
541
- *
542
- * @param cfg optional config literal
543
- */
544
- // eslint-disable-next-line complexity
545
- const _parseConfig = function _parseConfig() {
546
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
547
- if (CONFIG && CONFIG === cfg) {
548
- return;
549
- }
550
- /* Shield configuration object from tampering */
551
- if (!cfg || typeof cfg !== 'object') {
552
- cfg = {};
553
- }
554
- /* Shield configuration object from prototype pollution */
555
- cfg = clone(cfg);
556
- PARSER_MEDIA_TYPE =
557
- // eslint-disable-next-line unicorn/prefer-includes
558
- SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
559
- // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
560
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
561
- /* Set configuration parameters */
562
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
563
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
564
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
565
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
566
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
567
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
568
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
569
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
570
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
571
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
572
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
573
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
574
- ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
575
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
576
- SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
577
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
578
- RETURN_DOM = cfg.RETURN_DOM || false; // Default false
579
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
580
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
581
- FORCE_BODY = cfg.FORCE_BODY || false; // Default false
582
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
583
- SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
584
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
585
- IN_PLACE = cfg.IN_PLACE || false; // Default false
586
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
587
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
588
- MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
589
- HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
590
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
591
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
592
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
593
- }
594
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
595
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
596
- }
597
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
598
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
599
- }
600
- if (SAFE_FOR_TEMPLATES) {
601
- ALLOW_DATA_ATTR = false;
602
- }
603
- if (RETURN_DOM_FRAGMENT) {
604
- RETURN_DOM = true;
605
- }
606
- /* Parse profile info */
607
- if (USE_PROFILES) {
608
- ALLOWED_TAGS = addToSet({}, text);
609
- ALLOWED_ATTR = [];
610
- if (USE_PROFILES.html === true) {
611
- addToSet(ALLOWED_TAGS, html$1);
612
- addToSet(ALLOWED_ATTR, html);
613
- }
614
- if (USE_PROFILES.svg === true) {
615
- addToSet(ALLOWED_TAGS, svg$1);
616
- addToSet(ALLOWED_ATTR, svg);
617
- addToSet(ALLOWED_ATTR, xml);
618
- }
619
- if (USE_PROFILES.svgFilters === true) {
620
- addToSet(ALLOWED_TAGS, svgFilters);
621
- addToSet(ALLOWED_ATTR, svg);
622
- addToSet(ALLOWED_ATTR, xml);
623
- }
624
- if (USE_PROFILES.mathMl === true) {
625
- addToSet(ALLOWED_TAGS, mathMl$1);
626
- addToSet(ALLOWED_ATTR, mathMl);
627
- addToSet(ALLOWED_ATTR, xml);
628
- }
629
- }
630
- /* Merge configuration parameters */
631
- if (cfg.ADD_TAGS) {
632
- if (typeof cfg.ADD_TAGS === 'function') {
633
- EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
634
- } else {
635
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
636
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
637
- }
638
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
639
- }
640
- }
641
- if (cfg.ADD_ATTR) {
642
- if (typeof cfg.ADD_ATTR === 'function') {
643
- EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
644
- } else {
645
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
646
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
647
- }
648
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
649
- }
650
- }
651
- if (cfg.ADD_URI_SAFE_ATTR) {
652
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
653
- }
654
- if (cfg.FORBID_CONTENTS) {
655
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
656
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
657
- }
658
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
659
- }
660
- if (cfg.ADD_FORBID_CONTENTS) {
661
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
662
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
663
- }
664
- addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
665
- }
666
- /* Add #text in case KEEP_CONTENT is set to true */
667
- if (KEEP_CONTENT) {
668
- ALLOWED_TAGS['#text'] = true;
669
- }
670
- /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
671
- if (WHOLE_DOCUMENT) {
672
- addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
673
- }
674
- /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
675
- if (ALLOWED_TAGS.table) {
676
- addToSet(ALLOWED_TAGS, ['tbody']);
677
- delete FORBID_TAGS.tbody;
678
- }
679
- if (cfg.TRUSTED_TYPES_POLICY) {
680
- if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
681
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
682
- }
683
- if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
684
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
685
- }
686
- // Overwrite existing TrustedTypes policy.
687
- trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
688
- // Sign local variables required by `sanitize`.
689
- emptyHTML = trustedTypesPolicy.createHTML('');
690
- } else {
691
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
692
- if (trustedTypesPolicy === undefined) {
693
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
694
- }
695
- // If creating the internal policy succeeded sign internal variables.
696
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
697
- emptyHTML = trustedTypesPolicy.createHTML('');
698
- }
699
- }
700
- // Prevent further manipulation of configuration.
701
- // Not available in IE8, Safari 5, etc.
702
- if (freeze) {
703
- freeze(cfg);
704
- }
705
- CONFIG = cfg;
706
- };
707
- /* Keep track of all possible SVG and MathML tags
708
- * so that we can perform the namespace checks
709
- * correctly. */
710
- const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
711
- const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
712
- /**
713
- * @param element a DOM element whose namespace is being checked
714
- * @returns Return false if the element has a
715
- * namespace that a spec-compliant parser would never
716
- * return. Return true otherwise.
717
- */
718
- const _checkValidNamespace = function _checkValidNamespace(element) {
719
- let parent = getParentNode(element);
720
- // In JSDOM, if we're inside shadow DOM, then parentNode
721
- // can be null. We just simulate parent in this case.
722
- if (!parent || !parent.tagName) {
723
- parent = {
724
- namespaceURI: NAMESPACE,
725
- tagName: 'template'
726
- };
727
- }
728
- const tagName = stringToLowerCase(element.tagName);
729
- const parentTagName = stringToLowerCase(parent.tagName);
730
- if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
731
- return false;
732
- }
733
- if (element.namespaceURI === SVG_NAMESPACE) {
734
- // The only way to switch from HTML namespace to SVG
735
- // is via <svg>. If it happens via any other tag, then
736
- // it should be killed.
737
- if (parent.namespaceURI === HTML_NAMESPACE) {
738
- return tagName === 'svg';
739
- }
740
- // The only way to switch from MathML to SVG is via`
741
- // svg if parent is either <annotation-xml> or MathML
742
- // text integration points.
743
- if (parent.namespaceURI === MATHML_NAMESPACE) {
744
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
745
- }
746
- // We only allow elements that are defined in SVG
747
- // spec. All others are disallowed in SVG namespace.
748
- return Boolean(ALL_SVG_TAGS[tagName]);
749
- }
750
- if (element.namespaceURI === MATHML_NAMESPACE) {
751
- // The only way to switch from HTML namespace to MathML
752
- // is via <math>. If it happens via any other tag, then
753
- // it should be killed.
754
- if (parent.namespaceURI === HTML_NAMESPACE) {
755
- return tagName === 'math';
756
- }
757
- // The only way to switch from SVG to MathML is via
758
- // <math> and HTML integration points
759
- if (parent.namespaceURI === SVG_NAMESPACE) {
760
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
761
- }
762
- // We only allow elements that are defined in MathML
763
- // spec. All others are disallowed in MathML namespace.
764
- return Boolean(ALL_MATHML_TAGS[tagName]);
765
- }
766
- if (element.namespaceURI === HTML_NAMESPACE) {
767
- // The only way to switch from SVG to HTML is via
768
- // HTML integration points, and from MathML to HTML
769
- // is via MathML text integration points
770
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
771
- return false;
772
- }
773
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
774
- return false;
775
- }
776
- // We disallow tags that are specific for MathML
777
- // or SVG and should never appear in HTML namespace
778
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
779
- }
780
- // For XHTML and XML documents that support custom namespaces
781
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
782
- return true;
783
- }
784
- // The code should never reach this place (this means
785
- // that the element somehow got namespace that is not
786
- // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
787
- // Return false just in case.
788
- return false;
789
- };
790
- /**
791
- * _forceRemove
792
- *
793
- * @param node a DOM node
794
- */
795
- const _forceRemove = function _forceRemove(node) {
796
- arrayPush(DOMPurify.removed, {
797
- element: node
798
- });
799
- try {
800
- // eslint-disable-next-line unicorn/prefer-dom-node-remove
801
- getParentNode(node).removeChild(node);
802
- } catch (_) {
803
- remove(node);
804
- }
805
- };
806
- /**
807
- * _removeAttribute
808
- *
809
- * @param name an Attribute name
810
- * @param element a DOM node
811
- */
812
- const _removeAttribute = function _removeAttribute(name, element) {
813
- try {
814
- arrayPush(DOMPurify.removed, {
815
- attribute: element.getAttributeNode(name),
816
- from: element
817
- });
818
- } catch (_) {
819
- arrayPush(DOMPurify.removed, {
820
- attribute: null,
821
- from: element
822
- });
823
- }
824
- element.removeAttribute(name);
825
- // We void attribute values for unremovable "is" attributes
826
- if (name === 'is') {
827
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
828
- try {
829
- _forceRemove(element);
830
- } catch (_) {}
831
- } else {
832
- try {
833
- element.setAttribute(name, '');
834
- } catch (_) {}
835
- }
836
- }
837
- };
838
- /**
839
- * _initDocument
840
- *
841
- * @param dirty - a string of dirty markup
842
- * @return a DOM, filled with the dirty markup
843
- */
844
- const _initDocument = function _initDocument(dirty) {
845
- /* Create a HTML document */
846
- let doc = null;
847
- let leadingWhitespace = null;
848
- if (FORCE_BODY) {
849
- dirty = '<remove></remove>' + dirty;
850
- } else {
851
- /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
852
- const matches = stringMatch(dirty, /^[\r\n\t ]+/);
853
- leadingWhitespace = matches && matches[0];
854
- }
855
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
856
- // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
857
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
858
- }
859
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
860
- /*
861
- * Use the DOMParser API by default, fallback later if needs be
862
- * DOMParser not work for svg when has multiple root element.
863
- */
864
- if (NAMESPACE === HTML_NAMESPACE) {
865
- try {
866
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
867
- } catch (_) {}
868
- }
869
- /* Use createHTMLDocument in case DOMParser is not available */
870
- if (!doc || !doc.documentElement) {
871
- doc = implementation.createDocument(NAMESPACE, 'template', null);
872
- try {
873
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
874
- } catch (_) {
875
- // Syntax error if dirtyPayload is invalid xml
876
- }
877
- }
878
- const body = doc.body || doc.documentElement;
879
- if (dirty && leadingWhitespace) {
880
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
881
- }
882
- /* Work on whole document or just its body */
883
- if (NAMESPACE === HTML_NAMESPACE) {
884
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
885
- }
886
- return WHOLE_DOCUMENT ? doc.documentElement : body;
887
- };
888
- /**
889
- * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
890
- *
891
- * @param root The root element or node to start traversing on.
892
- * @return The created NodeIterator
893
- */
894
- const _createNodeIterator = function _createNodeIterator(root) {
895
- return createNodeIterator.call(root.ownerDocument || root, root,
896
- // eslint-disable-next-line no-bitwise
897
- NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
898
- };
899
- /**
900
- * _isClobbered
901
- *
902
- * @param element element to check for clobbering attacks
903
- * @return true if clobbered, false if safe
904
- */
905
- const _isClobbered = function _isClobbered(element) {
906
- return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
907
- };
908
- /**
909
- * Checks whether the given object is a DOM node.
910
- *
911
- * @param value object to check whether it's a DOM node
912
- * @return true is object is a DOM node
913
- */
914
- const _isNode = function _isNode(value) {
915
- return typeof Node === 'function' && value instanceof Node;
916
- };
917
- function _executeHooks(hooks, currentNode, data) {
918
- arrayForEach(hooks, hook => {
919
- hook.call(DOMPurify, currentNode, data, CONFIG);
920
- });
921
- }
922
- /**
923
- * _sanitizeElements
924
- *
925
- * @protect nodeName
926
- * @protect textContent
927
- * @protect removeChild
928
- * @param currentNode to check for permission to exist
929
- * @return true if node was killed, false if left alive
930
- */
931
- const _sanitizeElements = function _sanitizeElements(currentNode) {
932
- let content = null;
933
- /* Execute a hook if present */
934
- _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
935
- /* Check if element is clobbered or can clobber */
936
- if (_isClobbered(currentNode)) {
937
- _forceRemove(currentNode);
938
- return true;
939
- }
940
- /* Now let's check the element's type and name */
941
- const tagName = transformCaseFunc(currentNode.nodeName);
942
- /* Execute a hook if present */
943
- _executeHooks(hooks.uponSanitizeElement, currentNode, {
944
- tagName,
945
- allowedTags: ALLOWED_TAGS
946
- });
947
- /* Detect mXSS attempts abusing namespace confusion */
948
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
949
- _forceRemove(currentNode);
950
- return true;
951
- }
952
- /* Remove any occurrence of processing instructions */
953
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
954
- _forceRemove(currentNode);
955
- return true;
956
- }
957
- /* Remove any kind of possibly harmful comments */
958
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
959
- _forceRemove(currentNode);
960
- return true;
961
- }
962
- /* Remove element if anything forbids its presence */
963
- if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
964
- /* Check if we have a custom element to handle */
965
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
966
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
967
- return false;
968
- }
969
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
970
- return false;
971
- }
972
- }
973
- /* Keep content except for bad-listed elements */
974
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
975
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
976
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
977
- if (childNodes && parentNode) {
978
- const childCount = childNodes.length;
979
- for (let i = childCount - 1; i >= 0; --i) {
980
- const childClone = cloneNode(childNodes[i], true);
981
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
982
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
983
- }
984
- }
985
- }
986
- _forceRemove(currentNode);
987
- return true;
988
- }
989
- /* Check whether element has a valid namespace */
990
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
991
- _forceRemove(currentNode);
992
- return true;
993
- }
994
- /* Make sure that older browsers don't get fallback-tag mXSS */
995
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
996
- _forceRemove(currentNode);
997
- return true;
998
- }
999
- /* Sanitize element content to be template-safe */
1000
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1001
- /* Get the element's text content */
1002
- content = currentNode.textContent;
1003
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1004
- content = stringReplace(content, expr, ' ');
1005
- });
1006
- if (currentNode.textContent !== content) {
1007
- arrayPush(DOMPurify.removed, {
1008
- element: currentNode.cloneNode()
1009
- });
1010
- currentNode.textContent = content;
1011
- }
1012
- }
1013
- /* Execute a hook if present */
1014
- _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1015
- return false;
1016
- };
1017
- /**
1018
- * _isValidAttribute
1019
- *
1020
- * @param lcTag Lowercase tag name of containing element.
1021
- * @param lcName Lowercase attribute name.
1022
- * @param value Attribute value.
1023
- * @return Returns true if `value` is valid, otherwise false.
1024
- */
1025
- // eslint-disable-next-line complexity
1026
- const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1027
- /* Make sure attribute cannot clobber */
1028
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1029
- return false;
1030
- }
1031
- /* Allow valid data-* attributes: At least one character after "-"
1032
- (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1033
- XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1034
- We don't need to check the value; it's always URI safe. */
1035
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1036
- if (
1037
- // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1038
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1039
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1040
- _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||
1041
- // Alternative, second condition checks if it's an `is`-attribute, AND
1042
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1043
- lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1044
- return false;
1045
- }
1046
- /* Check value is safe. First, is attr inert? If so, is safe */
1047
- } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1048
- return false;
1049
- } else ;
1050
- return true;
1051
- };
1052
- /**
1053
- * _isBasicCustomElement
1054
- * checks if at least one dash is included in tagName, and it's not the first char
1055
- * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1056
- *
1057
- * @param tagName name of the tag of the node to sanitize
1058
- * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1059
- */
1060
- const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1061
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1062
- };
1063
- /**
1064
- * _sanitizeAttributes
1065
- *
1066
- * @protect attributes
1067
- * @protect nodeName
1068
- * @protect removeAttribute
1069
- * @protect setAttribute
1070
- *
1071
- * @param currentNode to sanitize
1072
- */
1073
- const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1074
- /* Execute a hook if present */
1075
- _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1076
- const {
1077
- attributes
1078
- } = currentNode;
1079
- /* Check if we have attributes; if not we might have a text node */
1080
- if (!attributes || _isClobbered(currentNode)) {
1081
- return;
1082
- }
1083
- const hookEvent = {
1084
- attrName: '',
1085
- attrValue: '',
1086
- keepAttr: true,
1087
- allowedAttributes: ALLOWED_ATTR,
1088
- forceKeepAttr: undefined
1089
- };
1090
- let l = attributes.length;
1091
- /* Go backwards over all attributes; safely remove bad ones */
1092
- while (l--) {
1093
- const attr = attributes[l];
1094
- const {
1095
- name,
1096
- namespaceURI,
1097
- value: attrValue
1098
- } = attr;
1099
- const lcName = transformCaseFunc(name);
1100
- const initValue = attrValue;
1101
- let value = name === 'value' ? initValue : stringTrim(initValue);
1102
- /* Execute a hook if present */
1103
- hookEvent.attrName = lcName;
1104
- hookEvent.attrValue = value;
1105
- hookEvent.keepAttr = true;
1106
- hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1107
- _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1108
- value = hookEvent.attrValue;
1109
- /* Full DOM Clobbering protection via namespace isolation,
1110
- * Prefix id and name attributes with `user-content-`
1111
- */
1112
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1113
- // Remove the attribute with this value
1114
- _removeAttribute(name, currentNode);
1115
- // Prefix the value and later re-create the attribute with the sanitized value
1116
- value = SANITIZE_NAMED_PROPS_PREFIX + value;
1117
- }
1118
- /* Work around a security issue with comments inside attributes */
1119
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
1120
- _removeAttribute(name, currentNode);
1121
- continue;
1122
- }
1123
- /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
1124
- if (lcName === 'attributename' && stringMatch(value, 'href')) {
1125
- _removeAttribute(name, currentNode);
1126
- continue;
1127
- }
1128
- /* Did the hooks approve of the attribute? */
1129
- if (hookEvent.forceKeepAttr) {
1130
- continue;
1131
- }
1132
- /* Did the hooks approve of the attribute? */
1133
- if (!hookEvent.keepAttr) {
1134
- _removeAttribute(name, currentNode);
1135
- continue;
1136
- }
1137
- /* Work around a security issue in jQuery 3.0 */
1138
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1139
- _removeAttribute(name, currentNode);
1140
- continue;
1141
- }
1142
- /* Sanitize attribute content to be template-safe */
1143
- if (SAFE_FOR_TEMPLATES) {
1144
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1145
- value = stringReplace(value, expr, ' ');
1146
- });
1147
- }
1148
- /* Is `value` valid for this attribute? */
1149
- const lcTag = transformCaseFunc(currentNode.nodeName);
1150
- if (!_isValidAttribute(lcTag, lcName, value)) {
1151
- _removeAttribute(name, currentNode);
1152
- continue;
1153
- }
1154
- /* Handle attributes that require Trusted Types */
1155
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1156
- if (namespaceURI) ; else {
1157
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1158
- case 'TrustedHTML':
1159
- {
1160
- value = trustedTypesPolicy.createHTML(value);
1161
- break;
1162
- }
1163
- case 'TrustedScriptURL':
1164
- {
1165
- value = trustedTypesPolicy.createScriptURL(value);
1166
- break;
1167
- }
1168
- }
1169
- }
1170
- }
1171
- /* Handle invalid data-* attribute set by try-catching it */
1172
- if (value !== initValue) {
1173
- try {
1174
- if (namespaceURI) {
1175
- currentNode.setAttributeNS(namespaceURI, name, value);
1176
- } else {
1177
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1178
- currentNode.setAttribute(name, value);
1179
- }
1180
- if (_isClobbered(currentNode)) {
1181
- _forceRemove(currentNode);
1182
- } else {
1183
- arrayPop(DOMPurify.removed);
1184
- }
1185
- } catch (_) {
1186
- _removeAttribute(name, currentNode);
1187
- }
1188
- }
1189
- }
1190
- /* Execute a hook if present */
1191
- _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1192
- };
1193
- /**
1194
- * _sanitizeShadowDOM
1195
- *
1196
- * @param fragment to iterate over recursively
1197
- */
1198
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1199
- let shadowNode = null;
1200
- const shadowIterator = _createNodeIterator(fragment);
1201
- /* Execute a hook if present */
1202
- _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1203
- while (shadowNode = shadowIterator.nextNode()) {
1204
- /* Execute a hook if present */
1205
- _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1206
- /* Sanitize tags and elements */
1207
- _sanitizeElements(shadowNode);
1208
- /* Check attributes next */
1209
- _sanitizeAttributes(shadowNode);
1210
- /* Deep shadow DOM detected */
1211
- if (shadowNode.content instanceof DocumentFragment) {
1212
- _sanitizeShadowDOM(shadowNode.content);
1213
- }
1214
- }
1215
- /* Execute a hook if present */
1216
- _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1217
- };
1218
- // eslint-disable-next-line complexity
1219
- DOMPurify.sanitize = function (dirty) {
1220
- let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1221
- let body = null;
1222
- let importedNode = null;
1223
- let currentNode = null;
1224
- let returnNode = null;
1225
- /* Make sure we have a string to sanitize.
1226
- DO NOT return early, as this will return the wrong type if
1227
- the user has requested a DOM object rather than a string */
1228
- IS_EMPTY_INPUT = !dirty;
1229
- if (IS_EMPTY_INPUT) {
1230
- dirty = '<!-->';
1231
- }
1232
- /* Stringify, in case dirty is an object */
1233
- if (typeof dirty !== 'string' && !_isNode(dirty)) {
1234
- if (typeof dirty.toString === 'function') {
1235
- dirty = dirty.toString();
1236
- if (typeof dirty !== 'string') {
1237
- throw typeErrorCreate('dirty is not a string, aborting');
1238
- }
1239
- } else {
1240
- throw typeErrorCreate('toString is not a function');
1241
- }
1242
- }
1243
- /* Return dirty HTML if DOMPurify cannot run */
1244
- if (!DOMPurify.isSupported) {
1245
- return dirty;
1246
- }
1247
- /* Assign config vars */
1248
- if (!SET_CONFIG) {
1249
- _parseConfig(cfg);
1250
- }
1251
- /* Clean up removed elements */
1252
- DOMPurify.removed = [];
1253
- /* Check if dirty is correctly typed for IN_PLACE */
1254
- if (typeof dirty === 'string') {
1255
- IN_PLACE = false;
1256
- }
1257
- if (IN_PLACE) {
1258
- /* Do some early pre-sanitization to avoid unsafe root nodes */
1259
- if (dirty.nodeName) {
1260
- const tagName = transformCaseFunc(dirty.nodeName);
1261
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1262
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1263
- }
1264
- }
1265
- } else if (dirty instanceof Node) {
1266
- /* If dirty is a DOM element, append to an empty document to avoid
1267
- elements being stripped by the parser */
1268
- body = _initDocument('<!---->');
1269
- importedNode = body.ownerDocument.importNode(dirty, true);
1270
- if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
1271
- /* Node is already a body, use as is */
1272
- body = importedNode;
1273
- } else if (importedNode.nodeName === 'HTML') {
1274
- body = importedNode;
1275
- } else {
1276
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1277
- body.appendChild(importedNode);
1278
- }
1279
- } else {
1280
- /* Exit directly if we have nothing to do */
1281
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1282
- // eslint-disable-next-line unicorn/prefer-includes
1283
- dirty.indexOf('<') === -1) {
1284
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1285
- }
1286
- /* Initialize the document to work on */
1287
- body = _initDocument(dirty);
1288
- /* Check we have a DOM node from the data */
1289
- if (!body) {
1290
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1291
- }
1292
- }
1293
- /* Remove first element node (ours) if FORCE_BODY is set */
1294
- if (body && FORCE_BODY) {
1295
- _forceRemove(body.firstChild);
1296
- }
1297
- /* Get node iterator */
1298
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1299
- /* Now start iterating over the created document */
1300
- while (currentNode = nodeIterator.nextNode()) {
1301
- /* Sanitize tags and elements */
1302
- _sanitizeElements(currentNode);
1303
- /* Check attributes next */
1304
- _sanitizeAttributes(currentNode);
1305
- /* Shadow DOM detected, sanitize it */
1306
- if (currentNode.content instanceof DocumentFragment) {
1307
- _sanitizeShadowDOM(currentNode.content);
1308
- }
1309
- }
1310
- /* If we sanitized `dirty` in-place, return it. */
1311
- if (IN_PLACE) {
1312
- return dirty;
1313
- }
1314
- /* Return sanitized string or DOM */
1315
- if (RETURN_DOM) {
1316
- if (RETURN_DOM_FRAGMENT) {
1317
- returnNode = createDocumentFragment.call(body.ownerDocument);
1318
- while (body.firstChild) {
1319
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1320
- returnNode.appendChild(body.firstChild);
1321
- }
1322
- } else {
1323
- returnNode = body;
1324
- }
1325
- if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1326
- /*
1327
- AdoptNode() is not used because internal state is not reset
1328
- (e.g. the past names map of a HTMLFormElement), this is safe
1329
- in theory but we would rather not risk another attack vector.
1330
- The state that is cloned by importNode() is explicitly defined
1331
- by the specs.
1332
- */
1333
- returnNode = importNode.call(originalDocument, returnNode, true);
1334
- }
1335
- return returnNode;
1336
- }
1337
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1338
- /* Serialize doctype if allowed */
1339
- if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1340
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1341
- }
1342
- /* Sanitize final string template-safe */
1343
- if (SAFE_FOR_TEMPLATES) {
1344
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1345
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
1346
- });
1347
- }
1348
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1349
- };
1350
- DOMPurify.setConfig = function () {
1351
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1352
- _parseConfig(cfg);
1353
- SET_CONFIG = true;
1354
- };
1355
- DOMPurify.clearConfig = function () {
1356
- CONFIG = null;
1357
- SET_CONFIG = false;
1358
- };
1359
- DOMPurify.isValidAttribute = function (tag, attr, value) {
1360
- /* Initialize shared config vars if necessary. */
1361
- if (!CONFIG) {
1362
- _parseConfig({});
1363
- }
1364
- const lcTag = transformCaseFunc(tag);
1365
- const lcName = transformCaseFunc(attr);
1366
- return _isValidAttribute(lcTag, lcName, value);
1367
- };
1368
- DOMPurify.addHook = function (entryPoint, hookFunction) {
1369
- if (typeof hookFunction !== 'function') {
1370
- return;
1371
- }
1372
- arrayPush(hooks[entryPoint], hookFunction);
1373
- };
1374
- DOMPurify.removeHook = function (entryPoint, hookFunction) {
1375
- if (hookFunction !== undefined) {
1376
- const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1377
- return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
1378
- }
1379
- return arrayPop(hooks[entryPoint]);
1380
- };
1381
- DOMPurify.removeHooks = function (entryPoint) {
1382
- hooks[entryPoint] = [];
1383
- };
1384
- DOMPurify.removeAllHooks = function () {
1385
- hooks = _createHooksMap();
1386
- };
1387
- return DOMPurify;
1388
- }
1389
- var purify = createDOMPurify();
1390
-
1391
- return purify;
1392
-
1393
- }));
1394
- //# sourceMappingURL=purify.js.map
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/dompurify/dist/purify.js.map DELETED
The diff for this file is too large to render. See raw diff
 
ui/node_modules/dompurify/dist/purify.min.js DELETED
@@ -1,3 +0,0 @@
1
- /*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
2
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DOMPurify=t()}(this,(function(){"use strict";const{entries:e,setPrototypeOf:t,isFrozen:n,getPrototypeOf:o,getOwnPropertyDescriptor:r}=Object;let{freeze:i,seal:a,create:l}=Object,{apply:c,construct:s}="undefined"!=typeof Reflect&&Reflect;i||(i=function(e){return e}),a||(a=function(e){return e}),c||(c=function(e,t){for(var n=arguments.length,o=new Array(n>2?n-2:0),r=2;r<n;r++)o[r-2]=arguments[r];return e.apply(t,o)}),s||(s=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return new e(...n)});const u=D(Array.prototype.forEach),m=D(Array.prototype.lastIndexOf),p=D(Array.prototype.pop),f=D(Array.prototype.push),d=D(Array.prototype.splice),h=D(String.prototype.toLowerCase),g=D(String.prototype.toString),T=D(String.prototype.match),y=D(String.prototype.replace),E=D(String.prototype.indexOf),A=D(String.prototype.trim),_=D(Object.prototype.hasOwnProperty),b=D(RegExp.prototype.test),S=(N=TypeError,function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return s(N,t)});var N;function D(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return c(e,t,o)}}function R(e,o){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:h;t&&t(e,null);let i=o.length;for(;i--;){let t=o[i];if("string"==typeof t){const e=r(t);e!==t&&(n(o)||(o[i]=e),t=e)}e[t]=!0}return e}function w(e){for(let t=0;t<e.length;t++){_(e,t)||(e[t]=null)}return e}function C(t){const n=l(null);for(const[o,r]of e(t)){_(t,o)&&(Array.isArray(r)?n[o]=w(r):r&&"object"==typeof r&&r.constructor===Object?n[o]=C(r):n[o]=r)}return n}function O(e,t){for(;null!==e;){const n=r(e,t);if(n){if(n.get)return D(n.get);if("function"==typeof n.value)return D(n.value)}e=o(e)}return function(){return null}}const v=i(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),x=i(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),L=i(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),k=i(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),I=i(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),M=i(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),U=i(["#text"]),z=i(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),P=i(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),F=i(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),H=i(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),B=a(/\{\{[\w\W]*|[\w\W]*\}\}/gm),G=a(/<%[\w\W]*|[\w\W]*%>/gm),W=a(/\$\{[\w\W]*/gm),Y=a(/^data-[\-\w.\u00B7-\uFFFF]+$/),j=a(/^aria-[\-\w]+$/),X=a(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),q=a(/^(?:\w+script|data):/i),$=a(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),K=a(/^html$/i),V=a(/^[a-z][.\w]*(-[.\w]+)+$/i);var Z=Object.freeze({__proto__:null,ARIA_ATTR:j,ATTR_WHITESPACE:$,CUSTOM_ELEMENT:V,DATA_ATTR:Y,DOCTYPE_NAME:K,ERB_EXPR:G,IS_ALLOWED_URI:X,IS_SCRIPT_OR_DATA:q,MUSTACHE_EXPR:B,TMPLIT_EXPR:W});const J=1,Q=3,ee=7,te=8,ne=9,oe=function(){return"undefined"==typeof window?null:window};var re=function t(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:oe();const o=e=>t(e);if(o.version="3.3.1",o.removed=[],!n||!n.document||n.document.nodeType!==ne||!n.Element)return o.isSupported=!1,o;let{document:r}=n;const a=r,c=a.currentScript,{DocumentFragment:s,HTMLTemplateElement:N,Node:D,Element:w,NodeFilter:B,NamedNodeMap:G=n.NamedNodeMap||n.MozNamedAttrMap,HTMLFormElement:W,DOMParser:Y,trustedTypes:j}=n,q=w.prototype,$=O(q,"cloneNode"),V=O(q,"remove"),re=O(q,"nextSibling"),ie=O(q,"childNodes"),ae=O(q,"parentNode");if("function"==typeof N){const e=r.createElement("template");e.content&&e.content.ownerDocument&&(r=e.content.ownerDocument)}let le,ce="";const{implementation:se,createNodeIterator:ue,createDocumentFragment:me,getElementsByTagName:pe}=r,{importNode:fe}=a;let de={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};o.isSupported="function"==typeof e&&"function"==typeof ae&&se&&void 0!==se.createHTMLDocument;const{MUSTACHE_EXPR:he,ERB_EXPR:ge,TMPLIT_EXPR:Te,DATA_ATTR:ye,ARIA_ATTR:Ee,IS_SCRIPT_OR_DATA:Ae,ATTR_WHITESPACE:_e,CUSTOM_ELEMENT:be}=Z;let{IS_ALLOWED_URI:Se}=Z,Ne=null;const De=R({},[...v,...x,...L,...I,...U]);let Re=null;const we=R({},[...z,...P,...F,...H]);let Ce=Object.seal(l(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Oe=null,ve=null;const xe=Object.seal(l(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let Le=!0,ke=!0,Ie=!1,Me=!0,Ue=!1,ze=!0,Pe=!1,Fe=!1,He=!1,Be=!1,Ge=!1,We=!1,Ye=!0,je=!1,Xe=!0,qe=!1,$e={},Ke=null;const Ve=R({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Ze=null;const Je=R({},["audio","video","img","source","image","track"]);let Qe=null;const et=R({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),tt="http://www.w3.org/1998/Math/MathML",nt="http://www.w3.org/2000/svg",ot="http://www.w3.org/1999/xhtml";let rt=ot,it=!1,at=null;const lt=R({},[tt,nt,ot],g);let ct=R({},["mi","mo","mn","ms","mtext"]),st=R({},["annotation-xml"]);const ut=R({},["title","style","font","a","script"]);let mt=null;const pt=["application/xhtml+xml","text/html"];let ft=null,dt=null;const ht=r.createElement("form"),gt=function(e){return e instanceof RegExp||e instanceof Function},Tt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!dt||dt!==e){if(e&&"object"==typeof e||(e={}),e=C(e),mt=-1===pt.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,ft="application/xhtml+xml"===mt?g:h,Ne=_(e,"ALLOWED_TAGS")?R({},e.ALLOWED_TAGS,ft):De,Re=_(e,"ALLOWED_ATTR")?R({},e.ALLOWED_ATTR,ft):we,at=_(e,"ALLOWED_NAMESPACES")?R({},e.ALLOWED_NAMESPACES,g):lt,Qe=_(e,"ADD_URI_SAFE_ATTR")?R(C(et),e.ADD_URI_SAFE_ATTR,ft):et,Ze=_(e,"ADD_DATA_URI_TAGS")?R(C(Je),e.ADD_DATA_URI_TAGS,ft):Je,Ke=_(e,"FORBID_CONTENTS")?R({},e.FORBID_CONTENTS,ft):Ve,Oe=_(e,"FORBID_TAGS")?R({},e.FORBID_TAGS,ft):C({}),ve=_(e,"FORBID_ATTR")?R({},e.FORBID_ATTR,ft):C({}),$e=!!_(e,"USE_PROFILES")&&e.USE_PROFILES,Le=!1!==e.ALLOW_ARIA_ATTR,ke=!1!==e.ALLOW_DATA_ATTR,Ie=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Me=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,Ue=e.SAFE_FOR_TEMPLATES||!1,ze=!1!==e.SAFE_FOR_XML,Pe=e.WHOLE_DOCUMENT||!1,Be=e.RETURN_DOM||!1,Ge=e.RETURN_DOM_FRAGMENT||!1,We=e.RETURN_TRUSTED_TYPE||!1,He=e.FORCE_BODY||!1,Ye=!1!==e.SANITIZE_DOM,je=e.SANITIZE_NAMED_PROPS||!1,Xe=!1!==e.KEEP_CONTENT,qe=e.IN_PLACE||!1,Se=e.ALLOWED_URI_REGEXP||X,rt=e.NAMESPACE||ot,ct=e.MATHML_TEXT_INTEGRATION_POINTS||ct,st=e.HTML_INTEGRATION_POINTS||st,Ce=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&gt(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Ce.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&gt(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Ce.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(Ce.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),Ue&&(ke=!1),Ge&&(Be=!0),$e&&(Ne=R({},U),Re=[],!0===$e.html&&(R(Ne,v),R(Re,z)),!0===$e.svg&&(R(Ne,x),R(Re,P),R(Re,H)),!0===$e.svgFilters&&(R(Ne,L),R(Re,P),R(Re,H)),!0===$e.mathMl&&(R(Ne,I),R(Re,F),R(Re,H))),e.ADD_TAGS&&("function"==typeof e.ADD_TAGS?xe.tagCheck=e.ADD_TAGS:(Ne===De&&(Ne=C(Ne)),R(Ne,e.ADD_TAGS,ft))),e.ADD_ATTR&&("function"==typeof e.ADD_ATTR?xe.attributeCheck=e.ADD_ATTR:(Re===we&&(Re=C(Re)),R(Re,e.ADD_ATTR,ft))),e.ADD_URI_SAFE_ATTR&&R(Qe,e.ADD_URI_SAFE_ATTR,ft),e.FORBID_CONTENTS&&(Ke===Ve&&(Ke=C(Ke)),R(Ke,e.FORBID_CONTENTS,ft)),e.ADD_FORBID_CONTENTS&&(Ke===Ve&&(Ke=C(Ke)),R(Ke,e.ADD_FORBID_CONTENTS,ft)),Xe&&(Ne["#text"]=!0),Pe&&R(Ne,["html","head","body"]),Ne.table&&(R(Ne,["tbody"]),delete Oe.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw S('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw S('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');le=e.TRUSTED_TYPES_POLICY,ce=le.createHTML("")}else void 0===le&&(le=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;const o="data-tt-policy-suffix";t&&t.hasAttribute(o)&&(n=t.getAttribute(o));const r="dompurify"+(n?"#"+n:"");try{return e.createPolicy(r,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+r+" could not be created."),null}}(j,c)),null!==le&&"string"==typeof ce&&(ce=le.createHTML(""));i&&i(e),dt=e}},yt=R({},[...x,...L,...k]),Et=R({},[...I,...M]),At=function(e){f(o.removed,{element:e});try{ae(e).removeChild(e)}catch(t){V(e)}},_t=function(e,t){try{f(o.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){f(o.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e)if(Be||Ge)try{At(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},bt=function(e){let t=null,n=null;if(He)e="<remove></remove>"+e;else{const t=T(e,/^[\r\n\t ]+/);n=t&&t[0]}"application/xhtml+xml"===mt&&rt===ot&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const o=le?le.createHTML(e):e;if(rt===ot)try{t=(new Y).parseFromString(o,mt)}catch(e){}if(!t||!t.documentElement){t=se.createDocument(rt,"template",null);try{t.documentElement.innerHTML=it?ce:o}catch(e){}}const i=t.body||t.documentElement;return e&&n&&i.insertBefore(r.createTextNode(n),i.childNodes[0]||null),rt===ot?pe.call(t,Pe?"html":"body")[0]:Pe?t.documentElement:i},St=function(e){return ue.call(e.ownerDocument||e,e,B.SHOW_ELEMENT|B.SHOW_COMMENT|B.SHOW_TEXT|B.SHOW_PROCESSING_INSTRUCTION|B.SHOW_CDATA_SECTION,null)},Nt=function(e){return e instanceof W&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof G)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},Dt=function(e){return"function"==typeof D&&e instanceof D};function Rt(e,t,n){u(e,(e=>{e.call(o,t,n,dt)}))}const wt=function(e){let t=null;if(Rt(de.beforeSanitizeElements,e,null),Nt(e))return At(e),!0;const n=ft(e.nodeName);if(Rt(de.uponSanitizeElement,e,{tagName:n,allowedTags:Ne}),ze&&e.hasChildNodes()&&!Dt(e.firstElementChild)&&b(/<[/\w!]/g,e.innerHTML)&&b(/<[/\w!]/g,e.textContent))return At(e),!0;if(e.nodeType===ee)return At(e),!0;if(ze&&e.nodeType===te&&b(/<[/\w]/g,e.data))return At(e),!0;if(!(xe.tagCheck instanceof Function&&xe.tagCheck(n))&&(!Ne[n]||Oe[n])){if(!Oe[n]&&Ot(n)){if(Ce.tagNameCheck instanceof RegExp&&b(Ce.tagNameCheck,n))return!1;if(Ce.tagNameCheck instanceof Function&&Ce.tagNameCheck(n))return!1}if(Xe&&!Ke[n]){const t=ae(e)||e.parentNode,n=ie(e)||e.childNodes;if(n&&t){for(let o=n.length-1;o>=0;--o){const r=$(n[o],!0);r.__removalCount=(e.__removalCount||0)+1,t.insertBefore(r,re(e))}}}return At(e),!0}return e instanceof w&&!function(e){let t=ae(e);t&&t.tagName||(t={namespaceURI:rt,tagName:"template"});const n=h(e.tagName),o=h(t.tagName);return!!at[e.namespaceURI]&&(e.namespaceURI===nt?t.namespaceURI===ot?"svg"===n:t.namespaceURI===tt?"svg"===n&&("annotation-xml"===o||ct[o]):Boolean(yt[n]):e.namespaceURI===tt?t.namespaceURI===ot?"math"===n:t.namespaceURI===nt?"math"===n&&st[o]:Boolean(Et[n]):e.namespaceURI===ot?!(t.namespaceURI===nt&&!st[o])&&!(t.namespaceURI===tt&&!ct[o])&&!Et[n]&&(ut[n]||!yt[n]):!("application/xhtml+xml"!==mt||!at[e.namespaceURI]))}(e)?(At(e),!0):"noscript"!==n&&"noembed"!==n&&"noframes"!==n||!b(/<\/no(script|embed|frames)/i,e.innerHTML)?(Ue&&e.nodeType===Q&&(t=e.textContent,u([he,ge,Te],(e=>{t=y(t,e," ")})),e.textContent!==t&&(f(o.removed,{element:e.cloneNode()}),e.textContent=t)),Rt(de.afterSanitizeElements,e,null),!1):(At(e),!0)},Ct=function(e,t,n){if(Ye&&("id"===t||"name"===t)&&(n in r||n in ht))return!1;if(ke&&!ve[t]&&b(ye,t));else if(Le&&b(Ee,t));else if(xe.attributeCheck instanceof Function&&xe.attributeCheck(t,e));else if(!Re[t]||ve[t]){if(!(Ot(e)&&(Ce.tagNameCheck instanceof RegExp&&b(Ce.tagNameCheck,e)||Ce.tagNameCheck instanceof Function&&Ce.tagNameCheck(e))&&(Ce.attributeNameCheck instanceof RegExp&&b(Ce.attributeNameCheck,t)||Ce.attributeNameCheck instanceof Function&&Ce.attributeNameCheck(t,e))||"is"===t&&Ce.allowCustomizedBuiltInElements&&(Ce.tagNameCheck instanceof RegExp&&b(Ce.tagNameCheck,n)||Ce.tagNameCheck instanceof Function&&Ce.tagNameCheck(n))))return!1}else if(Qe[t]);else if(b(Se,y(n,_e,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==E(n,"data:")||!Ze[e]){if(Ie&&!b(Ae,y(n,_e,"")));else if(n)return!1}else;return!0},Ot=function(e){return"annotation-xml"!==e&&T(e,be)},vt=function(e){Rt(de.beforeSanitizeAttributes,e,null);const{attributes:t}=e;if(!t||Nt(e))return;const n={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Re,forceKeepAttr:void 0};let r=t.length;for(;r--;){const i=t[r],{name:a,namespaceURI:l,value:c}=i,s=ft(a),m=c;let f="value"===a?m:A(m);if(n.attrName=s,n.attrValue=f,n.keepAttr=!0,n.forceKeepAttr=void 0,Rt(de.uponSanitizeAttribute,e,n),f=n.attrValue,!je||"id"!==s&&"name"!==s||(_t(a,e),f="user-content-"+f),ze&&b(/((--!?|])>)|<\/(style|title|textarea)/i,f)){_t(a,e);continue}if("attributename"===s&&T(f,"href")){_t(a,e);continue}if(n.forceKeepAttr)continue;if(!n.keepAttr){_t(a,e);continue}if(!Me&&b(/\/>/i,f)){_t(a,e);continue}Ue&&u([he,ge,Te],(e=>{f=y(f,e," ")}));const d=ft(e.nodeName);if(Ct(d,s,f)){if(le&&"object"==typeof j&&"function"==typeof j.getAttributeType)if(l);else switch(j.getAttributeType(d,s)){case"TrustedHTML":f=le.createHTML(f);break;case"TrustedScriptURL":f=le.createScriptURL(f)}if(f!==m)try{l?e.setAttributeNS(l,a,f):e.setAttribute(a,f),Nt(e)?At(e):p(o.removed)}catch(t){_t(a,e)}}else _t(a,e)}Rt(de.afterSanitizeAttributes,e,null)},xt=function e(t){let n=null;const o=St(t);for(Rt(de.beforeSanitizeShadowDOM,t,null);n=o.nextNode();)Rt(de.uponSanitizeShadowNode,n,null),wt(n),vt(n),n.content instanceof s&&e(n.content);Rt(de.afterSanitizeShadowDOM,t,null)};return o.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null,r=null,i=null,l=null;if(it=!e,it&&(e="\x3c!--\x3e"),"string"!=typeof e&&!Dt(e)){if("function"!=typeof e.toString)throw S("toString is not a function");if("string"!=typeof(e=e.toString()))throw S("dirty is not a string, aborting")}if(!o.isSupported)return e;if(Fe||Tt(t),o.removed=[],"string"==typeof e&&(qe=!1),qe){if(e.nodeName){const t=ft(e.nodeName);if(!Ne[t]||Oe[t])throw S("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof D)n=bt("\x3c!----\x3e"),r=n.ownerDocument.importNode(e,!0),r.nodeType===J&&"BODY"===r.nodeName||"HTML"===r.nodeName?n=r:n.appendChild(r);else{if(!Be&&!Ue&&!Pe&&-1===e.indexOf("<"))return le&&We?le.createHTML(e):e;if(n=bt(e),!n)return Be?null:We?ce:""}n&&He&&At(n.firstChild);const c=St(qe?e:n);for(;i=c.nextNode();)wt(i),vt(i),i.content instanceof s&&xt(i.content);if(qe)return e;if(Be){if(Ge)for(l=me.call(n.ownerDocument);n.firstChild;)l.appendChild(n.firstChild);else l=n;return(Re.shadowroot||Re.shadowrootmode)&&(l=fe.call(a,l,!0)),l}let m=Pe?n.outerHTML:n.innerHTML;return Pe&&Ne["!doctype"]&&n.ownerDocument&&n.ownerDocument.doctype&&n.ownerDocument.doctype.name&&b(K,n.ownerDocument.doctype.name)&&(m="<!DOCTYPE "+n.ownerDocument.doctype.name+">\n"+m),Ue&&u([he,ge,Te],(e=>{m=y(m,e," ")})),le&&We?le.createHTML(m):m},o.setConfig=function(){Tt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),Fe=!0},o.clearConfig=function(){dt=null,Fe=!1},o.isValidAttribute=function(e,t,n){dt||Tt({});const o=ft(e),r=ft(t);return Ct(o,r,n)},o.addHook=function(e,t){"function"==typeof t&&f(de[e],t)},o.removeHook=function(e,t){if(void 0!==t){const n=m(de[e],t);return-1===n?void 0:d(de[e],n,1)[0]}return p(de[e])},o.removeHooks=function(e){de[e]=[]},o.removeAllHooks=function(){de={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},o}();return re}));
3
- //# sourceMappingURL=purify.min.js.map
 
 
 
 
ui/node_modules/dompurify/dist/purify.min.js.map DELETED
The diff for this file is too large to render. See raw diff
 
ui/node_modules/dompurify/package.json DELETED
@@ -1,171 +0,0 @@
1
- {
2
- "scripts": {
3
- "lint": "xo src/*.ts",
4
- "format": "npm run format:js && npm run format:md",
5
- "format:md": "prettier --write --parser markdown '**/*.md'",
6
- "format:js": "prettier --write '{src,demos,scripts,test,website}/*.{js,ts}'",
7
- "commit-amend-build": "scripts/commit-amend-build.sh",
8
- "prebuild": "rimraf dist/**",
9
- "dev": "cross-env NODE_ENV=development BABEL_ENV=rollup rollup -w -c -o dist/purify.js",
10
- "build": "run-s build:types build:rollup build:fix-types build:cleanup",
11
- "build:types": "tsc --outDir dist/types --declaration --emitDeclarationOnly",
12
- "build:rollup": "rollup -c",
13
- "build:fix-types": "node ./scripts/fix-types.js",
14
- "build:umd": "rollup -c -f umd -o dist/purify.js",
15
- "build:umd:min": "rollup -c -f umd -o dist/purify.min.js -p terser",
16
- "build:es": "rollup -c -f es -o dist/purify.es.mjs",
17
- "build:cjs": "rollup -c -f cjs -o dist/purify.cjs.js",
18
- "build:cleanup": "rimraf dist/types",
19
- "test:jsdom": "cross-env NODE_ENV=test BABEL_ENV=rollup node test/jsdom-node-runner --dot",
20
- "test:karma": "cross-env NODE_ENV=test BABEL_ENV=rollup karma start test/karma.conf.js --log-level warn ",
21
- "test:ci": "cross-env NODE_ENV=test BABEL_ENV=rollup npm run test:jsdom && npm run test:karma -- --log-level error --reporters dots --single-run --shouldTestOnBrowserStack=\"${TEST_BROWSERSTACK}\" --shouldProbeOnly=\"${TEST_PROBE_ONLY}\"",
22
- "test": "cross-env NODE_ENV=test BABEL_ENV=rollup npm run lint && npm run test:jsdom && npm run test:karma -- --browsers Chrome",
23
- "verify-typescript": "node ./typescript/verify.js"
24
- },
25
- "main": "./dist/purify.cjs.js",
26
- "module": "./dist/purify.es.mjs",
27
- "browser": "./dist/purify.js",
28
- "production": "./dist/purify.min.js",
29
- "types": "./dist/purify.cjs.d.ts",
30
- "exports": {
31
- ".": {
32
- "import": {
33
- "types": "./dist/purify.es.d.mts",
34
- "default": "./dist/purify.es.mjs"
35
- },
36
- "default": {
37
- "types": "./dist/purify.cjs.d.ts",
38
- "default": "./dist/purify.cjs.js"
39
- }
40
- },
41
- "./purify.min.js": "./dist/purify.min.js",
42
- "./purify.js": "./dist/purify.js",
43
- "./dist/purify.min.js": "./dist/purify.min.js",
44
- "./dist/purify.js": "./dist/purify.js"
45
- },
46
- "files": [
47
- "dist"
48
- ],
49
- "pre-commit": [
50
- "lint",
51
- "build",
52
- "commit-amend-build"
53
- ],
54
- "xo": {
55
- "semicolon": true,
56
- "space": 2,
57
- "extends": [
58
- "prettier"
59
- ],
60
- "plugins": [
61
- "prettier"
62
- ],
63
- "rules": {
64
- "import/no-useless-path-segments": 0,
65
- "unicorn/prefer-optional-catch-binding": 0,
66
- "unicorn/prefer-node-remove": 0,
67
- "prettier/prettier": [
68
- "error",
69
- {
70
- "trailingComma": "es5",
71
- "singleQuote": true
72
- }
73
- ],
74
- "camelcase": [
75
- "error",
76
- {
77
- "properties": "never"
78
- }
79
- ],
80
- "@typescript-eslint/ban-types": 0,
81
- "@typescript-eslint/consistent-type-definitions": 0,
82
- "@typescript-eslint/indent": 0,
83
- "@typescript-eslint/naming-convention": 0,
84
- "@typescript-eslint/no-throw-literal": 0,
85
- "@typescript-eslint/no-unnecessary-boolean-literal-compare": 0,
86
- "@typescript-eslint/no-unsafe-argument": 0,
87
- "@typescript-eslint/no-unsafe-assignment": 0,
88
- "@typescript-eslint/no-unsafe-call": 0,
89
- "@typescript-eslint/no-unsafe-return": 0,
90
- "@typescript-eslint/prefer-includes": 0,
91
- "@typescript-eslint/prefer-optional-chain": 0,
92
- "@typescript-eslint/prefer-nullish-coalescing": 0,
93
- "@typescript-eslint/restrict-plus-operands": 0
94
- },
95
- "globals": [
96
- "window",
97
- "VERSION"
98
- ]
99
- },
100
- "optionalDependencies": {
101
- "@types/trusted-types": "^2.0.7"
102
- },
103
- "devDependencies": {
104
- "@babel/core": "^7.17.8",
105
- "@babel/preset-env": "^7.16.11",
106
- "@rollup/plugin-babel": "^6.0.4",
107
- "@rollup/plugin-node-resolve": "^15.3.0",
108
- "@rollup/plugin-replace": "^6.0.1",
109
- "@rollup/plugin-terser": "^0.4.4",
110
- "@types/estree": "^1.0.0",
111
- "@types/node": "^16.18.120",
112
- "cross-env": "^7.0.3",
113
- "eslint-config-prettier": "^8.5.0",
114
- "eslint-plugin-prettier": "^4.0.0",
115
- "jquery": "^3.6.0",
116
- "jsdom": "^20.0.0",
117
- "karma": "^6.3.17",
118
- "karma-browserstack-launcher": "^1.5.1",
119
- "karma-chrome-launcher": "^3.1.0",
120
- "karma-firefox-launcher": "^2.1.2",
121
- "karma-qunit": "^4.1.2",
122
- "karma-rollup-preprocessor": "^7.0.8",
123
- "lodash.sample": "^4.2.1",
124
- "minimist": "^1.2.6",
125
- "npm-run-all": "^4.1.5",
126
- "pre-commit": "^1.2.2",
127
- "prettier": "^2.5.1",
128
- "qunit": "^2.4.1",
129
- "qunit-tap": "^1.5.0",
130
- "rimraf": "^3.0.2",
131
- "rollup": "^3.29.5",
132
- "rollup-plugin-dts": "^6.1.1",
133
- "rollup-plugin-includepaths": "^0.2.4",
134
- "rollup-plugin-typescript2": "^0.36.0",
135
- "tslib": "^2.7.0",
136
- "typescript": "^5.6.3",
137
- "xo": "^0.54.1"
138
- },
139
- "resolutions": {
140
- "natives": "1.1.6"
141
- },
142
- "name": "dompurify",
143
- "description": "DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. It's written in JavaScript and works in all modern browsers (Safari, Opera (15+), Internet Explorer (10+), Firefox and Chrome - as well as almost anything else using Blink or WebKit). DOMPurify is written by security people who have vast background in web attacks and XSS. Fear not.",
144
- "version": "3.3.1",
145
- "directories": {
146
- "test": "test"
147
- },
148
- "repository": {
149
- "type": "git",
150
- "url": "git://github.com/cure53/DOMPurify.git"
151
- },
152
- "keywords": [
153
- "dom",
154
- "xss",
155
- "html",
156
- "svg",
157
- "mathml",
158
- "security",
159
- "secure",
160
- "sanitizer",
161
- "sanitize",
162
- "filter",
163
- "purify"
164
- ],
165
- "author": "Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)",
166
- "license": "(MPL-2.0 OR Apache-2.0)",
167
- "bugs": {
168
- "url": "https://github.com/cure53/DOMPurify/issues"
169
- },
170
- "homepage": "https://github.com/cure53/DOMPurify"
171
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/lit/LICENSE DELETED
@@ -1,28 +0,0 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2017 Google LLC. All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- 3. Neither the name of the copyright holder nor the names of its
16
- contributors may be used to endorse or promote products derived from
17
- this software without specific prior written permission.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/lit/README.md DELETED
@@ -1,71 +0,0 @@
1
- <div align="center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="./logo-dark.svg" alt="Lit" width="300" height="141">
4
- </source>
5
- <source media="(prefers-color-scheme: light)" srcset="./logo.svg" alt="Lit" width="300" height="141">
6
- </source>
7
- <img src="./logo.svg" alt="Lit" width="300" height="141">
8
- </picture>
9
-
10
- ### Simple. Fast. Web Components.
11
-
12
- [![Build Status](https://github.com/lit/lit/actions/workflows/tests.yml/badge.svg)](https://github.com/lit/lit/actions/workflows/tests.yml)
13
- [![Published on npm](https://img.shields.io/npm/v/lit.svg?logo=npm)](https://www.npmjs.com/package/lit)
14
- [![Join our Discord](https://img.shields.io/badge/discord-join%20chat-5865F2.svg?logo=discord&logoColor=fff)](https://lit.dev/discord/)
15
- [![Mentioned in Awesome Lit](https://awesome.re/mentioned-badge.svg)](https://github.com/web-padawan/awesome-lit)
16
-
17
- </div>
18
-
19
- Lit is a simple library for building fast, lightweight web components.
20
-
21
- At Lit's core is a boilerplate-killing component base class that provides reactive state, scoped styles, and a declarative template system that's tiny, fast and expressive.
22
-
23
- ## Documentation
24
-
25
- See the full documentation for Lit at [lit.dev](https://lit.dev)
26
-
27
- ## Overview
28
-
29
- Lit provides developers with just the right tools to build fast web components:
30
-
31
- - A fast declarative HTML template system
32
- - Reactive property declarations
33
- - A customizable reactive update lifecycle
34
- - Easy to use scoped CSS styling
35
-
36
- Lit builds on top of standard web components, and makes them easier to write:
37
-
38
- ```ts
39
- import {LitElement, html, css} from 'lit';
40
- import {customElement, property} from 'lit/decorators.js';
41
-
42
- // Registers the element
43
- @customElement('my-element')
44
- export class MyElement extends LitElement {
45
- // Styles are applied to the shadow root and scoped to this element
46
- static styles = css`
47
- span {
48
- color: green;
49
- }
50
- `;
51
-
52
- // Creates a reactive property that triggers rendering
53
- @property()
54
- mood = 'great';
55
-
56
- // Render the component's DOM by returning a Lit template
57
- render() {
58
- return html`Web Components are <span>${this.mood}</span>!`;
59
- }
60
- }
61
- ```
62
-
63
- Once you've defined your component, you can use it anywhere you use HTML:
64
-
65
- ```html
66
- <my-element mood="awesome"></my-element>
67
- ```
68
-
69
- ## Contributing
70
-
71
- Please see [CONTRIBUTING.md](../../CONTRIBUTING.md).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/node_modules/lit/async-directive.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2021 Google LLC
4
- * SPDX-License-Identifier: BSD-3-Clause
5
- */
6
- export * from 'lit-html/async-directive.js';
7
- //# sourceMappingURL=async-directive.d.ts.map
 
 
 
 
 
 
 
 
ui/node_modules/lit/async-directive.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-directive.d.ts","sourceRoot":"","sources":["../src/async-directive.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,6BAA6B,CAAC"}
 
 
ui/node_modules/lit/async-directive.js DELETED
@@ -1,2 +0,0 @@
1
- export*from"lit-html/async-directive.js";
2
- //# sourceMappingURL=async-directive.js.map
 
 
 
ui/node_modules/lit/async-directive.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-directive.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}