@prosopo/procaptcha-bundle 4.1.40 → 4.1.42

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.
@@ -1,91 +1,57 @@
1
- import { loadI18next } from "@prosopo/locale";
2
- import { getDefaultCallbacks, setUserCallbacks } from "@prosopo/procaptcha-common";
3
- import { lightTheme, darkTheme, createWidgetSkeleton } from "@prosopo/widget-skeleton";
4
1
  import { resolveLanguage } from "./language.js";
5
- class WidgetFactory {
6
- constructor(widgetThemeResolver) {
7
- this.widgetThemeResolver = widgetThemeResolver;
8
- this.captchaRenderer = null;
9
- this._i18n = null;
10
- }
11
- get i18n() {
12
- if (this._i18n === null) {
13
- throw new Error("I18n is not initialized");
14
- }
15
- return this._i18n;
16
- }
17
- async createWidgets(containers, renderOptions, isWeb2 = true, invisible = false) {
18
- return Promise.all(
19
- containers.map((container) => {
20
- const callbacks = getDefaultCallbacks(container);
21
- setUserCallbacks(renderOptions, callbacks, container);
22
- return this.createWidget(
23
- container,
24
- renderOptions,
25
- callbacks,
26
- isWeb2,
27
- invisible
28
- );
29
- })
30
- );
31
- }
32
- async createWidget(container, renderOptions, callbacks, isWeb2 = true, invisible = false) {
33
- renderOptions.theme = this.widgetThemeResolver.resolveWidgetTheme(
34
- container,
35
- renderOptions
36
- );
37
- const widgetTheme = "light" === renderOptions.theme ? lightTheme : darkTheme;
38
- let widgetInteractiveArea;
39
- let widgetContainer;
40
- if (invisible) {
41
- const newDiv = document.createElement("div");
42
- container.appendChild(newDiv);
43
- widgetInteractiveArea = newDiv;
44
- widgetContainer = newDiv;
45
- } else {
46
- const widgetResult = createWidgetSkeleton(
47
- container,
48
- widgetTheme,
49
- "prosopo-procaptcha"
50
- );
51
- widgetInteractiveArea = widgetResult.widgetInteractiveArea;
52
- widgetContainer = widgetResult.webComponent;
53
- }
54
- const language = resolveLanguage(renderOptions, container);
55
- const captchaRenderer = await this.getCaptchaRenderer(language);
56
- const captchaRoot = captchaRenderer.renderCaptcha(
57
- {
58
- identifierPrefix: "procaptcha-",
59
- emotionCacheKey: "procaptcha",
60
- webComponentTag: "prosopo-procaptcha"
61
- },
62
- widgetInteractiveArea,
63
- renderOptions,
64
- callbacks,
65
- isWeb2,
66
- this.i18n,
67
- invisible,
68
- widgetContainer,
69
- container
70
- );
71
- return captchaRoot;
72
- }
73
- async getCaptchaRenderer(language) {
74
- if (this._i18n === null) {
75
- this._i18n = await loadI18next(false, language);
76
- } else if (language && this._i18n.language !== language) {
77
- await this._i18n.changeLanguage(language);
78
- }
79
- if (this.captchaRenderer === null) {
80
- this.captchaRenderer = await this.createCaptchaRenderer();
81
- }
82
- return this.captchaRenderer;
83
- }
84
- async createCaptchaRenderer() {
85
- const CaptchaRenderer = (await import("./captcha/captchaRenderer.js")).CaptchaRenderer;
86
- return new CaptchaRenderer();
87
- }
88
- }
89
- export {
90
- WidgetFactory
2
+ import { getDefaultCallbacks, setUserCallbacks } from "@prosopo/procaptcha-common";
3
+ import { loadI18next } from "@prosopo/locale";
4
+ import { createWidgetSkeleton, darkTheme, lightTheme } from "@prosopo/widget-skeleton";
5
+ //#region src/util/widgetFactory.ts
6
+ var WidgetFactory = class {
7
+ constructor(widgetThemeResolver) {
8
+ this.widgetThemeResolver = widgetThemeResolver;
9
+ this.captchaRenderer = null;
10
+ this._i18n = null;
11
+ }
12
+ get i18n() {
13
+ if (this._i18n === null) throw new Error("I18n is not initialized");
14
+ return this._i18n;
15
+ }
16
+ async createWidgets(containers, renderOptions, isWeb2 = true, invisible = false) {
17
+ return Promise.all(containers.map((container) => {
18
+ const callbacks = getDefaultCallbacks(container);
19
+ setUserCallbacks(renderOptions, callbacks, container);
20
+ return this.createWidget(container, renderOptions, callbacks, isWeb2, invisible);
21
+ }));
22
+ }
23
+ async createWidget(container, renderOptions, callbacks, isWeb2 = true, invisible = false) {
24
+ renderOptions.theme = this.widgetThemeResolver.resolveWidgetTheme(container, renderOptions);
25
+ const widgetTheme = "light" === renderOptions.theme ? lightTheme : darkTheme;
26
+ let widgetInteractiveArea;
27
+ let widgetContainer;
28
+ if (invisible) {
29
+ const newDiv = document.createElement("div");
30
+ container.appendChild(newDiv);
31
+ widgetInteractiveArea = newDiv;
32
+ widgetContainer = newDiv;
33
+ } else {
34
+ const widgetResult = createWidgetSkeleton(container, widgetTheme, "prosopo-procaptcha");
35
+ widgetInteractiveArea = widgetResult.widgetInteractiveArea;
36
+ widgetContainer = widgetResult.webComponent;
37
+ }
38
+ const language = resolveLanguage(renderOptions, container);
39
+ return (await this.getCaptchaRenderer(language)).renderCaptcha({
40
+ identifierPrefix: "procaptcha-",
41
+ emotionCacheKey: "procaptcha",
42
+ webComponentTag: "prosopo-procaptcha"
43
+ }, widgetInteractiveArea, renderOptions, callbacks, isWeb2, this.i18n, invisible, widgetContainer, container);
44
+ }
45
+ async getCaptchaRenderer(language) {
46
+ if (this._i18n === null) this._i18n = await loadI18next(false, language);
47
+ else if (language && this._i18n.language !== language) await this._i18n.changeLanguage(language);
48
+ if (this.captchaRenderer === null) this.captchaRenderer = await this.createCaptchaRenderer();
49
+ return this.captchaRenderer;
50
+ }
51
+ async createCaptchaRenderer() {
52
+ const CaptchaRenderer = (await import("./captcha/captchaRenderer.js")).CaptchaRenderer;
53
+ return new CaptchaRenderer();
54
+ }
91
55
  };
56
+ //#endregion
57
+ export { WidgetFactory };
@@ -1,16 +1,16 @@
1
- class WidgetThemeResolver {
2
- constructor() {
3
- this.themesSet = /* @__PURE__ */ new Set(["light", "dark"]);
4
- this.defaultTheme = "light";
5
- }
6
- resolveWidgetTheme(element, renderOptions) {
7
- const themeAttribute = renderOptions.theme || element.getAttribute("data-theme") || this.defaultTheme;
8
- return this.validateTheme(themeAttribute);
9
- }
10
- validateTheme(themeAttribute) {
11
- return this.themesSet.has(themeAttribute) ? themeAttribute : this.defaultTheme;
12
- }
13
- }
14
- export {
15
- WidgetThemeResolver
1
+ //#region src/util/widgetThemeResolver.ts
2
+ var WidgetThemeResolver = class {
3
+ constructor() {
4
+ this.themesSet = /* @__PURE__ */ new Set(["light", "dark"]);
5
+ this.defaultTheme = "light";
6
+ }
7
+ resolveWidgetTheme(element, renderOptions) {
8
+ const themeAttribute = renderOptions.theme || element.getAttribute("data-theme") || this.defaultTheme;
9
+ return this.validateTheme(themeAttribute);
10
+ }
11
+ validateTheme(themeAttribute) {
12
+ return this.themesSet.has(themeAttribute) ? themeAttribute : this.defaultTheme;
13
+ }
16
14
  };
15
+ //#endregion
16
+ export { WidgetThemeResolver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/procaptcha-bundle",
3
- "version": "4.1.40",
3
+ "version": "4.1.42",
4
4
  "author": "PROSOPO LIMITED <info@prosopo.io>",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -39,12 +39,12 @@
39
39
  },
40
40
  "browserslist": ["> 0.5%, last 2 versions, not dead"],
41
41
  "dependencies": {
42
- "@prosopo/dotenv": "3.0.49",
43
- "@prosopo/locale": "3.2.7",
44
- "@prosopo/procaptcha-common": "2.11.17",
45
- "@prosopo/procaptcha-frictionless": "2.12.21",
46
- "@prosopo/types": "4.9.12",
47
- "@prosopo/util": "3.3.4",
42
+ "@prosopo/dotenv": "3.0.50",
43
+ "@prosopo/locale": "3.2.8",
44
+ "@prosopo/procaptcha-common": "2.11.18",
45
+ "@prosopo/procaptcha-frictionless": "2.12.23",
46
+ "@prosopo/types": "4.10.0",
47
+ "@prosopo/util": "3.3.5",
48
48
  "@prosopo/widget-skeleton": "2.8.4",
49
49
  "dotenv": "16.4.5",
50
50
  "fast-glob": "3.3.2",
@@ -68,20 +68,20 @@
68
68
  "registry": "https://registry.npmjs.org"
69
69
  },
70
70
  "devDependencies": {
71
- "@prosopo/config": "3.3.4",
71
+ "@prosopo/config": "3.3.5",
72
72
  "@types/jsdom": "21.1.7",
73
73
  "@types/node": "22.10.2",
74
74
  "@types/react": "18.3.1",
75
75
  "@types/react-dom": "18.3.1",
76
- "@vitest/coverage-v8": "3.2.4",
76
+ "@vitest/coverage-v8": "4.1.10",
77
77
  "concurrently": "9.0.1",
78
78
  "del-cli": "6.0.0",
79
79
  "npm-run-all": "4.1.5",
80
80
  "tslib": "2.7.0",
81
81
  "tsx": "4.20.3",
82
82
  "typescript": "5.6.2",
83
- "vite": "6.4.1",
84
- "vitest": "3.2.4"
83
+ "vite": "8.1.5",
84
+ "vitest": "4.1.10"
85
85
  },
86
86
  "overrides": {
87
87
  "@types/react": "18.3.1"