@prosopo/procaptcha-bundle 3.3.0 → 4.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +28 -35
  2. package/.turbo/turbo-build$colon$tsc.log +33 -36
  3. package/.turbo/turbo-build.log +29 -36
  4. package/CHANGELOG.md +481 -0
  5. package/dist/cjs/index.cjs +4 -9
  6. package/dist/cjs/util/captcha/captchaRenderer.cjs +10 -9
  7. package/dist/cjs/util/captcha/components/{frictionlessCaptcha.cjs → bundleCaptcha.cjs} +2 -2
  8. package/dist/cjs/util/config.cjs +14 -4
  9. package/dist/cjs/util/widgetFactory.cjs +4 -6
  10. package/dist/components.d.ts +1 -4
  11. package/dist/components.d.ts.map +1 -1
  12. package/dist/components.js +1 -4
  13. package/dist/components.js.map +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +4 -9
  16. package/dist/index.js.map +1 -1
  17. package/dist/tests/util/config.test.js +6 -6
  18. package/dist/tests/util/config.test.js.map +1 -1
  19. package/dist/tests/util/renderLogic.test.js +22 -14
  20. package/dist/tests/util/renderLogic.test.js.map +1 -1
  21. package/dist/util/captcha/captchaRenderer.d.ts +1 -6
  22. package/dist/util/captcha/captchaRenderer.d.ts.map +1 -1
  23. package/dist/util/captcha/captchaRenderer.js +10 -9
  24. package/dist/util/captcha/captchaRenderer.js.map +1 -1
  25. package/dist/util/captcha/{captchaProps.d.ts → components/bundleCaptcha.d.ts} +4 -3
  26. package/dist/util/captcha/components/bundleCaptcha.d.ts.map +1 -0
  27. package/dist/util/captcha/components/{frictionlessCaptcha.js → bundleCaptcha.js} +2 -2
  28. package/dist/util/captcha/components/bundleCaptcha.js.map +1 -0
  29. package/dist/util/config.d.ts +2 -2
  30. package/dist/util/config.d.ts.map +1 -1
  31. package/dist/util/config.js +14 -4
  32. package/dist/util/config.js.map +1 -1
  33. package/dist/util/widgetFactory.d.ts +1 -1
  34. package/dist/util/widgetFactory.d.ts.map +1 -1
  35. package/dist/util/widgetFactory.js +4 -6
  36. package/dist/util/widgetFactory.js.map +1 -1
  37. package/package.json +12 -12
  38. package/src/components.ts +15 -0
  39. package/src/index.html +11 -0
  40. package/src/index.ts +259 -0
  41. package/src/tests/procaptchaReady.unit.test.ts +58 -0
  42. package/src/tests/util/config.test.ts +97 -0
  43. package/src/tests/util/renderLogic.test.tsx +221 -0
  44. package/src/util/captcha/captchaRenderer.tsx +126 -0
  45. package/src/util/captcha/components/bundleCaptcha.tsx +57 -0
  46. package/src/util/config.ts +40 -0
  47. package/src/util/configCreator.ts +51 -0
  48. package/src/util/language.ts +53 -0
  49. package/src/util/timeout.ts +43 -0
  50. package/src/util/widgetFactory.ts +145 -0
  51. package/src/util/widgetThemeResolver.ts +40 -0
  52. package/tsconfig.cjs.json +35 -0
  53. package/tsconfig.json +42 -0
  54. package/tsconfig.tsbuildinfo +1 -0
  55. package/tsconfig.types.json +9 -0
  56. package/vite.config.ts +18 -1
  57. package/vite.iife.config.ts +119 -0
  58. package/vite.serve.config.ts +17 -0
  59. package/dist/cjs/util/captcha/captchaComponentProvider.cjs +0 -20
  60. package/dist/cjs/util/captcha/captchaComponentsList.cjs +0 -12
  61. package/dist/cjs/util/captcha/captchaType.cjs +0 -12
  62. package/dist/cjs/util/captcha/components/imageCaptcha.cjs +0 -17
  63. package/dist/cjs/util/captcha/components/powCaptcha.cjs +0 -17
  64. package/dist/tests/util/captchaType.test.d.ts +0 -2
  65. package/dist/tests/util/captchaType.test.d.ts.map +0 -1
  66. package/dist/tests/util/captchaType.test.js +0 -36
  67. package/dist/tests/util/captchaType.test.js.map +0 -1
  68. package/dist/util/captcha/captchaComponentProvider.d.ts +0 -8
  69. package/dist/util/captcha/captchaComponentProvider.d.ts.map +0 -1
  70. package/dist/util/captcha/captchaComponentProvider.js +0 -20
  71. package/dist/util/captcha/captchaComponentProvider.js.map +0 -1
  72. package/dist/util/captcha/captchaComponentsList.d.ts +0 -6
  73. package/dist/util/captcha/captchaComponentsList.d.ts.map +0 -1
  74. package/dist/util/captcha/captchaComponentsList.js +0 -12
  75. package/dist/util/captcha/captchaComponentsList.js.map +0 -1
  76. package/dist/util/captcha/captchaProps.d.ts.map +0 -1
  77. package/dist/util/captcha/captchaProps.js +0 -2
  78. package/dist/util/captcha/captchaProps.js.map +0 -1
  79. package/dist/util/captcha/captchaType.d.ts +0 -3
  80. package/dist/util/captcha/captchaType.d.ts.map +0 -1
  81. package/dist/util/captcha/captchaType.js +0 -12
  82. package/dist/util/captcha/captchaType.js.map +0 -1
  83. package/dist/util/captcha/components/frictionlessCaptcha.d.ts +0 -4
  84. package/dist/util/captcha/components/frictionlessCaptcha.d.ts.map +0 -1
  85. package/dist/util/captcha/components/frictionlessCaptcha.js.map +0 -1
  86. package/dist/util/captcha/components/imageCaptcha.d.ts +0 -4
  87. package/dist/util/captcha/components/imageCaptcha.d.ts.map +0 -1
  88. package/dist/util/captcha/components/imageCaptcha.js +0 -17
  89. package/dist/util/captcha/components/imageCaptcha.js.map +0 -1
  90. package/dist/util/captcha/components/powCaptcha.d.ts +0 -4
  91. package/dist/util/captcha/components/powCaptcha.d.ts.map +0 -1
  92. package/dist/util/captcha/components/powCaptcha.js +0 -17
  93. package/dist/util/captcha/components/powCaptcha.js.map +0 -1
