@prosopo/procaptcha-react 0.1.19 → 0.2.1

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.
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const material = require("@mui/material");
4
+ const CaptchaWidget = require("./CaptchaWidget.cjs");
5
+ const util = require("@prosopo/util");
6
+ const common = require("@prosopo/common");
7
+ const index = require("../util/index.cjs");
8
+ const theme = require("./theme.cjs");
9
+ const CaptchaComponent = (props) => {
10
+ const { t } = common.useTranslation();
11
+ const { challenge, index: index$1, solutions, onSubmit, onCancel, onClick, onNext } = props;
12
+ const captcha = util.at(challenge.captchas, index$1);
13
+ const solution = util.at(solutions, index$1);
14
+ return /* @__PURE__ */ jsxRuntime.jsx(material.ThemeProvider, { theme, children: /* @__PURE__ */ jsxRuntime.jsx(
15
+ material.Box,
16
+ {
17
+ sx: {
18
+ // center the popup horizontally and vertically
19
+ display: "flex",
20
+ alignItems: "center",
21
+ justifyContent: "center",
22
+ // fill entire screen
23
+ width: "100%",
24
+ height: "100%"
25
+ },
26
+ children: /* @__PURE__ */ jsxRuntime.jsx(
27
+ material.Box,
28
+ {
29
+ sx: {
30
+ // introduce scroll bars when screen < minWidth of children
31
+ overflowX: "auto",
32
+ overflowY: "auto",
33
+ width: "100%",
34
+ // limit the popup width
35
+ maxWidth: "450px",
36
+ // maxHeight introduces vertical scroll bars if children content longer than window
37
+ maxHeight: "100%"
38
+ },
39
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
40
+ material.Box,
41
+ {
42
+ bgcolor: theme.palette.background.default,
43
+ sx: {
44
+ display: "flex",
45
+ flexDirection: "column",
46
+ // the min width of the popup before scroll bars appear
47
+ minWidth: "300px"
48
+ },
49
+ children: [
50
+ /* @__PURE__ */ jsxRuntime.jsxs(
51
+ material.Box,
52
+ {
53
+ px: 2,
54
+ py: 3,
55
+ sx: {
56
+ // center the header
57
+ display: "flex",
58
+ alignItems: "center",
59
+ width: "100%"
60
+ },
61
+ bgcolor: theme.palette.primary.main,
62
+ children: [
63
+ /* @__PURE__ */ jsxRuntime.jsxs(
64
+ material.Typography,
65
+ {
66
+ sx: {
67
+ color: "#ffffff",
68
+ fontWeight: 700
69
+ },
70
+ children: [
71
+ t("WIDGET.SELECT_ALL"),
72
+ ": "
73
+ ]
74
+ }
75
+ ),
76
+ /* @__PURE__ */ jsxRuntime.jsx(
77
+ material.Typography,
78
+ {
79
+ px: 1,
80
+ sx: {
81
+ color: "#ffffff",
82
+ fontWeight: 700,
83
+ textTransform: "uppercase",
84
+ fontSize: theme.typography.h6.fontSize
85
+ },
86
+ children: `${util.at(props.challenge.captchas, props.index).captcha.target}`
87
+ }
88
+ )
89
+ ]
90
+ }
91
+ ),
92
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { ...index({ dev: { cy: "captcha-" + props.index } }), children: /* @__PURE__ */ jsxRuntime.jsx(CaptchaWidget.CaptchaWidget, { challenge: captcha, solution, onClick }) }),
93
+ /* @__PURE__ */ jsxRuntime.jsx(
94
+ material.Box,
95
+ {
96
+ px: 2,
97
+ py: 1,
98
+ sx: {
99
+ display: "flex",
100
+ alignItems: "center",
101
+ justifyContent: "center",
102
+ width: "100%"
103
+ },
104
+ ...index({ dev: { cy: "dots-captcha" } }),
105
+ children: challenge.captchas.map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(
106
+ material.Box,
107
+ {
108
+ sx: {
109
+ width: 7,
110
+ height: 7,
111
+ borderRadius: "50%",
112
+ border: "1px solid #CFCFCF"
113
+ },
114
+ mx: 0.5,
115
+ bgcolor: index$1 === i ? theme.palette.background.default : "#CFCFCF"
116
+ },
117
+ i
118
+ ))
119
+ }
120
+ ),
121
+ /* @__PURE__ */ jsxRuntime.jsxs(
122
+ material.Box,
123
+ {
124
+ px: 2,
125
+ pt: 0,
126
+ pb: 2,
127
+ sx: {
128
+ display: "flex",
129
+ alignItems: "center",
130
+ justifyContent: "space-between"
131
+ },
132
+ children: [
133
+ /* @__PURE__ */ jsxRuntime.jsx(material.Button, { onClick: onCancel, variant: "text", children: t("WIDGET.CANCEL") }),
134
+ /* @__PURE__ */ jsxRuntime.jsx(
135
+ material.Button,
136
+ {
137
+ color: "primary",
138
+ onClick: index$1 < challenge.captchas.length - 1 ? onNext : onSubmit,
139
+ variant: "contained",
140
+ ...index({ dev: { cy: "button-next" } }),
141
+ children: index$1 < challenge.captchas.length - 1 ? t("WIDGET.NEXT") : t("WIDGET.SUBMIT")
142
+ }
143
+ )
144
+ ]
145
+ }
146
+ )
147
+ ]
148
+ }
149
+ )
150
+ }
151
+ )
152
+ }
153
+ ) });
154
+ };
155
+ module.exports = CaptchaComponent;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const material = require("@mui/material");
5
+ const CheckIcon = require("@mui/icons-material/Check.js");
6
+ const normalizeIcon = (Icon) => {
7
+ return Icon.default ? Icon.default : Icon;
8
+ };
9
+ const CheckIconNormalized = normalizeIcon(CheckIcon);
10
+ const getHash = (item) => {
11
+ if (!item.hash) {
12
+ throw new Error("item.hash is undefined");
13
+ }
14
+ return item.hash;
15
+ };
16
+ function CaptchaWidget(props) {
17
+ const { challenge, solution, onClick } = props;
18
+ const items = challenge.captcha.items;
19
+ const theme = material.useTheme();
20
+ const isTouchDevice = "ontouchstart" in window;
21
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
22
+ material.Box,
23
+ {
24
+ component: "div",
25
+ pr: 0.5,
26
+ pb: 0.5,
27
+ sx: {
28
+ // expand to full height / width of parent
29
+ width: "100%",
30
+ height: "100%",
31
+ // display children in flex, spreading them evenly and wrapping when row length exceeded
32
+ display: "flex",
33
+ flexDirection: "row",
34
+ flexWrap: "wrap"
35
+ },
36
+ children: items.map((item, index) => {
37
+ const hash = getHash(item);
38
+ return /* @__PURE__ */ jsxRuntime.jsx(
39
+ material.Box,
40
+ {
41
+ pt: 0.5,
42
+ pl: 0.5,
43
+ sx: {
44
+ // enable the items in the grid to grow in width to use up excess space
45
+ flexGrow: 1,
46
+ // make the width of each item 1/3rd of the width overall, i.e. 3 columns
47
+ flexBasis: "33.3333%",
48
+ // include the padding / margin / border in the width
49
+ boxSizing: "border-box"
50
+ },
51
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
52
+ material.Box,
53
+ {
54
+ sx: { cursor: "pointer", height: "100%", width: "100%" },
55
+ onClick: isTouchDevice ? void 0 : () => onClick(hash),
56
+ onTouchStart: isTouchDevice ? () => onClick(hash) : void 0,
57
+ children: [
58
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { border: 1, borderColor: "lightgray" }, children: /* @__PURE__ */ jsxRuntime.jsx(
59
+ "img",
60
+ {
61
+ style: {
62
+ width: "100%",
63
+ // image should be full width / height of the item
64
+ backgroundColor: "lightgray",
65
+ // colour of the bands when letterboxing and image
66
+ opacity: solution.includes(hash) && isTouchDevice ? "50%" : "100%",
67
+ // iphone workaround
68
+ display: "block",
69
+ // removes whitespace below imgs
70
+ objectFit: "contain",
71
+ // contain the entire image in the img tag
72
+ aspectRatio: "1/1"
73
+ // force AR to be 1, letterboxing images with different aspect ratios
74
+ },
75
+ src: item.data,
76
+ alt: `Captcha image ${index + 1}`
77
+ }
78
+ ) }),
79
+ /* @__PURE__ */ jsxRuntime.jsx(material.Fade, { in: solution.includes(hash), children: /* @__PURE__ */ jsxRuntime.jsx(
80
+ material.Box,
81
+ {
82
+ sx: {
83
+ // relative to where the element _should_ be positioned
84
+ position: "relative",
85
+ // make the overlay the full height/width of an item
86
+ width: "100%",
87
+ height: "100%",
88
+ // shift it up 100% to overlay the item element
89
+ top: "-100%",
90
+ // transition on opacity upon (de)selection
91
+ transitionDuration: "300ms",
92
+ transitionProperty: "opacity"
93
+ },
94
+ children: /* @__PURE__ */ jsxRuntime.jsx(
95
+ material.Box,
96
+ {
97
+ sx: {
98
+ // make the overlay absolute positioned compare to its container
99
+ position: "absolute",
100
+ // spread across 100% width/height of the item box
101
+ top: 0,
102
+ left: 0,
103
+ bottom: 0,
104
+ right: 0,
105
+ height: "100%",
106
+ width: "100%",
107
+ // display overlays in center
108
+ display: "flex",
109
+ alignItems: "center",
110
+ justifyContent: "center",
111
+ // make bg half opacity, i.e. shadowing the item's img
112
+ backgroundColor: "rgba(0,0,0,0.5)"
113
+ },
114
+ children: /* @__PURE__ */ jsxRuntime.jsx(
115
+ CheckIconNormalized,
116
+ {
117
+ htmlColor: theme.palette.background.default,
118
+ sx: {
119
+ // img must be displayed as block otherwise get's a bottom whitespace border
120
+ display: "block",
121
+ // how big the overlay icon is
122
+ width: "35%",
123
+ height: "35%"
124
+ }
125
+ }
126
+ )
127
+ }
128
+ )
129
+ }
130
+ ) })
131
+ ]
132
+ }
133
+ )
134
+ },
135
+ index
136
+ );
137
+ })
138
+ }
139
+ ) });
140
+ }
141
+ exports.CaptchaWidget = CaptchaWidget;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const material = require("@mui/material");
5
+ const react = require("react");
6
+ const common = require("@prosopo/common");
7
+ const extensionDapp = require("@polkadot/extension-dapp");
8
+ const ExtensionAccountSelect = ({
9
+ value,
10
+ dappName,
11
+ onChange
12
+ }) => {
13
+ const { t } = common.useTranslation();
14
+ const [accounts, setAccounts] = react.useState([]);
15
+ react.useEffect(() => {
16
+ const prom = extensionDapp.web3Enable(dappName).then(() => {
17
+ return extensionDapp.web3AccountsSubscribe(setAccounts);
18
+ });
19
+ return () => {
20
+ prom.then((unsub) => unsub());
21
+ };
22
+ }, []);
23
+ const account = accounts.find((a) => a.address === value) || null;
24
+ return /* @__PURE__ */ jsxRuntime.jsx(
25
+ material.Autocomplete,
26
+ {
27
+ disablePortal: true,
28
+ id: "select-account",
29
+ options: accounts,
30
+ value: account,
31
+ isOptionEqualToValue: (option, value2) => option.address === value2.address,
32
+ onChange: (event, value2) => {
33
+ if (value2) {
34
+ console.log("Selected account:", value2);
35
+ onChange(value2.address);
36
+ } else {
37
+ console.log("Deselected account");
38
+ onChange("");
39
+ }
40
+ },
41
+ sx: { width: 550 },
42
+ getOptionLabel: (option) => `${option.meta.name}: ${option.address}`,
43
+ renderInput: (props) => /* @__PURE__ */ jsxRuntime.jsx(material.TextField, { ...props, label: t("WIDGET.SELECT_ACCOUNT") })
44
+ }
45
+ );
46
+ };
47
+ exports.ExtensionAccountSelect = ExtensionAccountSelect;
48
+ exports.default = ExtensionAccountSelect;
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("@emotion/react/jsx-runtime");
4
+ const procaptcha = require("@prosopo/procaptcha");
5
+ const material = require("@mui/material");
6
+ const react = require("@emotion/react");
7
+ const react$1 = require("react");
8
+ const CaptchaComponent = require("./CaptchaComponent.cjs");
9
+ const logoStyle = react.css`
10
+ align-items: center;
11
+ justify-content: flex-end;
12
+ display: flex;
13
+ padding: 8px;
14
+
15
+ @media (max-width: 245px) {
16
+ &:nth-of-type(1),
17
+ &:nth-of-type(2) {
18
+ display: none;
19
+ } /* Both logos hidden */
20
+ }
21
+
22
+ @media (min-width: 245px) and (max-width: 400px) {
23
+ &:nth-of-type(1) {
24
+ display: flex;
25
+ } /* logoWithText */
26
+ &:nth-of-type(2) {
27
+ display: none;
28
+ } /* logoWithoutText */
29
+ }
30
+
31
+ @media (min-width: 401px) {
32
+ &:nth-of-type(1) {
33
+ display: none;
34
+ } /* logoWithText */
35
+ &:nth-of-type(2) {
36
+ display: flex;
37
+ } /* logoWithoutText */
38
+ }
39
+ `;
40
+ const useRefAsState = (defaultValue) => {
41
+ const ref = react$1.useRef(defaultValue);
42
+ const setter = (value2) => {
43
+ ref.current = value2;
44
+ };
45
+ const value = ref.current;
46
+ return [value, setter];
47
+ };
48
+ const useProcaptcha = () => {
49
+ const [isHuman, setIsHuman] = react$1.useState(false);
50
+ const [index, setIndex] = react$1.useState(-1);
51
+ const [solutions, setSolutions] = react$1.useState([]);
52
+ const [captchaApi, setCaptchaApi] = useRefAsState(void 0);
53
+ const [showModal, setShowModal] = react$1.useState(false);
54
+ const [challenge, setChallenge] = react$1.useState(void 0);
55
+ const [loading, setLoading] = react$1.useState(false);
56
+ const [account, setAccount] = react$1.useState(void 0);
57
+ const [dappAccount, setDappAccount] = react$1.useState(void 0);
58
+ const [submission, setSubmission] = useRefAsState(void 0);
59
+ const [timeout, setTimeout] = useRefAsState(void 0);
60
+ const [blockNumber, setBlockNumber] = useRefAsState(void 0);
61
+ return [
62
+ // the state
63
+ {
64
+ isHuman,
65
+ index,
66
+ solutions,
67
+ captchaApi,
68
+ showModal,
69
+ challenge,
70
+ loading,
71
+ account,
72
+ dappAccount,
73
+ submission,
74
+ timeout,
75
+ blockNumber
76
+ },
77
+ // and method to update the state
78
+ (nextState) => {
79
+ if (nextState.account !== void 0)
80
+ setAccount(nextState.account);
81
+ if (nextState.isHuman !== void 0)
82
+ setIsHuman(nextState.isHuman);
83
+ if (nextState.index !== void 0)
84
+ setIndex(nextState.index);
85
+ if (nextState.solutions !== void 0)
86
+ setSolutions(nextState.solutions.slice());
87
+ if (nextState.captchaApi !== void 0)
88
+ setCaptchaApi(nextState.captchaApi);
89
+ if (nextState.showModal !== void 0)
90
+ setShowModal(nextState.showModal);
91
+ if (nextState.challenge !== void 0)
92
+ setChallenge(nextState.challenge);
93
+ if (nextState.loading !== void 0)
94
+ setLoading(nextState.loading);
95
+ if (nextState.showModal !== void 0)
96
+ setShowModal(nextState.showModal);
97
+ if (nextState.dappAccount !== void 0)
98
+ setDappAccount(nextState.dappAccount);
99
+ if (nextState.submission !== void 0)
100
+ setSubmission(nextState.submission);
101
+ if (nextState.timeout !== void 0)
102
+ setTimeout(nextState.timeout);
103
+ if (nextState.blockNumber !== void 0)
104
+ setBlockNumber(nextState.blockNumber);
105
+ }
106
+ ];
107
+ };
108
+ const Procaptcha = (props) => {
109
+ console.log("config", props.config);
110
+ const config = props.config;
111
+ const callbacks = props.callbacks || {};
112
+ const [state, updateState] = useProcaptcha();
113
+ console.log("state", state);
114
+ const manager = procaptcha.Manager(config, state, updateState, callbacks);
115
+ const configSx = config.sx || { maxWidth: "400px", minWidth: "200px" };
116
+ return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: [
117
+ /* @__PURE__ */ jsxRuntime.jsx(material.Backdrop, { open: state.showModal, sx: { zIndex: (theme) => theme.zIndex.drawer + 1 }, children: state.challenge ? /* @__PURE__ */ jsxRuntime.jsx(
118
+ CaptchaComponent,
119
+ {
120
+ challenge: state.challenge,
121
+ index: state.index,
122
+ solutions: state.solutions,
123
+ onSubmit: manager.submit,
124
+ onCancel: manager.cancel,
125
+ onClick: manager.select,
126
+ onNext: manager.nextRound
127
+ }
128
+ ) : /* @__PURE__ */ jsxRuntime.jsx(material.Alert, { children: "No challenge set." }) }),
129
+ /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { p: 0, sx: [...Array.isArray(configSx) ? configSx : [configSx]], "data-cy": "button-human", children: [
130
+ " ",
131
+ /* @__PURE__ */ jsxRuntime.jsxs(
132
+ material.Box,
133
+ {
134
+ p: 1,
135
+ border: 1,
136
+ borderColor: "grey.300",
137
+ borderRadius: 2,
138
+ sx: {
139
+ display: "flex",
140
+ justifyContent: "space-between",
141
+ alignItems: "center",
142
+ flexWrap: "wrap",
143
+ backgroundColor: "white"
144
+ },
145
+ children: [
146
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ jsxRuntime.jsxs(
147
+ material.Box,
148
+ {
149
+ sx: {
150
+ display: "flex",
151
+ justifyContent: "flex-start",
152
+ alignItems: "center",
153
+ flexWrap: "wrap"
154
+ },
155
+ children: [
156
+ /* @__PURE__ */ jsxRuntime.jsxs(
157
+ material.Box,
158
+ {
159
+ sx: {
160
+ height: "50px",
161
+ width: "50px",
162
+ display: "flex",
163
+ alignItems: "center",
164
+ justifyContent: "center",
165
+ flexDirection: "column"
166
+ },
167
+ children: [
168
+ /* @__PURE__ */ jsxRuntime.jsx(
169
+ material.Box,
170
+ {
171
+ sx: {
172
+ display: !state.loading ? "block" : "none"
173
+ },
174
+ children: /* @__PURE__ */ jsxRuntime.jsx(
175
+ material.Checkbox,
176
+ {
177
+ onChange: manager.start,
178
+ checked: state.isHuman,
179
+ inputProps: { "aria-label": "controlled" },
180
+ sx: {
181
+ "& .MuiSvgIcon-root": { fontSize: 32 }
182
+ }
183
+ }
184
+ )
185
+ }
186
+ ),
187
+ /* @__PURE__ */ jsxRuntime.jsx(
188
+ material.Box,
189
+ {
190
+ sx: {
191
+ display: state.loading ? "block" : "none"
192
+ },
193
+ children: /* @__PURE__ */ jsxRuntime.jsx(material.Box, { pt: "5px", children: /* @__PURE__ */ jsxRuntime.jsx(material.CircularProgress, { size: "24px", disableShrink: true }) })
194
+ }
195
+ )
196
+ ]
197
+ }
198
+ ),
199
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { p: 1, children: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { color: "common.black", children: "I am a human" }) })
200
+ ]
201
+ }
202
+ ) }),
203
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(material.Link, { href: "https://prosopo.io", target: "_blank", children: /* @__PURE__ */ jsxRuntime.jsx(material.Box, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
204
+ /* @__PURE__ */ jsxRuntime.jsx("div", { css: logoStyle, dangerouslySetInnerHTML: { __html: logoWithoutText } }),
205
+ /* @__PURE__ */ jsxRuntime.jsx("div", { css: logoStyle, dangerouslySetInnerHTML: { __html: logoWithText } })
206
+ ] }) }) }) })
207
+ ]
208
+ }
209
+ )
210
+ ] })
211
+ ] });
212
+ };
213
+ const logoWithText = '<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2062.63 468.67" height="35px" width="140px"><defs><style>.cls-1{fill:#1d1d1b;}</style></defs><title>Prosopo Logo Black</title><path class="cls-1" d="M335.55,1825.19A147.75,147.75,0,0,1,483.3,1972.94h50.5c0-109.49-88.76-198.25-198.25-198.25v50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M269.36,1891.39A147.74,147.74,0,0,1,417.1,2039.13h50.5c0-109.49-88.75-198.24-198.24-198.24v50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M414,2157.17a147.75,147.75,0,0,1-147.74-147.74h-50.5c0,109.49,88.75,198.24,198.24,198.24v-50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M480.17,2091a147.74,147.74,0,0,1-147.74-147.75H281.92c0,109.49,88.76,198.25,198.25,198.25V2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M862.8,2017.5q-27.39,22.86-78.25,22.86h-65v112.19H654.82v-312h134q46.32,0,73.86,24.13t27.55,74.72Q890.2,1994.64,862.8,2017.5ZM813,1905.1q-12.37-10.36-34.7-10.38H719.59v91.87h58.75q22.32,0,34.7-11.22t12.39-35.56Q825.43,1915.48,813,1905.1Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1045.69,1916.42c.78.08,2.51.19,5.19.32v61.81c-3.81-.42-7.2-.71-10.16-.85s-5.36-.21-7.2-.21q-36.4,0-48.89,23.71-7,13.33-7,41.06v110.29H916.89V1921.82h57.58V1962q14-23.07,24.34-31.54,16.94-14.18,44-14.18C1044,1916.32,1044.92,1916.35,1045.69,1916.42Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1265.64,2124.32q-29.21,36.06-88.69,36.06t-88.69-36.06Q1059,2088.26,1059,2037.5q0-49.9,29.22-86.5t88.69-36.59q59.47,0,88.69,36.59t29.21,86.5Q1294.85,2088.26,1265.64,2124.32ZM1217.38,2091q14.17-18.81,14.18-53.48t-14.18-53.37q-14.19-18.7-40.64-18.71T1136,1984.13q-14.29,18.72-14.29,53.37T1136,2091q14.28,18.81,40.75,18.81T1217.38,2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1371.81,2078.88q1.92,16.1,8.29,22.87,11.28,12.06,41.7,12.06,17.85,0,28.39-5.29t10.53-15.88a17.12,17.12,0,0,0-8.48-15.45q-8.49-5.28-63.12-18.2-39.33-9.73-55.41-24.35-16.08-14.39-16.09-41.49,0-32,25.14-54.93t70.75-23q43.26,0,70.53,17.25t31.29,59.59H1455q-1.27-11.64-6.58-18.42-10-12.27-34-12.28-19.74,0-28.13,6.14t-8.38,14.4c0,6.91,3,11.93,8.92,15q8.89,4.89,63,16.73,36,8.46,54.05,25.61,17.77,17.35,17.78,43.39,0,34.3-25.56,56t-79,21.7q-54.51,0-80.49-23t-26-58.53Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1745.54,2124.32q-29.22,36.06-88.7,36.06t-88.69-36.06q-29.2-36.06-29.21-86.82,0-49.9,29.21-86.5t88.69-36.59q59.49,0,88.7,36.59t29.21,86.5Q1774.75,2088.26,1745.54,2124.32ZM1697.27,2091q14.19-18.81,14.19-53.48t-14.19-53.37q-14.18-18.7-40.64-18.71t-40.75,18.71q-14.28,18.72-14.28,53.37t14.28,53.48q14.3,18.81,40.75,18.81T1697.27,2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1992.75,1946.59q28.24,29.84,28.23,87.63,0,61-27.58,92.93t-71.06,32q-27.69,0-46-13.76-10-7.62-19.6-22.23v120.24H1797V1921.82h57.79v34.08q9.79-15,20.88-23.71,20.23-15.43,48.15-15.45Q1964.53,1916.74,1992.75,1946.59Zm-46.3,43.39q-12.3-20.52-39.88-20.53-33.15,0-45.54,31.11-6.43,16.51-6.42,41.92,0,40.21,21.58,56.51,12.82,9.53,30.37,9.53,25.45,0,38.83-19.48t13.36-51.86Q1958.75,2010.51,1946.45,1990Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M2249.14,2124.32q-29.2,36.06-88.69,36.06t-88.69-36.06q-29.22-36.06-29.21-86.82,0-49.9,29.21-86.5t88.69-36.59q59.49,0,88.69,36.59t29.22,86.5Q2278.36,2088.26,2249.14,2124.32ZM2200.88,2091q14.19-18.81,14.18-53.48t-14.18-53.37q-14.18-18.7-40.64-18.71t-40.75,18.71q-14.28,18.72-14.29,53.37t14.29,53.48q14.3,18.81,40.75,18.81T2200.88,2091Z" transform="translate(-215.73 -1774.69)"/></svg>';
214
+ const logoWithoutText = '<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 260 348" height="35px"><path id="Vector" d="M95.7053 40.2707C127.005 40.2707 157.022 52.6841 179.154 74.78C201.286 96.8759 213.719 126.844 213.719 158.093H254.056C254.056 70.7808 183.16 -4.57764e-05 95.7053 -4.57764e-05V40.2707Z" fill="#000000"/><path id="Vector_2" d="M42.8365 93.0614C58.3333 93.0614 73.6784 96.1087 87.9955 102.029C102.313 107.95 115.322 116.628 126.279 127.568C137.237 138.508 145.93 151.496 151.86 165.79C157.79 180.084 160.843 195.404 160.843 210.875H201.179C201.179 123.564 130.291 52.7906 42.8365 52.7906V93.0614Z" fill="#000000"/><path id="Vector_3" d="M158.367 305.005C127.07 305.003 97.056 292.59 74.926 270.496C52.796 248.402 40.3626 218.437 40.3604 187.191H0.0239563C0.0239563 274.503 70.9123 345.276 158.367 345.276V305.005Z" fill="#000000"/><path id="Vector_4" d="M211.219 252.239C195.722 252.239 180.376 249.191 166.059 243.27C151.741 237.349 138.732 228.67 127.774 217.729C116.816 206.788 108.123 193.799 102.194 179.505C96.2637 165.21 93.2121 149.889 93.2132 134.417H52.8687C52.8687 221.729 123.765 292.509 211.219 292.509V252.239Z" fill="#000000"/></g><defs><clipPath id="clip0_1_2"><rect width="254" height="345" fill="white"/></clipPath></defs></svg>';
215
+ exports.Procaptcha = Procaptcha;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const CaptchaWidget = require("./CaptchaWidget.cjs");
4
+ require("./CaptchaComponent.cjs");
5
+ const ExtensionAccountSelect = require("./ExtensionAccountSelect.cjs");
6
+ const Procaptcha = require("./Procaptcha.cjs");
7
+ exports.CaptchaWidget = CaptchaWidget.CaptchaWidget;
8
+ exports.ExtensionAccountSelect = ExtensionAccountSelect.ExtensionAccountSelect;
9
+ exports.Procaptcha = Procaptcha.Procaptcha;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ const material = require("@mui/material");
3
+ const theme = material.createTheme({
4
+ palette: {
5
+ primary: {
6
+ main: "#1976d2",
7
+ contrastText: "#fff"
8
+ }
9
+ }
10
+ });
11
+ module.exports = theme;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("./components/index.cjs");
4
+ require("./util/index.cjs");
5
+ const ExtensionAccountSelect = require("./components/ExtensionAccountSelect.cjs");
6
+ const CaptchaWidget = require("./components/CaptchaWidget.cjs");
7
+ const Procaptcha = require("./components/Procaptcha.cjs");
8
+ exports.ExtensionAccountSelect = ExtensionAccountSelect.ExtensionAccountSelect;
9
+ exports.CaptchaWidget = CaptchaWidget.CaptchaWidget;
10
+ exports.Procaptcha = Procaptcha.Procaptcha;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ function renameKeysForDataAttr(data = {}) {
3
+ return Object.keys(data).reduce((prev, curr) => ({ ...prev, [`data-${curr}`]: data[curr] }), {});
4
+ }
5
+ function addDataAttr({
6
+ general,
7
+ dev
8
+ }) {
9
+ return {
10
+ ...renameKeysForDataAttr(general),
11
+ ...process.env.NODE_ENV === "development" ? renameKeysForDataAttr(dev) : {}
12
+ };
13
+ }
14
+ module.exports = addDataAttr;
@@ -140,7 +140,7 @@ export const Procaptcha = (props) => {
140
140
  console.log('state', state);
141
141
  const manager = Manager(config, state, updateState, callbacks);
142
142
  const configSx = config.sx || { maxWidth: '400px', minWidth: '200px' };
143
- return (_jsxs(Box, { sx: { maxWidth: '100%', maxHeight: '100%', overflowX: 'auto' }, children: [_jsx(Backdrop, { open: state.showModal, sx: { zIndex: (theme) => theme.zIndex.drawer + 1 }, children: state.challenge ? (_jsx(CaptchaComponent, { challenge: state.challenge, index: state.index, solutions: state.solutions, onSubmit: manager.submit, onCancel: manager.cancel, onClick: manager.select, onNext: manager.nextRound })) : (_jsx(Alert, { children: "No challenge set." })) }), _jsxs(Box, { p: 1, sx: [...(Array.isArray(configSx) ? configSx : [configSx])], "data-cy": 'button-human', children: [' ', _jsxs(Box, { p: 1, border: 1, borderColor: "grey.300", borderRadius: 2, sx: {
143
+ return (_jsxs(Box, { sx: { maxWidth: '100%', maxHeight: '100%', overflowX: 'auto' }, children: [_jsx(Backdrop, { open: state.showModal, sx: { zIndex: (theme) => theme.zIndex.drawer + 1 }, children: state.challenge ? (_jsx(CaptchaComponent, { challenge: state.challenge, index: state.index, solutions: state.solutions, onSubmit: manager.submit, onCancel: manager.cancel, onClick: manager.select, onNext: manager.nextRound })) : (_jsx(Alert, { children: "No challenge set." })) }), _jsxs(Box, { p: 0, sx: [...(Array.isArray(configSx) ? configSx : [configSx])], "data-cy": 'button-human', children: [' ', _jsxs(Box, { p: 1, border: 1, borderColor: "grey.300", borderRadius: 2, sx: {
144
144
  display: 'flex',
145
145
  justifyContent: 'space-between',
146
146
  alignItems: 'center',
package/package.json CHANGED
@@ -1,15 +1,22 @@
1
1
  {
2
2
  "name": "@prosopo/procaptcha-react",
3
- "version": "0.1.19",
3
+ "version": "0.2.1",
4
4
  "author": "PROSOPO LIMITED <info@prosopo.io>",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
7
7
  "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/cjs/index.cjs"
12
+ }
13
+ },
8
14
  "types": "./dist/index.d.ts",
9
15
  "source": "./src/index.ts",
10
16
  "scripts": {
11
17
  "clean": "tsc --build --clean",
12
- "build": "tsc --build --verbose",
18
+ "build": "tsc --build --verbose tsconfig.json",
19
+ "build:cjs": "npx vite --config vite.cjs.config.ts build",
13
20
  "lint": "npx eslint .",
14
21
  "lint:fix": "npx eslint . --fix --config ../../.eslintrc.js"
15
22
  },
@@ -24,8 +31,8 @@
24
31
  "@polkadot/extension-dapp": "0.46.5",
25
32
  "@polkadot/extension-inject": "0.46.5",
26
33
  "@polkadot/types": "10.9.1",
27
- "@prosopo/common": "^0.1.19",
28
- "@prosopo/procaptcha": "^0.1.19",
34
+ "@prosopo/common": "0.2.1",
35
+ "@prosopo/procaptcha": "0.2.1",
29
36
  "i18next": "^21.9.2",
30
37
  "react": "^18.2.0",
31
38
  "react-dom": "^18.2.0",
@@ -0,0 +1,6 @@
1
+ import { ViteCommonJSConfig } from '@prosopo/config'
2
+ import path from 'path'
3
+
4
+ export default function () {
5
+ return ViteCommonJSConfig('procaptcha-react', path.resolve('./tsconfig.cjs.json'))
6
+ }