@alfalab/core-components-pattern-lock 1.0.0

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 (53) hide show
  1. package/Component.d.ts +14 -0
  2. package/Component.js +62 -0
  3. package/consts.d.ts +9 -0
  4. package/consts.js +30 -0
  5. package/cssm/Component.d.ts +14 -0
  6. package/cssm/Component.js +61 -0
  7. package/cssm/consts.d.ts +9 -0
  8. package/cssm/consts.js +30 -0
  9. package/cssm/index.d.ts +3 -0
  10. package/cssm/index.js +17 -0
  11. package/cssm/index.module.css +42 -0
  12. package/cssm/typings.d.ts +40 -0
  13. package/cssm/typings.js +2 -0
  14. package/cssm/utils-455c7792.d.ts +43 -0
  15. package/cssm/utils-455c7792.js +112 -0
  16. package/cssm/utils.d.ts +0 -0
  17. package/cssm/utils.js +13 -0
  18. package/cssm/vars.css +0 -0
  19. package/esm/Component.d.ts +14 -0
  20. package/esm/Component.js +53 -0
  21. package/esm/consts.d.ts +9 -0
  22. package/esm/consts.js +24 -0
  23. package/esm/index.css +43 -0
  24. package/esm/index.d.ts +3 -0
  25. package/esm/index.js +7 -0
  26. package/esm/typings.d.ts +40 -0
  27. package/esm/typings.js +1 -0
  28. package/esm/utils-0cf042c3.d.ts +43 -0
  29. package/esm/utils-0cf042c3.js +106 -0
  30. package/esm/utils.d.ts +0 -0
  31. package/esm/utils.js +2 -0
  32. package/index.css +43 -0
  33. package/index.d.ts +3 -0
  34. package/index.js +16 -0
  35. package/modern/Component.d.ts +14 -0
  36. package/modern/Component.js +49 -0
  37. package/modern/consts.d.ts +9 -0
  38. package/modern/consts.js +24 -0
  39. package/modern/index.css +43 -0
  40. package/modern/index.d.ts +3 -0
  41. package/modern/index.js +7 -0
  42. package/modern/typings.d.ts +40 -0
  43. package/modern/typings.js +1 -0
  44. package/modern/utils.d.ts +10 -0
  45. package/modern/utils.js +78 -0
  46. package/package.json +23 -0
  47. package/send-stats.js +82 -0
  48. package/typings.d.ts +40 -0
  49. package/typings.js +2 -0
  50. package/utils-e7492ab3.d.ts +43 -0
  51. package/utils-e7492ab3.js +112 -0
  52. package/utils.d.ts +0 -0
  53. package/utils.js +13 -0