@@ -0,0 +1,126 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import createCache, { type EmotionCache } from "@emotion/cache";
16
+ import { CacheProvider } from "@emotion/react";
17
+ import type { Ti18n } from "@prosopo/locale";
18
+ import type {
19
+ Callbacks,
20
+ ProcaptchaClientConfigOutput,
21
+ ProcaptchaRenderOptions,
22
+ } from "@prosopo/types";
23
+ import type { ReactNode } from "react";
24
+ import { type Root, createRoot } from "react-dom/client";
25
+ import { createConfig } from "../configCreator.js";
26
+ import { setLanguage } from "../language.js";
27
+ import { setValidChallengeLength } from "../timeout.js";
28
+ import { BundleCaptcha } from "./components/bundleCaptcha.js";
29
+
30
+ interface RenderSettings {
31
+ identifierPrefix: string;
32
+ emotionCacheKey: string;
33
+ webComponentTag: string;
34
+ }
35
+
36
+ class CaptchaRenderer {
37
+ public renderCaptcha(
38
+ settings: RenderSettings,
39
+ container: HTMLElement,
40
+ renderOptions: ProcaptchaRenderOptions,
41
+ callbacks: Callbacks,
42
+ isWeb2: boolean,
43
+ i18n: Ti18n,
44
+ invisible: boolean,
45
+ widgetContainer: HTMLElement,
46
+ sourceElement?: Element,
47
+ ): Root {
48
+ const config = createConfig(
49
+ renderOptions.siteKey,
50
+ renderOptions.theme,
51
+ renderOptions.language,
52
+ isWeb2,
53
+ invisible,
54
+ renderOptions.userAccountAddress,
55
+ );
56
+ this.readAndValidateSettings(
57
+ sourceElement || container,
58
+ config,
59
+ renderOptions,
60
+ );
61
+
62
+ const reactRoot = this.createReactRoot(
63
+ container,
64
+ settings.identifierPrefix,
65
+ );
66
+
67
+ const emotionCache = this.makeEmotionCache(
68
+ settings.emotionCacheKey,
69
+ container,
70
+ );
71
+
72
+ const captchaComponent = (
73
+ <BundleCaptcha
74
+ config={config}
75
+ callbacks={callbacks}
76
+ i18n={i18n}
77
+ container={widgetContainer}
78
+ />
79
+ );
80
+
81
+ this.renderCaptchaComponent(reactRoot, emotionCache, captchaComponent);
82
+
83
+ return reactRoot;
84
+ }
85
+
86
+ protected readAndValidateSettings(
87
+ element: Element,
88
+ config: ProcaptchaClientConfigOutput,
89
+ renderOptions: ProcaptchaRenderOptions,
90
+ ): void {
91
+ setValidChallengeLength(renderOptions, element, config);
92
+ setLanguage(renderOptions, element, config);
93
+ }
94
+
95
+ protected makeEmotionCache(
96
+ cacheKey: string,
97
+ container: HTMLElement,
98
+ ): EmotionCache {
99
+ return createCache({
100
+ key: cacheKey,
101
+ prepend: true,
102
+ container: container,
103
+ });
104
+ }
105
+
106
+ protected createReactRoot(
107
+ container: HTMLElement,
108
+ identifierPrefix: string,
109
+ ): Root {
110
+ return createRoot(container, {
111
+ identifierPrefix: identifierPrefix,
112
+ });
113
+ }
114
+
115
+ protected renderCaptchaComponent(
116
+ reactRoot: Root,
117
+ emotionCache: EmotionCache,
118
+ captchaComponent: ReactNode,
119
+ ): void {
120
+ reactRoot.render(
121
+ <CacheProvider value={emotionCache}>{captchaComponent}</CacheProvider>,
122
+ );
123
+ }
124
+ }
125
+
126
+ export { CaptchaRenderer };
@@ -0,0 +1,57 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import type { Ti18n } from "@prosopo/locale";
16
+ import { getDefaultEvents } from "@prosopo/procaptcha-common";
17
+ import { ProcaptchaFrictionless } from "@prosopo/procaptcha-frictionless";
18
+ import type {
19
+ ProcaptchaCallbacks,
20
+ ProcaptchaClientConfigInput,
21
+ } from "@prosopo/types";
22
+ import { useState } from "react";
23
+
24
+ interface BundleCaptchaProps {
25
+ config: ProcaptchaClientConfigInput;
26
+ callbacks: ProcaptchaCallbacks;
27
+ i18n: Ti18n;
28
+ container: HTMLElement;
29
+ }
30
+
31
+ // Universal captcha mount used by the script-tag bundle. Wraps
32
+ // ProcaptchaFrictionless with a `key`-driven restart hook so a "no session"
33
+ // error can fully unmount and remount the underlying widget. The server
34
+ // decides which concrete challenge type to render via the /frictionless
35
+ // endpoint — the wrapper itself is type-agnostic.
36
+ const BundleCaptcha = (props: BundleCaptchaProps) => {
37
+ const { config, callbacks, i18n, container } = props;
38
+
39
+ const [componentKey, setComponentKey] = useState(0);
40
+
41
+ const restart = () => {
42
+ setComponentKey((prevKey) => prevKey + 1);
43
+ };
44
+
45
+ return (
46
+ <ProcaptchaFrictionless
47
+ key={componentKey}
48
+ config={config}
49
+ callbacks={getDefaultEvents(callbacks)}
50
+ restart={restart}
51
+ i18n={i18n}
52
+ container={container}
53
+ />
54
+ );
55
+ };
56
+
57
+ export { BundleCaptcha };
@@ -0,0 +1,40 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ export const getProcaptchaScript = (
16
+ names: string[],
17
+ ): HTMLScriptElement | null => {
18
+ for (const name of names) {
19
+ const script = document.querySelector<HTMLScriptElement>(
20
+ `script[src*="${name}"]`,
21
+ );
22
+ if (script) {
23
+ return script;
24
+ }
25
+ }
26
+ return null;
27
+ };
28
+
29
+ export const extractParams = (names: string[]) => {
30
+ const script = getProcaptchaScript(names);
31
+ if (script) {
32
+ const params = new URLSearchParams(script.src.split("?")[1]);
33
+ return {
34
+ onloadUrlCallback: params.get("onload") || undefined,
35
+ renderExplicit: params.get("render") || undefined,
36
+ };
37
+ }
38
+
39
+ return { onloadUrlCallback: undefined, renderExplicit: undefined };
40
+ };
@@ -0,0 +1,51 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import type { Languages } from "@prosopo/locale";
16
+ import {
17
+ EnvironmentTypesSchema,
18
+ type ProcaptchaClientConfigOutput,
19
+ ProcaptchaConfigSchema,
20
+ } from "@prosopo/types";
21
+
22
+ function createConfig(
23
+ siteKey?: string,
24
+ theme: "light" | "dark" = "light",
25
+ language?: (typeof Languages)[keyof typeof Languages],
26
+ web2 = true,
27
+ invisible = false,
28
+ userAccountAddress?: string,
29
+ ): ProcaptchaClientConfigOutput {
30
+ if (!siteKey) {
31
+ siteKey = process.env.PROSOPO_SITE_KEY || "";
32
+ }
33
+
34
+ return ProcaptchaConfigSchema.parse({
35
+ defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT
36
+ ? EnvironmentTypesSchema.parse(process.env.PROSOPO_DEFAULT_ENVIRONMENT)
37
+ : EnvironmentTypesSchema.enum.development,
38
+ userAccountAddress: userAccountAddress || "",
39
+ account: {
40
+ address: siteKey,
41
+ },
42
+ serverUrl: process.env.PROSOPO_SERVER_URL || "",
43
+ mongoAtlasUri: process.env.PROSOPO_MONGO_EVENTS_URI || "",
44
+ web2,
45
+ mode: invisible ? "invisible" : "visible",
46
+ theme,
47
+ language,
48
+ });
49
+ }
50
+
51
+ export { createConfig };
@@ -0,0 +1,53 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import { LanguageSchema, type Languages } from "@prosopo/locale";
16
+ import type {
17
+ ProcaptchaClientConfigInput,
18
+ ProcaptchaRenderOptions,
19
+ } from "@prosopo/types";
20
+
21
+ /**
22
+ * Prioritizes language selection from:
23
+ * 1. renderOptions.language
24
+ * 2. element's data-language attribute
25
+ * 3. Defaults to 'en'
26
+ *
27
+ * Validates the language against currently supported languages
28
+ *
29
+ * @param renderOptions
30
+ * @param element
31
+ * @param config
32
+ */
33
+ export const setLanguage = (
34
+ renderOptions: ProcaptchaRenderOptions | undefined,
35
+ element: Element,
36
+ config: ProcaptchaClientConfigInput,
37
+ ) => {
38
+ const languageAttribute =
39
+ renderOptions?.language || element.getAttribute("data-language");
40
+
41
+ if (languageAttribute) {
42
+ config.language = validateLanguage(languageAttribute);
43
+ }
44
+ };
45
+
46
+ const validateLanguage = (languageAttribute: string | typeof Languages) => {
47
+ try {
48
+ return LanguageSchema.parse(languageAttribute);
49
+ } catch (error) {
50
+ console.error(`Invalid language attribute: ${languageAttribute}`);
51
+ return LanguageSchema.parse("en");
52
+ }
53
+ };
@@ -0,0 +1,43 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import type {
15
+ ProcaptchaClientConfigOutput,
16
+ ProcaptchaRenderOptions,
17
+ } from "@prosopo/types";
18
+
19
+ /**
20
+ * Set the timeout for a solved captcha
21
+ *
22
+ * @param renderOptions
23
+ * @param element
24
+ * @param config
25
+ */
26
+ export const setValidChallengeLength = (
27
+ renderOptions: ProcaptchaRenderOptions | undefined,
28
+ element: Element,
29
+ config: ProcaptchaClientConfigOutput,
30
+ ): void => {
31
+ const challengeValidLengthAttribute =
32
+ renderOptions?.["challenge-valid-length"] ||
33
+ element.getAttribute("data-challenge-valid-length");
34
+
35
+ if (challengeValidLengthAttribute) {
36
+ config.captchas.image.solutionTimeout = Number.parseInt(
37
+ challengeValidLengthAttribute,
38
+ );
39
+ config.captchas.pow.solutionTimeout = Number.parseInt(
40
+ challengeValidLengthAttribute,
41
+ );
42
+ }
43
+ };
@@ -0,0 +1,145 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import { loadI18next } from "@prosopo/locale";
16
+ import type { Ti18n } from "@prosopo/locale";
17
+ import {
18
+ getDefaultCallbacks,
19
+ setUserCallbacks,
20
+ } from "@prosopo/procaptcha-common";
21
+ import type { Callbacks, ProcaptchaRenderOptions } from "@prosopo/types";
22
+ import {
23
+ createWidgetSkeleton,
24
+ darkTheme,
25
+ lightTheme,
26
+ } from "@prosopo/widget-skeleton";
27
+ import type { Root } from "react-dom/client";
28
+ import type { CaptchaRenderer } from "./captcha/captchaRenderer.js";
29
+ import type { WidgetThemeResolver } from "./widgetThemeResolver.js";
30
+
31
+ class WidgetFactory {
32
+ private captchaRenderer: CaptchaRenderer | null = null;
33
+ private _i18n: Ti18n | null = null;
34
+
35
+ public constructor(
36
+ private readonly widgetThemeResolver: WidgetThemeResolver,
37
+ ) {}
38
+
39
+ get i18n(): Ti18n {
40
+ if (this._i18n === null) {
41
+ throw new Error("I18n is not initialized");
42
+ }
43
+ return this._i18n;
44
+ }
45
+
46
+ public async createWidgets(
47
+ containers: Element[],
48
+ renderOptions: ProcaptchaRenderOptions,
49
+ isWeb2 = true,
50
+ invisible = false,
51
+ ): Promise<Root[]> {
52
+ return Promise.all(
53
+ containers.map((container) => {
54
+ const callbacks = getDefaultCallbacks(container);
55
+ setUserCallbacks(renderOptions, callbacks, container);
56
+ return this.createWidget(
57
+ container,
58
+ renderOptions,
59
+ callbacks,
60
+ isWeb2,
61
+ invisible,
62
+ );
63
+ }),
64
+ );
65
+ }
66
+
67
+ public async createWidget(
68
+ container: Element,
69
+ renderOptions: ProcaptchaRenderOptions,
70
+ callbacks: Callbacks,
71
+ isWeb2 = true,
72
+ invisible = false,
73
+ ): Promise<Root> {
74
+ renderOptions.theme = this.widgetThemeResolver.resolveWidgetTheme(
75
+ container,
76
+ renderOptions,
77
+ );
78
+
79
+ const widgetTheme =
80
+ "light" === renderOptions.theme ? lightTheme : darkTheme;
81
+
82
+ let widgetInteractiveArea: HTMLElement;
83
+ let widgetContainer: HTMLElement;
84
+
85
+ // Don't create the widget skeleton if the mode is invisible
86
+ if (invisible) {
87
+ //Create new div inside the container
88
+ const newDiv = document.createElement("div");
89
+ container.appendChild(newDiv);
90
+ widgetInteractiveArea = newDiv as HTMLElement;
91
+ widgetContainer = newDiv;
92
+ } else {
93
+ const widgetResult = createWidgetSkeleton(
94
+ container,
95
+ widgetTheme,
96
+ "prosopo-procaptcha",
97
+ );
98
+ widgetInteractiveArea = widgetResult.widgetInteractiveArea;
99
+ widgetContainer = widgetResult.webComponent;
100
+ }
101
+
102
+ // all the captcha-rendering logic is lazy-loaded, to avoid react & zod delay the initial widget creation.
103
+
104
+ const captchaRenderer = await this.getCaptchaRenderer();
105
+
106
+ const captchaRoot = captchaRenderer.renderCaptcha(
107
+ {
108
+ identifierPrefix: "procaptcha-",
109
+ emotionCacheKey: "procaptcha",
110
+ webComponentTag: "prosopo-procaptcha",
111
+ },
112
+ widgetInteractiveArea,
113
+ renderOptions,
114
+ callbacks,
115
+ isWeb2,
116
+ this.i18n,
117
+ invisible,
118
+ widgetContainer,
119
+ container,
120
+ );
121
+
122
+ return captchaRoot;
123
+ }
124
+
125
+ protected async getCaptchaRenderer(): Promise<CaptchaRenderer> {
126
+ if (this._i18n === null) {
127
+ this._i18n = await loadI18next(false);
128
+ }
129
+
130
+ if (this.captchaRenderer === null) {
131
+ this.captchaRenderer = await this.createCaptchaRenderer();
132
+ }
133
+
134
+ return this.captchaRenderer;
135
+ }
136
+
137
+ protected async createCaptchaRenderer(): Promise<CaptchaRenderer> {
138
+ const CaptchaRenderer = (await import("./captcha/captchaRenderer.js"))
139
+ .CaptchaRenderer;
140
+
141
+ return new CaptchaRenderer();
142
+ }
143
+ }
144
+
145
+ export { WidgetFactory };
@@ -0,0 +1,40 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import type { ProcaptchaRenderOptions } from "@prosopo/types";
16
+
17
+ class WidgetThemeResolver {
18
+ private readonly themesSet = new Set(["light", "dark"]);
19
+ private readonly defaultTheme = "light";
20
+
21
+ public resolveWidgetTheme(
22
+ element: Element,
23
+ renderOptions: ProcaptchaRenderOptions,
24
+ ): "light" | "dark" {
25
+ const themeAttribute =
26
+ renderOptions.theme ||
27
+ element.getAttribute("data-theme") ||
28
+ this.defaultTheme;
29
+
30
+ return this.validateTheme(themeAttribute);
31
+ }
32
+
33
+ protected validateTheme(themeAttribute: string): "light" | "dark" {
34
+ return this.themesSet.has(themeAttribute)
35
+ ? (themeAttribute as "light" | "dark")
36
+ : this.defaultTheme;
37
+ }
38
+ }
39
+
40
+ export { WidgetThemeResolver };
@@ -0,0 +1,35 @@
1
+ {
2
+ "extends": "../../tsconfig.cjs.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist/cjs",
6
+ "lib": ["es6", "dom"]
7
+ },
8
+ "include": ["src/index.ts", "src/index.html"],
9
+ "references": [
10
+ {
11
+ "path": "../../dev/config/tsconfig.cjs.json"
12
+ },
13
+ {
14
+ "path": "../dotenv/tsconfig.cjs.json"
15
+ },
16
+ {
17
+ "path": "../locale/tsconfig.cjs.json"
18
+ },
19
+ {
20
+ "path": "../procaptcha-frictionless/tsconfig.cjs.json"
21
+ },
22
+ {
23
+ "path": "../types/tsconfig.cjs.json"
24
+ },
25
+ {
26
+ "path": "../util/tsconfig.cjs.json"
27
+ },
28
+ {
29
+ "path": "../widget-skeleton/tsconfig.cjs.json"
30
+ },
31
+ {
32
+ "path": "../procaptcha-common/tsconfig.cjs.json"
33
+ }
34
+ ]
35
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "extends": "../../tsconfig.esm.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist",
6
+ "lib": ["es6", "dom"]
7
+ },
8
+ "include": [
9
+ "src",
10
+ "src/**/*.json",
11
+ "src/index.html",
12
+ "src/**/*.ts",
13
+ "src/**/*.tsx",
14
+ "src/**/*.d.ts"
15
+ ],
16
+ "references": [
17
+ {
18
+ "path": "../../dev/config/tsconfig.json"
19
+ },
20
+ {
21
+ "path": "../dotenv"
22
+ },
23
+ {
24
+ "path": "../locale"
25
+ },
26
+ {
27
+ "path": "../procaptcha-frictionless"
28
+ },
29
+ {
30
+ "path": "../types"
31
+ },
32
+ {
33
+ "path": "../util"
34
+ },
35
+ {
36
+ "path": "../widget-skeleton"
37
+ },
38
+ {
39
+ "path": "../procaptcha-common"
40
+ }
41
+ ]
42
+ }