package/Component.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+ import { TPatternLockInstance } from 'react-canvas-pattern-lock';
4
+ declare const PatternLock: React.ForwardRefExoticComponent<{
5
+ className?: string | undefined;
6
+ error?: React.ReactNode;
7
+ dataTestId?: string | undefined;
8
+ observeTokens?: boolean | undefined;
9
+ observerParams?: {
10
+ getTarget?: (() => Node) | undefined;
11
+ options?: MutationObserverInit | undefined;
12
+ } | undefined;
13
+ } & Omit<import("react-canvas-pattern-lock").ReactPatternLockProps, "theme" | "width" | "height" | "rows" | "cols"> & React.RefAttributes<TPatternLockInstance>>;
14
+ export { PatternLock };
package/Component.js ADDED
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('./utils-e7492ab3.js');
6
+ var React = require('react');
7
+ var reactCanvasPatternLock = require('react-canvas-pattern-lock');
8
+ var cn = require('classnames');
9
+ var coreComponentsGap = require('@alfalab/core-components-gap');
10
+ var consts = require('./consts.js');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
15
+ var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
16
+
17
+ var styles = {"component":"pattern-lock__component_1oflx","hidden":"pattern-lock__hidden_1oflx","error":"pattern-lock__error_1oflx"};
18
+ require('./index.css')
19
+
20
+ var PatternLock = React.forwardRef(function (_a, ref) {
21
+ var _b;
22
+ var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, restProps = utils.__rest(_a, ["observeTokens", "observerParams", "justifyNodes", "className", "error", "dataTestId"]);
23
+ var _f = React.useState(), params = _f[0], setParams = _f[1];
24
+ React.useEffect(function () {
25
+ var _a = utils.getSizes(), elementSizes = _a.elementSizes, width = _a.width, height = _a.height;
26
+ setParams({
27
+ theme: utils.getTheme(elementSizes),
28
+ width: width,
29
+ height: height,
30
+ });
31
+ }, []);
32
+ React.useEffect(function () {
33
+ var styleObserver = null;
34
+ if (observeTokens) {
35
+ var _a = observerParams.options, options = _a === void 0 ? consts.OBSERVE_OPTIONS : _a, _b = observerParams.getTarget, getTarget = _b === void 0 ? utils.getDefaultObserveTarget : _b;
36
+ styleObserver = new MutationObserver(function () {
37
+ return setParams(function (prevState) {
38
+ var _a = utils.getSizes(), width = _a.width, height = _a.height, elementSizes = _a.elementSizes;
39
+ if (!prevState) {
40
+ return { theme: utils.getTheme(elementSizes), width: width, height: height };
41
+ }
42
+ var prevBgColor = prevState.theme[consts.THEME_STATE.INITIAL].colors.bg;
43
+ var themeChanged = prevBgColor !== utils.getColorByToken(consts.OBSERVABLE_TOKENS.BG);
44
+ if (themeChanged)
45
+ return utils.__assign(utils.__assign({}, prevState), { theme: utils.getTheme(elementSizes) });
46
+ return prevState;
47
+ });
48
+ });
49
+ styleObserver.observe(getTarget(), options);
50
+ }
51
+ return function () { return styleObserver === null || styleObserver === void 0 ? void 0 : styleObserver.disconnect(); };
52
+ // eslint-disable-next-line react-hooks/exhaustive-deps
53
+ }, [observeTokens]);
54
+ return (React__default['default'].createElement("div", { className: cn__default['default'](styles.component, className, (_b = {}, _b[styles.hidden] = !params, _b)), "data-test-id": dataTestId },
55
+ React__default['default'].createElement(coreComponentsGap.Gap, { size: 'm' }),
56
+ React__default['default'].createElement(coreComponentsGap.Gap, { size: 's' }),
57
+ React__default['default'].createElement("div", { className: styles.error }, error),
58
+ React__default['default'].createElement(coreComponentsGap.Gap, { size: 'xl' }),
59
+ React__default['default'].createElement(reactCanvasPatternLock.ReactCanvasPatternLock, utils.__assign({}, restProps, params, { ref: ref, rows: 3, cols: 3, justifyNodes: justifyNodes }))));
60
+ });
61
+
62
+ exports.PatternLock = PatternLock;
package/consts.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { ObservableTokens } from "./typings";
2
+ declare const OBSERVE_OPTIONS: MutationObserverInit;
3
+ declare const OBSERVABLE_TOKENS: ObservableTokens;
4
+ declare const THEME_STATE: {
5
+ INITIAL: string;
6
+ SUCCESS: string;
7
+ FAILURE: string;
8
+ };
9
+ export { OBSERVE_OPTIONS, OBSERVABLE_TOKENS, THEME_STATE };
package/consts.js ADDED
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var OBSERVE_OPTIONS = {
6
+ childList: true,
7
+ attributes: false,
8
+ characterData: false,
9
+ subtree: true,
10
+ };
11
+ var OBSERVABLE_TOKENS = {
12
+ ACCENT_INITIAL: '--color-light-graphic-primary',
13
+ ACCENT_SUCCESS: '--color-light-graphic-positive',
14
+ ACCENT_FAILURE: '--color-light-graphic-negative',
15
+ PRIMARY: '--color-light-graphic-tertiary',
16
+ BG: '--color-light-bg-primary',
17
+ RING_BG_INITIAL: '--color-light-specialbg-secondary-transparent',
18
+ SELECTED_RING_BG_INITIAL: '--color-light-specialbg-tertiary-transparent',
19
+ SELECTED_RING_BG_SUCCESS: '--color-light-graphic-positive-alpha-10',
20
+ SELECTED_RING_BG_FAILURE: '--color-light-graphic-negative-alpha-10',
21
+ };
22
+ var THEME_STATE = {
23
+ INITIAL: 'initial',
24
+ SUCCESS: 'success',
25
+ FAILURE: 'failure',
26
+ };
27
+
28
+ exports.OBSERVABLE_TOKENS = OBSERVABLE_TOKENS;
29
+ exports.OBSERVE_OPTIONS = OBSERVE_OPTIONS;
30
+ exports.THEME_STATE = THEME_STATE;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+ import { TPatternLockInstance } from 'react-canvas-pattern-lock';
4
+ declare const PatternLock: React.ForwardRefExoticComponent<{
5
+ className?: string | undefined;
6
+ error?: React.ReactNode;
7
+ dataTestId?: string | undefined;
8
+ observeTokens?: boolean | undefined;
9
+ observerParams?: {
10
+ getTarget?: (() => Node) | undefined;
11
+ options?: MutationObserverInit | undefined;
12
+ } | undefined;
13
+ } & Omit<import("react-canvas-pattern-lock").ReactPatternLockProps, "theme" | "width" | "height" | "rows" | "cols"> & React.RefAttributes<TPatternLockInstance>>;
14
+ export { PatternLock };
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('./utils-455c7792.js');
6
+ var React = require('react');
7
+ var reactCanvasPatternLock = require('react-canvas-pattern-lock');
8
+ var cn = require('classnames');
9
+ var coreComponentsGap = require('@alfalab/core-components-gap/cssm');
10
+ var consts = require('./consts.js');
11
+ var styles = require('./index.module.css');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
16
+ var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
17
+ var styles__default = /*#__PURE__*/_interopDefaultLegacy(styles);
18
+
19
+ var PatternLock = React.forwardRef(function (_a, ref) {
20
+ var _b;
21
+ var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, restProps = utils.__rest(_a, ["observeTokens", "observerParams", "justifyNodes", "className", "error", "dataTestId"]);
22
+ var _f = React.useState(), params = _f[0], setParams = _f[1];
23
+ React.useEffect(function () {
24
+ var _a = utils.getSizes(), elementSizes = _a.elementSizes, width = _a.width, height = _a.height;
25
+ setParams({
26
+ theme: utils.getTheme(elementSizes),
27
+ width: width,
28
+ height: height,
29
+ });
30
+ }, []);
31
+ React.useEffect(function () {
32
+ var styleObserver = null;
33
+ if (observeTokens) {
34
+ var _a = observerParams.options, options = _a === void 0 ? consts.OBSERVE_OPTIONS : _a, _b = observerParams.getTarget, getTarget = _b === void 0 ? utils.getDefaultObserveTarget : _b;
35
+ styleObserver = new MutationObserver(function () {
36
+ return setParams(function (prevState) {
37
+ var _a = utils.getSizes(), width = _a.width, height = _a.height, elementSizes = _a.elementSizes;
38
+ if (!prevState) {
39
+ return { theme: utils.getTheme(elementSizes), width: width, height: height };
40
+ }
41
+ var prevBgColor = prevState.theme[consts.THEME_STATE.INITIAL].colors.bg;
42
+ var themeChanged = prevBgColor !== utils.getColorByToken(consts.OBSERVABLE_TOKENS.BG);
43
+ if (themeChanged)
44
+ return utils.__assign(utils.__assign({}, prevState), { theme: utils.getTheme(elementSizes) });
45
+ return prevState;
46
+ });
47
+ });
48
+ styleObserver.observe(getTarget(), options);
49
+ }
50
+ return function () { return styleObserver === null || styleObserver === void 0 ? void 0 : styleObserver.disconnect(); };
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
52
+ }, [observeTokens]);
53
+ return (React__default['default'].createElement("div", { className: cn__default['default'](styles__default['default'].component, className, (_b = {}, _b[styles__default['default'].hidden] = !params, _b)), "data-test-id": dataTestId },
54
+ React__default['default'].createElement(coreComponentsGap.Gap, { size: 'm' }),
55
+ React__default['default'].createElement(coreComponentsGap.Gap, { size: 's' }),
56
+ React__default['default'].createElement("div", { className: styles__default['default'].error }, error),
57
+ React__default['default'].createElement(coreComponentsGap.Gap, { size: 'xl' }),
58
+ React__default['default'].createElement(reactCanvasPatternLock.ReactCanvasPatternLock, utils.__assign({}, restProps, params, { ref: ref, rows: 3, cols: 3, justifyNodes: justifyNodes }))));
59
+ });
60
+
61
+ exports.PatternLock = PatternLock;
@@ -0,0 +1,9 @@
1
+ import { ObservableTokens } from "./typings";
2
+ declare const OBSERVE_OPTIONS: MutationObserverInit;
3
+ declare const OBSERVABLE_TOKENS: ObservableTokens;
4
+ declare const THEME_STATE: {
5
+ INITIAL: string;
6
+ SUCCESS: string;
7
+ FAILURE: string;
8
+ };
9
+ export { OBSERVE_OPTIONS, OBSERVABLE_TOKENS, THEME_STATE };
package/cssm/consts.js ADDED
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var OBSERVE_OPTIONS = {
6
+ childList: true,
7
+ attributes: false,
8
+ characterData: false,
9
+ subtree: true,
10
+ };
11
+ var OBSERVABLE_TOKENS = {
12
+ ACCENT_INITIAL: '--color-light-graphic-primary',
13
+ ACCENT_SUCCESS: '--color-light-graphic-positive',
14
+ ACCENT_FAILURE: '--color-light-graphic-negative',
15
+ PRIMARY: '--color-light-graphic-tertiary',
16
+ BG: '--color-light-bg-primary',
17
+ RING_BG_INITIAL: '--color-light-specialbg-secondary-transparent',
18
+ SELECTED_RING_BG_INITIAL: '--color-light-specialbg-tertiary-transparent',
19
+ SELECTED_RING_BG_SUCCESS: '--color-light-graphic-positive-alpha-10',
20
+ SELECTED_RING_BG_FAILURE: '--color-light-graphic-negative-alpha-10',
21
+ };
22
+ var THEME_STATE = {
23
+ INITIAL: 'initial',
24
+ SUCCESS: 'success',
25
+ FAILURE: 'failure',
26
+ };
27
+
28
+ exports.OBSERVABLE_TOKENS = OBSERVABLE_TOKENS;
29
+ exports.OBSERVE_OPTIONS = OBSERVE_OPTIONS;
30
+ exports.THEME_STATE = THEME_STATE;
@@ -0,0 +1,3 @@
1
+ export type { PatternLockProps } from "./typings";
2
+ export * from "./Component";
3
+ export { THEME_STATE } from "./consts";
package/cssm/index.js ADDED
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('./utils-455c7792.js');
6
+ require('react');
7
+ require('react-canvas-pattern-lock');
8
+ require('classnames');
9
+ require('@alfalab/core-components-gap/cssm');
10
+ var consts = require('./consts.js');
11
+ require('./index.module.css');
12
+ var Component = require('./Component.js');
13
+
14
+
15
+
16
+ exports.THEME_STATE = consts.THEME_STATE;
17
+ exports.PatternLock = Component.PatternLock;
@@ -0,0 +1,42 @@
1
+ :root {
2
+ --color-light-text-negative: #d91d0b;
3
+ }
4
+ :root {
5
+
6
+ /* Hard */
7
+
8
+ /* Up */
9
+
10
+ /* Hard up */
11
+ }
12
+ :root {
13
+ --gap-xs: 8px;
14
+ --gap-m: 16px;
15
+ --gap-xl: 24px;
16
+ }
17
+ :root {
18
+ --pattern-lock-max-width: 500px;
19
+ }
20
+ .component {
21
+ max-width: var(--pattern-lock-max-width);
22
+ margin: var(--gap-xs) 0 var(--gap-xl) 0
23
+ }
24
+ .component canvas {
25
+ display: block;
26
+ margin: 0 auto;
27
+ }
28
+ .hidden {
29
+ visibility: hidden;
30
+ }
31
+ .error {
32
+ font-size: 16px;
33
+ line-height: 24px;
34
+ font-weight: 400;
35
+
36
+ display: flex;
37
+ justify-content: center;
38
+ align-items: center;
39
+ padding: 0 var(--gap-m);
40
+ min-height: 24px;
41
+ color: var(--color-light-text-negative);
42
+ }
@@ -0,0 +1,40 @@
1
+ import { ReactNode } from 'react';
2
+ import { ReactPatternLockProps } from 'react-canvas-pattern-lock';
3
+ type PatternLockProps = {
4
+ /**
5
+ * Дополнительный класс.
6
+ */
7
+ className?: string;
8
+ /**
9
+ * Сообщение об ошибке
10
+ */
11
+ error?: ReactNode;
12
+ /**
13
+ * Идентификатор для систем автоматизированного тестирования.
14
+ */
15
+ dataTestId?: string;
16
+ /**
17
+ * Следить ли за изменениями значений цветовых токенов.
18
+ * @default false
19
+ */
20
+ observeTokens?: boolean;
21
+ /**
22
+ * Параметры MutationObserver для наблюдения за изменениями режима(css custom properties).
23
+ */
24
+ observerParams?: {
25
+ getTarget?: () => Node;
26
+ options?: MutationObserverInit;
27
+ };
28
+ } & Omit<ReactPatternLockProps, 'theme' | 'width' | 'height' | 'rows' | 'cols'>;
29
+ type ObservableTokens = {
30
+ ACCENT_INITIAL: string;
31
+ ACCENT_SUCCESS: string;
32
+ ACCENT_FAILURE: string;
33
+ RING_BG_INITIAL: string;
34
+ SELECTED_RING_BG_INITIAL: string;
35
+ SELECTED_RING_BG_SUCCESS: string;
36
+ SELECTED_RING_BG_FAILURE: string;
37
+ PRIMARY: string;
38
+ BG: string;
39
+ };
40
+ export { PatternLockProps, ObservableTokens };
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,43 @@
1
+ import { Theme, ThemeParams } from 'react-canvas-pattern-lock';
2
+ declare function __extends(d: any, b: any): void;
3
+ declare function __rest(s: any, e: any): {};
4
+ declare function __decorate(decorators: any, target: any, key: any, desc: any, ...args: any[]): any;
5
+ declare function __param(paramIndex: any, decorator: any): (target: any, key: any) => void;
6
+ declare function __metadata(metadataKey: any, metadataValue: any): any;
7
+ declare function __awaiter(thisArg: any, _arguments: any, P: any, generator: any): any;
8
+ declare function __generator(thisArg: any, body: any): {
9
+ next: (v: any) => any;
10
+ throw: (v: any) => any;
11
+ return: (v: any) => any;
12
+ };
13
+ declare function __exportStar(m: any, o: any): void;
14
+ declare function __values(o: any): any;
15
+ declare function __read(o: any, n: any): any;
16
+ declare function __spread(...args: any[]): any[];
17
+ declare function __spreadArrays(...args: any[]): any[];
18
+ declare function __spreadArray(to: any, from: any, pack: any, ...args: any[]): any;
19
+ declare function __await(v: any): __await;
20
+ declare class __await {
21
+ constructor(v: any);
22
+ v: any;
23
+ }
24
+ declare function __asyncGenerator(thisArg: any, _arguments: any, generator: any): {};
25
+ declare function __asyncDelegator(o: any): {};
26
+ declare function __asyncValues(o: any): any;
27
+ declare function __makeTemplateObject(cooked: any, raw: any): any;
28
+ declare function __importStar(mod: any): any;
29
+ declare function __importDefault(mod: any): any;
30
+ declare function __classPrivateFieldGet(receiver: any, state: any, kind: any, f: any): any;
31
+ declare function __classPrivateFieldSet(receiver: any, state: any, value: any, kind: any, f: any): any;
32
+ declare function __classPrivateFieldIn(state: any, receiver: any): any;
33
+ declare function __assign(...args: any[]): any;
34
+ declare function __createBinding(o: any, m: any, k: any, k2: any): void;
35
+ declare function getDefaultObserveTarget(): HTMLHeadElement;
36
+ declare function getColorByToken(token: string): string;
37
+ declare const getSizes: () => {
38
+ elementSizes: ThemeParams['dimens'];
39
+ width: number;
40
+ height: number;
41
+ };
42
+ declare function getTheme(dimens: ThemeParams['dimens']): Theme;
43
+ export { __extends, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __spreadArray, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault, __classPrivateFieldGet, __classPrivateFieldSet, __classPrivateFieldIn, __assign, __createBinding, getDefaultObserveTarget, getColorByToken, getSizes, getTheme };
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ var consts = require('./consts.js');
4
+
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ exports.__assign = function () {
20
+ exports.__assign = Object.assign || function __assign(t) {
21
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
22
+ s = arguments[i];
23
+ for (var p in s)
24
+ if (Object.prototype.hasOwnProperty.call(s, p))
25
+ t[p] = s[p];
26
+ }
27
+ return t;
28
+ };
29
+ return exports.__assign.apply(this, arguments);
30
+ };
31
+ function __rest(s, e) {
32
+ var t = {};
33
+ for (var p in s)
34
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
35
+ t[p] = s[p];
36
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
37
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
38
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
39
+ t[p[i]] = s[p[i]];
40
+ }
41
+ return t;
42
+ }
43
+
44
+ function getDefaultObserveTarget() {
45
+ return document.head;
46
+ }
47
+ function getColorByToken(token) {
48
+ return getComputedStyle(document.documentElement).getPropertyValue(token);
49
+ }
50
+ var getSizes = (function () {
51
+ var COMMON_SIZES = {
52
+ lineWidth: 6,
53
+ nodeRing: 0,
54
+ nodeCore: 12,
55
+ };
56
+ var cachedSize;
57
+ return function () {
58
+ if (cachedSize) {
59
+ return cachedSize;
60
+ }
61
+ if (window.matchMedia('(min-width: 390px)').matches) {
62
+ cachedSize = {
63
+ elementSizes: exports.__assign(exports.__assign({}, COMMON_SIZES), { nodeRadius: 43 }),
64
+ width: 322,
65
+ height: 322,
66
+ };
67
+ }
68
+ else if (window.matchMedia('(min-width: 360px)').matches) {
69
+ cachedSize = {
70
+ elementSizes: exports.__assign(exports.__assign({}, COMMON_SIZES), { nodeRadius: 38 }),
71
+ width: 292,
72
+ height: 292,
73
+ };
74
+ }
75
+ else {
76
+ cachedSize = {
77
+ elementSizes: exports.__assign(exports.__assign({}, COMMON_SIZES), { nodeRadius: 32 }),
78
+ width: 240,
79
+ height: 240,
80
+ };
81
+ }
82
+ return cachedSize;
83
+ };
84
+ })();
85
+ function getTheme(dimens) {
86
+ var _a;
87
+ var baseColors = {
88
+ primary: getColorByToken(consts.OBSERVABLE_TOKENS.PRIMARY),
89
+ bg: getColorByToken(consts.OBSERVABLE_TOKENS.BG),
90
+ ringBg: getColorByToken(consts.OBSERVABLE_TOKENS.RING_BG_INITIAL),
91
+ };
92
+ return _a = {},
93
+ _a[consts.THEME_STATE.INITIAL] = {
94
+ colors: exports.__assign(exports.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_INITIAL), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_INITIAL) }),
95
+ dimens: dimens,
96
+ },
97
+ _a[consts.THEME_STATE.SUCCESS] = {
98
+ colors: exports.__assign(exports.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_SUCCESS), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_SUCCESS) }),
99
+ dimens: dimens,
100
+ },
101
+ _a[consts.THEME_STATE.FAILURE] = {
102
+ colors: exports.__assign(exports.__assign({}, baseColors), { accent: getColorByToken(consts.OBSERVABLE_TOKENS.ACCENT_FAILURE), selectedRingBg: getColorByToken(consts.OBSERVABLE_TOKENS.SELECTED_RING_BG_FAILURE) }),
103
+ dimens: dimens,
104
+ },
105
+ _a;
106
+ }
107
+
108
+ exports.__rest = __rest;
109
+ exports.getColorByToken = getColorByToken;
110
+ exports.getDefaultObserveTarget = getDefaultObserveTarget;
111
+ exports.getSizes = getSizes;
112
+ exports.getTheme = getTheme;
File without changes
package/cssm/utils.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('./utils-455c7792.js');
6
+ require('./consts.js');
7
+
8
+
9
+
10
+ exports.getColorByToken = utils.getColorByToken;
11
+ exports.getDefaultObserveTarget = utils.getDefaultObserveTarget;
12
+ exports.getSizes = utils.getSizes;
13
+ exports.getTheme = utils.getTheme;
package/cssm/vars.css ADDED
File without changes
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+ import { TPatternLockInstance } from 'react-canvas-pattern-lock';
4
+ declare const PatternLock: React.ForwardRefExoticComponent<{
5
+ className?: string | undefined;
6
+ error?: React.ReactNode;
7
+ dataTestId?: string | undefined;
8
+ observeTokens?: boolean | undefined;
9
+ observerParams?: {
10
+ getTarget?: (() => Node) | undefined;
11
+ options?: MutationObserverInit | undefined;
12
+ } | undefined;
13
+ } & Omit<import("react-canvas-pattern-lock").ReactPatternLockProps, "theme" | "width" | "height" | "rows" | "cols"> & React.RefAttributes<TPatternLockInstance>>;
14
+ export { PatternLock };
@@ -0,0 +1,53 @@
1
+ import { _ as __rest, g as getSizes, a as getTheme, b as getColorByToken, c as __assign, d as getDefaultObserveTarget } from './utils-0cf042c3.js';
2
+ import React, { forwardRef, useState, useEffect } from 'react';
3
+ import { ReactCanvasPatternLock } from 'react-canvas-pattern-lock';
4
+ import cn from 'classnames';
5
+ import { Gap } from '@alfalab/core-components-gap/esm';
6
+ import { THEME_STATE, OBSERVABLE_TOKENS, OBSERVE_OPTIONS } from './consts.js';
7
+
8
+ var styles = {"component":"pattern-lock__component_1oflx","hidden":"pattern-lock__hidden_1oflx","error":"pattern-lock__error_1oflx"};
9
+ require('./index.css')
10
+
11
+ var PatternLock = forwardRef(function (_a, ref) {
12
+ var _b;
13
+ var _c = _a.observeTokens, observeTokens = _c === void 0 ? false : _c, _d = _a.observerParams, observerParams = _d === void 0 ? {} : _d, _e = _a.justifyNodes, justifyNodes = _e === void 0 ? 'space-between' : _e, className = _a.className, error = _a.error, dataTestId = _a.dataTestId, restProps = __rest(_a, ["observeTokens", "observerParams", "justifyNodes", "className", "error", "dataTestId"]);
14
+ var _f = useState(), params = _f[0], setParams = _f[1];
15
+ useEffect(function () {
16
+ var _a = getSizes(), elementSizes = _a.elementSizes, width = _a.width, height = _a.height;
17
+ setParams({
18
+ theme: getTheme(elementSizes),
19
+ width: width,
20
+ height: height,
21
+ });
22
+ }, []);
23
+ useEffect(function () {
24
+ var styleObserver = null;
25
+ if (observeTokens) {
26
+ var _a = observerParams.options, options = _a === void 0 ? OBSERVE_OPTIONS : _a, _b = observerParams.getTarget, getTarget = _b === void 0 ? getDefaultObserveTarget : _b;
27
+ styleObserver = new MutationObserver(function () {
28
+ return setParams(function (prevState) {
29
+ var _a = getSizes(), width = _a.width, height = _a.height, elementSizes = _a.elementSizes;
30
+ if (!prevState) {
31
+ return { theme: getTheme(elementSizes), width: width, height: height };
32
+ }
33
+ var prevBgColor = prevState.theme[THEME_STATE.INITIAL].colors.bg;
34
+ var themeChanged = prevBgColor !== getColorByToken(OBSERVABLE_TOKENS.BG);
35
+ if (themeChanged)
36
+ return __assign(__assign({}, prevState), { theme: getTheme(elementSizes) });
37
+ return prevState;
38
+ });
39
+ });
40
+ styleObserver.observe(getTarget(), options);
41
+ }
42
+ return function () { return styleObserver === null || styleObserver === void 0 ? void 0 : styleObserver.disconnect(); };
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ }, [observeTokens]);
45
+ return (React.createElement("div", { className: cn(styles.component, className, (_b = {}, _b[styles.hidden] = !params, _b)), "data-test-id": dataTestId },
46
+ React.createElement(Gap, { size: 'm' }),
47
+ React.createElement(Gap, { size: 's' }),
48
+ React.createElement("div", { className: styles.error }, error),
49
+ React.createElement(Gap, { size: 'xl' }),
50
+ React.createElement(ReactCanvasPatternLock, __assign({}, restProps, params, { ref: ref, rows: 3, cols: 3, justifyNodes: justifyNodes }))));
51
+ });
52
+
53
+ export { PatternLock };
@@ -0,0 +1,9 @@
1
+ import { ObservableTokens } from "./typings";
2
+ declare const OBSERVE_OPTIONS: MutationObserverInit;
3
+ declare const OBSERVABLE_TOKENS: ObservableTokens;
4
+ declare const THEME_STATE: {
5
+ INITIAL: string;
6
+ SUCCESS: string;
7
+ FAILURE: string;
8
+ };
9
+ export { OBSERVE_OPTIONS, OBSERVABLE_TOKENS, THEME_STATE };
package/esm/consts.js ADDED
@@ -0,0 +1,24 @@
1
+ var OBSERVE_OPTIONS = {
2
+ childList: true,
3
+ attributes: false,
4
+ characterData: false,
5
+ subtree: true,
6
+ };
7
+ var OBSERVABLE_TOKENS = {
8
+ ACCENT_INITIAL: '--color-light-graphic-primary',
9
+ ACCENT_SUCCESS: '--color-light-graphic-positive',
10
+ ACCENT_FAILURE: '--color-light-graphic-negative',
11
+ PRIMARY: '--color-light-graphic-tertiary',
12
+ BG: '--color-light-bg-primary',
13
+ RING_BG_INITIAL: '--color-light-specialbg-secondary-transparent',
14
+ SELECTED_RING_BG_INITIAL: '--color-light-specialbg-tertiary-transparent',
15
+ SELECTED_RING_BG_SUCCESS: '--color-light-graphic-positive-alpha-10',
16
+ SELECTED_RING_BG_FAILURE: '--color-light-graphic-negative-alpha-10',
17
+ };
18
+ var THEME_STATE = {
19
+ INITIAL: 'initial',
20
+ SUCCESS: 'success',
21
+ FAILURE: 'failure',
22
+ };
23
+
24
+ export { OBSERVABLE_TOKENS, OBSERVE_OPTIONS, THEME_STATE };