etudes 5.2.0 → 5.3.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.
- package/components/Accordion.js +171 -205
- package/components/BurgerButton.js +40 -94
- package/components/Carousel.js +87 -123
- package/components/Collection.js +84 -120
- package/components/Counter.js +32 -63
- package/components/CoverImage.js +24 -68
- package/components/CoverVideo.js +25 -69
- package/components/DebugConsole.js +27 -79
- package/components/Dial.js +28 -65
- package/components/Dropdown.js +86 -98
- package/components/FlatSVG.js +22 -71
- package/components/Image.js +21 -50
- package/components/MasonryGrid.js +122 -257
- package/components/Panorama.js +48 -92
- package/components/PanoramaSlider.js +57 -113
- package/components/RangeSlider.js +125 -182
- package/components/RotatingGallery.js +28 -59
- package/components/SelectableButton.js +10 -54
- package/components/Slider.js +108 -159
- package/components/StepwiseSlider.js +124 -176
- package/components/SwipeContainer.js +30 -73
- package/components/TextField.js +12 -49
- package/components/Video.js +31 -61
- package/components/WithTooltip.js +117 -111
- package/components/index.js +24 -0
- package/hooks/index.js +17 -0
- package/hooks/useClickOutsideEffect.js +8 -38
- package/hooks/useDragEffect.js +20 -53
- package/hooks/useDragValueEffect.js +31 -81
- package/hooks/useImageSize.js +16 -38
- package/hooks/useInterval.js +9 -41
- package/hooks/useLoadImageEffect.js +15 -48
- package/hooks/useLoadVideoMetadataEffect.js +15 -48
- package/hooks/useMounted.js +5 -25
- package/hooks/usePrevious.js +4 -9
- package/hooks/useRect.js +9 -29
- package/hooks/useResizeEffect.js +10 -44
- package/hooks/useScrollPositionEffect.js +19 -50
- package/hooks/useSearchParamState.js +12 -34
- package/hooks/useSize.js +9 -29
- package/hooks/useTimeout.js +8 -38
- package/hooks/useVideoSize.js +16 -38
- package/hooks/useViewportSize.js +7 -27
- package/operators/Conditional.js +6 -11
- package/operators/Each.js +6 -14
- package/operators/ExtractChild.js +9 -36
- package/operators/ExtractChildren.js +7 -34
- package/operators/Repeat.js +4 -37
- package/operators/index.js +5 -0
- package/package.json +27 -41
- package/providers/ScrollPositionProvider.js +37 -60
- package/providers/index.js +1 -0
- package/utils/asClassNameDict.js +1 -5
- package/utils/asComponentDict.js +11 -16
- package/utils/asStyleDict.js +1 -5
- package/utils/cloneStyledElement.js +14 -61
- package/utils/index.js +5 -22
- package/utils/styles.js +5 -21
- package/components/Accordion.d.ts +0 -219
- package/components/Accordion.js.map +0 -1
- package/components/BurgerButton.d.ts +0 -34
- package/components/BurgerButton.js.map +0 -1
- package/components/Carousel.d.ts +0 -53
- package/components/Carousel.js.map +0 -1
- package/components/Collection.d.ts +0 -171
- package/components/Collection.js.map +0 -1
- package/components/Counter.d.ts +0 -11
- package/components/Counter.js.map +0 -1
- package/components/CoverImage.d.ts +0 -28
- package/components/CoverImage.js.map +0 -1
- package/components/CoverVideo.d.ts +0 -28
- package/components/CoverVideo.js.map +0 -1
- package/components/DebugConsole.d.ts +0 -15
- package/components/DebugConsole.js.map +0 -1
- package/components/Dial.d.ts +0 -79
- package/components/Dial.js.map +0 -1
- package/components/Dropdown.d.ts +0 -109
- package/components/Dropdown.js.map +0 -1
- package/components/FlatSVG.d.ts +0 -72
- package/components/FlatSVG.js.map +0 -1
- package/components/Image.d.ts +0 -144
- package/components/Image.js.map +0 -1
- package/components/MasonryGrid.d.ts +0 -29
- package/components/MasonryGrid.js.map +0 -1
- package/components/Panorama.d.ts +0 -77
- package/components/Panorama.js.map +0 -1
- package/components/PanoramaSlider.d.ts +0 -71
- package/components/PanoramaSlider.js.map +0 -1
- package/components/RangeSlider.d.ts +0 -34
- package/components/RangeSlider.js.map +0 -1
- package/components/RotatingGallery.d.ts +0 -91
- package/components/RotatingGallery.js.map +0 -1
- package/components/SelectableButton.d.ts +0 -19
- package/components/SelectableButton.js.map +0 -1
- package/components/Slider.d.ts +0 -160
- package/components/Slider.js.map +0 -1
- package/components/StepwiseSlider.d.ts +0 -215
- package/components/StepwiseSlider.js.map +0 -1
- package/components/SwipeContainer.d.ts +0 -21
- package/components/SwipeContainer.js.map +0 -1
- package/components/TextField.d.ts +0 -21
- package/components/TextField.js.map +0 -1
- package/components/Video.d.ts +0 -38
- package/components/Video.js.map +0 -1
- package/components/WithTooltip.d.ts +0 -32
- package/components/WithTooltip.js.map +0 -1
- package/hooks/useClickOutsideEffect.d.ts +0 -2
- package/hooks/useClickOutsideEffect.js.map +0 -1
- package/hooks/useDragEffect.d.ts +0 -48
- package/hooks/useDragEffect.js.map +0 -1
- package/hooks/useDragValueEffect.d.ts +0 -56
- package/hooks/useDragValueEffect.js.map +0 -1
- package/hooks/useImageSize.d.ts +0 -21
- package/hooks/useImageSize.js.map +0 -1
- package/hooks/useInterval.d.ts +0 -18
- package/hooks/useInterval.js.map +0 -1
- package/hooks/useLoadImageEffect.d.ts +0 -43
- package/hooks/useLoadImageEffect.js.map +0 -1
- package/hooks/useLoadVideoMetadataEffect.d.ts +0 -35
- package/hooks/useLoadVideoMetadataEffect.js.map +0 -1
- package/hooks/useMounted.d.ts +0 -1
- package/hooks/useMounted.js.map +0 -1
- package/hooks/usePrevious.d.ts +0 -19
- package/hooks/usePrevious.js.map +0 -1
- package/hooks/useRect.d.ts +0 -11
- package/hooks/useRect.js.map +0 -1
- package/hooks/useResizeEffect.d.ts +0 -17
- package/hooks/useResizeEffect.js.map +0 -1
- package/hooks/useScrollPositionEffect.d.ts +0 -13
- package/hooks/useScrollPositionEffect.js.map +0 -1
- package/hooks/useSearchParamState.d.ts +0 -34
- package/hooks/useSearchParamState.js.map +0 -1
- package/hooks/useSize.d.ts +0 -10
- package/hooks/useSize.js.map +0 -1
- package/hooks/useTimeout.d.ts +0 -10
- package/hooks/useTimeout.js.map +0 -1
- package/hooks/useVideoSize.d.ts +0 -21
- package/hooks/useVideoSize.js.map +0 -1
- package/hooks/useViewportSize.d.ts +0 -7
- package/hooks/useViewportSize.js.map +0 -1
- package/operators/Conditional.d.ts +0 -5
- package/operators/Conditional.js.map +0 -1
- package/operators/Each.d.ts +0 -7
- package/operators/Each.js.map +0 -1
- package/operators/ExtractChild.d.ts +0 -8
- package/operators/ExtractChild.js.map +0 -1
- package/operators/ExtractChildren.d.ts +0 -6
- package/operators/ExtractChildren.js.map +0 -1
- package/operators/Repeat.d.ts +0 -11
- package/operators/Repeat.js.map +0 -1
- package/providers/ScrollPositionProvider.d.ts +0 -15
- package/providers/ScrollPositionProvider.js.map +0 -1
- package/utils/asClassNameDict.d.ts +0 -3
- package/utils/asClassNameDict.js.map +0 -1
- package/utils/asComponentDict.d.ts +0 -5
- package/utils/asComponentDict.js.map +0 -1
- package/utils/asStyleDict.d.ts +0 -4
- package/utils/asStyleDict.js.map +0 -1
- package/utils/cloneStyledElement.d.ts +0 -18
- package/utils/cloneStyledElement.js.map +0 -1
- package/utils/index.d.ts +0 -5
- package/utils/index.js.map +0 -1
- package/utils/styles.d.ts +0 -2
- package/utils/styles.js.map +0 -1
|
@@ -1,52 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ExtractChild = void 0;
|
|
26
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
27
|
-
var react_1 = require("react");
|
|
28
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, forwardRef, isValidElement } from 'react';
|
|
3
|
+
import { cloneStyledElement } from '../utils/index.js';
|
|
29
4
|
/**
|
|
30
5
|
* Extracts a single child of a parent component into its own component. If the
|
|
31
6
|
* parent component has multiple children, only the first one will be extracted,
|
|
32
7
|
* the rest will be ignored.
|
|
33
8
|
*/
|
|
34
|
-
|
|
35
|
-
var children = _a.children, props = __rest(_a, ["children"]);
|
|
9
|
+
export const ExtractChild = forwardRef(({ children, ...props }, ref) => {
|
|
36
10
|
if (Array.isArray(children)) {
|
|
37
|
-
console.error(
|
|
11
|
+
console.error(`[etudes::ExtractChild] Only one child is expected, but found ${children.length}. Only the first child is extracted while the rest are discarded.`);
|
|
38
12
|
}
|
|
39
|
-
return ((
|
|
13
|
+
return (_jsx(_Fragment, { children: Children.map(children, (child, idx) => {
|
|
40
14
|
if (idx > 0) {
|
|
41
15
|
return undefined;
|
|
42
16
|
}
|
|
43
|
-
else if (
|
|
44
|
-
return
|
|
17
|
+
else if (isValidElement(child)) {
|
|
18
|
+
return cloneStyledElement(child, { ...props, ref });
|
|
45
19
|
}
|
|
46
20
|
else {
|
|
47
21
|
return child;
|
|
48
22
|
}
|
|
49
23
|
}) }));
|
|
50
24
|
});
|
|
51
|
-
Object.defineProperty(
|
|
52
|
-
//# sourceMappingURL=ExtractChild.js.map
|
|
25
|
+
Object.defineProperty(ExtractChild, 'displayName', { value: 'ExtractChild', writable: false });
|
|
@@ -1,39 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ExtractChildren = ExtractChildren;
|
|
26
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
27
|
-
var react_1 = require("react");
|
|
28
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, isValidElement } from 'react';
|
|
3
|
+
import { cloneStyledElement } from '../utils/index.js';
|
|
29
4
|
/**
|
|
30
5
|
* Extracts all children of a parent component into its own component.
|
|
31
6
|
*/
|
|
32
|
-
function ExtractChildren(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return (0, utils_1.cloneStyledElement)(child, __assign({}, props));
|
|
7
|
+
export function ExtractChildren({ children, ...props }) {
|
|
8
|
+
return (_jsx(_Fragment, { children: Children.map(children, child => {
|
|
9
|
+
if (isValidElement(child)) {
|
|
10
|
+
return cloneStyledElement(child, { ...props });
|
|
37
11
|
}
|
|
38
12
|
else {
|
|
39
13
|
return child;
|
|
@@ -41,4 +15,3 @@ function ExtractChildren(_a) {
|
|
|
41
15
|
}) }));
|
|
42
16
|
}
|
|
43
17
|
Object.defineProperty(ExtractChildren, 'displayName', { value: 'ExtractChildren', writable: false });
|
|
44
|
-
//# sourceMappingURL=ExtractChildren.js.map
|
package/operators/Repeat.js
CHANGED
|
@@ -1,43 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.Repeat = Repeat;
|
|
29
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
|
-
var react_1 = require("react");
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
31
3
|
/**
|
|
32
4
|
* A tag-less component that repeats its children, automatically assigning each
|
|
33
5
|
* a unique key.
|
|
34
6
|
*/
|
|
35
|
-
function Repeat(
|
|
36
|
-
|
|
37
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: __spreadArray([], __read(Array(count)), false).map(function (v, i) {
|
|
38
|
-
var _a;
|
|
39
|
-
return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: (_a = render === null || render === void 0 ? void 0 : render(i)) !== null && _a !== void 0 ? _a : (typeof children === 'function' ? children(i) : children) }, "element-".concat(i)));
|
|
40
|
-
}) }));
|
|
7
|
+
export function Repeat({ count = 1, children, render, }) {
|
|
8
|
+
return (_jsx(_Fragment, { children: [...Array(count)].map((v, i) => (_jsx(Fragment, { children: render?.(i) ?? (typeof children === 'function' ? children(i) : children) }, `element-${i}`))) }));
|
|
41
9
|
}
|
|
42
10
|
Object.defineProperty(Repeat, 'displayName', { value: 'Repeat', writable: false });
|
|
43
|
-
//# sourceMappingURL=Repeat.js.map
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "etudes",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "A study of headless React components",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"clean": "rimraf lib",
|
|
7
8
|
"prebuild": "npm run lint && npm run clean",
|
|
8
|
-
"build": "
|
|
9
|
+
"build": "tsc",
|
|
9
10
|
"pages": "rimraf .gh-pages && webpack --config demo/config/build.conf.ts",
|
|
10
|
-
"
|
|
11
|
-
"demo": "concurrently \"cross-env NODE_ENV=production tsc -w --diagnostics false\" \"wait-on lib && cross-env NODE_ENV=development webpack-cli serve --mode development --hot --config demo/config/build.conf.ts\"",
|
|
11
|
+
"dev": "concurrently \"tsc -w\" \"wait-on -t 30s lib && vite dev -c demo/vite.config.ts --port 8080\"",
|
|
12
12
|
"test": "echo \"No tests yet :)\"",
|
|
13
13
|
"lint": "eslint",
|
|
14
|
-
"lint:fix": "
|
|
15
|
-
"scan": "dotenv -- sh -c 'sonar-scanner -Dsonar.projectKey=$SONAR_PROJECT_KEY -Dsonar.sources=. -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.token=$SONAR_TOKEN'"
|
|
14
|
+
"lint:fix": "eslint --fix"
|
|
16
15
|
},
|
|
17
16
|
"repository": {
|
|
18
17
|
"type": "git",
|
|
@@ -34,59 +33,46 @@
|
|
|
34
33
|
"utils"
|
|
35
34
|
],
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@babel/plugin-transform-runtime": "^7.24.7",
|
|
39
|
-
"@babel/preset-env": "^7.24.7",
|
|
40
|
-
"@babel/preset-react": "^7.24.7",
|
|
41
|
-
"@babel/preset-typescript": "^7.24.7",
|
|
42
|
-
"@eslint/js": "^9.5.0",
|
|
36
|
+
"@eslint/js": "^9.9.1",
|
|
43
37
|
"@semantic-release/changelog": "^6.0.3",
|
|
44
38
|
"@semantic-release/git": "^10.0.1",
|
|
45
|
-
"@stylistic/eslint-plugin": "^2.
|
|
39
|
+
"@stylistic/eslint-plugin": "^2.7.2",
|
|
46
40
|
"@types/debug": "^4.1.12",
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/react": "^18.3.3",
|
|
41
|
+
"@types/node": "^22.5.4",
|
|
42
|
+
"@types/react": "^18.3.5",
|
|
50
43
|
"@types/react-dom": "^18.3.0",
|
|
51
44
|
"@types/styled-components": "^5.1.34",
|
|
52
|
-
"@
|
|
53
|
-
"@types/webpack-env": "^1.18.5",
|
|
54
|
-
"babel-loader": "^9.1.3",
|
|
55
|
-
"babel-plugin-styled-components": "^2.1.4",
|
|
45
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
56
46
|
"concurrently": "^8.2.2",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"dotenv-cli": "^7.4.2",
|
|
60
|
-
"eslint": "^9.5.0",
|
|
61
|
-
"html-webpack-plugin": "^5.6.0",
|
|
47
|
+
"debug": "^4.3.6",
|
|
48
|
+
"eslint": "^9.9.1",
|
|
62
49
|
"react": "^18.3.1",
|
|
63
50
|
"react-dom": "^18.3.1",
|
|
64
|
-
"react-router": "^6.
|
|
65
|
-
"react-router-dom": "^6.
|
|
66
|
-
"rimraf": "^
|
|
67
|
-
"semantic-release": "^24.
|
|
68
|
-
"styled-components": "^6.1.
|
|
69
|
-
"
|
|
70
|
-
"typescript": "^5.5.
|
|
71
|
-
"typescript-eslint": "^8.
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"webpack-dev-server": "^5.0.4"
|
|
51
|
+
"react-router": "^6.26.1",
|
|
52
|
+
"react-router-dom": "^6.26.1",
|
|
53
|
+
"rimraf": "^6.0.1",
|
|
54
|
+
"semantic-release": "^24.1.0",
|
|
55
|
+
"styled-components": "^6.1.13",
|
|
56
|
+
"tsx": "^4.19.0",
|
|
57
|
+
"typescript": "^5.5.4",
|
|
58
|
+
"typescript-eslint": "^8.4.0",
|
|
59
|
+
"vite": "^5.4.3",
|
|
60
|
+
"vite-plugin-dts": "^4.1.0",
|
|
61
|
+
"wait-on": "^8.0.0"
|
|
76
62
|
},
|
|
77
63
|
"dependencies": {
|
|
78
64
|
"clsx": "^2.1.1",
|
|
79
65
|
"fast-deep-equal": "^3.1.3",
|
|
80
|
-
"fast-xml-parser": "^4.
|
|
66
|
+
"fast-xml-parser": "^4.5.0",
|
|
81
67
|
"interactjs": "^1.10.27",
|
|
82
68
|
"resize-observer-polyfill": "^1.5.1",
|
|
83
|
-
"spase": "^
|
|
69
|
+
"spase": "^8.0.3"
|
|
84
70
|
},
|
|
85
71
|
"peerDependencies": {
|
|
86
72
|
"react": "^18.2.0"
|
|
87
73
|
},
|
|
88
74
|
"optionalDependencies": {
|
|
89
|
-
"react-router": "^6.
|
|
90
|
-
"react-router-dom": "^6.
|
|
75
|
+
"react-router": "^6.26.1",
|
|
76
|
+
"react-router-dom": "^6.26.1"
|
|
91
77
|
}
|
|
92
78
|
}
|
|
@@ -1,66 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.ScrollPositionContext = void 0;
|
|
20
|
-
exports.ScrollPositionProvider = ScrollPositionProvider;
|
|
21
|
-
exports.useScrollPosition = useScrollPosition;
|
|
22
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
23
|
-
var react_1 = require("react");
|
|
24
|
-
var spase_1 = require("spase");
|
|
25
|
-
exports.ScrollPositionContext = (0, react_1.createContext)(undefined);
|
|
26
|
-
function ScrollPositionProvider(_a) {
|
|
27
|
-
var children = _a.children;
|
|
28
|
-
var _b = __read((0, react_1.useState)({
|
|
29
|
-
minPos: new spase_1.Point(),
|
|
30
|
-
maxPos: new spase_1.Point(),
|
|
31
|
-
pos: new spase_1.Point(),
|
|
32
|
-
step: new spase_1.Point(),
|
|
33
|
-
}), 2), value = _b[0], setValue = _b[1];
|
|
34
|
-
(0, react_1.useEffect)(function () {
|
|
35
|
-
var updateScrollPosition = function () {
|
|
36
|
-
var refRect = spase_1.Rect.fromViewport();
|
|
37
|
-
var refRectMin = refRect.clone({ x: 0, y: 0 });
|
|
38
|
-
var refRectFull = spase_1.Rect.from(window, { overflow: true });
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useState } from 'react';
|
|
3
|
+
import { Point, Rect } from 'spase';
|
|
4
|
+
export const ScrollPositionContext = createContext(undefined);
|
|
5
|
+
export function ScrollPositionProvider({ children, }) {
|
|
6
|
+
const [value, setValue] = useState({
|
|
7
|
+
minPos: new Point(),
|
|
8
|
+
maxPos: new Point(),
|
|
9
|
+
pos: new Point(),
|
|
10
|
+
step: new Point(),
|
|
11
|
+
});
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const updateScrollPosition = () => {
|
|
14
|
+
const refRect = Rect.fromViewport();
|
|
15
|
+
const refRectMin = refRect.clone({ x: 0, y: 0 });
|
|
16
|
+
const refRectFull = Rect.from(window, { overflow: true });
|
|
39
17
|
if (!refRectFull)
|
|
40
18
|
return;
|
|
41
|
-
|
|
42
|
-
|
|
19
|
+
const refRectMax = refRectMin.clone({ x: refRectFull.width - refRect.width, y: refRectFull.height - refRect.height });
|
|
20
|
+
const step = new Point([refRect.left / refRectMax.left, refRect.top / refRectMax.top]);
|
|
43
21
|
setValue({
|
|
44
|
-
minPos: new
|
|
45
|
-
maxPos: new
|
|
46
|
-
pos: new
|
|
47
|
-
step
|
|
22
|
+
minPos: new Point([refRectMin.left, refRectMin.top]),
|
|
23
|
+
maxPos: new Point([refRectMax.left, refRectMax.top]),
|
|
24
|
+
pos: new Point([refRect.left, refRect.top]),
|
|
25
|
+
step,
|
|
48
26
|
});
|
|
49
27
|
};
|
|
50
28
|
window.addEventListener('scroll', updateScrollPosition);
|
|
51
29
|
window.addEventListener('resize', updateScrollPosition);
|
|
52
30
|
window.addEventListener('orientationchange', updateScrollPosition);
|
|
53
31
|
updateScrollPosition();
|
|
54
|
-
return
|
|
32
|
+
return () => {
|
|
55
33
|
window.removeEventListener('scroll', updateScrollPosition);
|
|
56
34
|
window.removeEventListener('resize', updateScrollPosition);
|
|
57
35
|
window.removeEventListener('orientationchange', updateScrollPosition);
|
|
58
36
|
};
|
|
59
37
|
}, []);
|
|
60
|
-
return ((
|
|
38
|
+
return (_jsx(ScrollPositionContext.Provider, { value: value, children: children }));
|
|
61
39
|
}
|
|
62
|
-
function useScrollPosition(targetRef) {
|
|
63
|
-
|
|
40
|
+
export function useScrollPosition(targetRef) {
|
|
41
|
+
const context = useContext(ScrollPositionContext);
|
|
64
42
|
if (!context)
|
|
65
43
|
throw Error('Cannot fetch the current scroll position context, is the corresponding provider instated?');
|
|
66
44
|
if (!targetRef) {
|
|
@@ -69,22 +47,21 @@ function useScrollPosition(targetRef) {
|
|
|
69
47
|
step: context.step,
|
|
70
48
|
};
|
|
71
49
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
50
|
+
const element = targetRef.current;
|
|
51
|
+
const refRect = Rect.fromViewport();
|
|
52
|
+
const rect = Rect.from(element);
|
|
75
53
|
if (!refRect || !rect) {
|
|
76
54
|
return {
|
|
77
|
-
pos: new
|
|
78
|
-
step: new
|
|
55
|
+
pos: new Point(),
|
|
56
|
+
step: new Point(),
|
|
79
57
|
};
|
|
80
58
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
59
|
+
const posX = refRect.right - rect.left;
|
|
60
|
+
const posY = refRect.bottom - rect.top;
|
|
61
|
+
const stepX = posX / rect.width;
|
|
62
|
+
const stepY = posY / rect.height;
|
|
85
63
|
return {
|
|
86
|
-
pos: new
|
|
87
|
-
step: new
|
|
64
|
+
pos: new Point([posX, posY]),
|
|
65
|
+
step: new Point([stepX, stepY]),
|
|
88
66
|
};
|
|
89
67
|
}
|
|
90
|
-
//# sourceMappingURL=ScrollPositionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ScrollPositionProvider.js';
|
package/utils/asClassNameDict.js
CHANGED
package/utils/asComponentDict.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var types = Object.values(typeDict);
|
|
9
|
-
var components = {};
|
|
10
|
-
react_1.Children.forEach(children, function (child) {
|
|
11
|
-
if (!(0, react_1.isValidElement)(child))
|
|
1
|
+
import { Children, isValidElement } from 'react';
|
|
2
|
+
export function asComponentDict(children, typeDict = {}) {
|
|
3
|
+
const keys = Object.keys(typeDict);
|
|
4
|
+
const types = Object.values(typeDict);
|
|
5
|
+
const components = {};
|
|
6
|
+
Children.forEach(children, child => {
|
|
7
|
+
if (!isValidElement(child))
|
|
12
8
|
throw Error('Invalid child detected');
|
|
13
|
-
|
|
9
|
+
const index = types.indexOf(child.type);
|
|
14
10
|
if (index < 0)
|
|
15
|
-
throw Error(
|
|
16
|
-
|
|
11
|
+
throw Error(`Unsupported child, only the following children are allowed: ${types}`);
|
|
12
|
+
const key = keys[index];
|
|
17
13
|
if (components[key])
|
|
18
|
-
throw Error(
|
|
14
|
+
throw Error(`Only one ${types[index]} can be provided as a child`);
|
|
19
15
|
components[key] = child;
|
|
20
16
|
});
|
|
21
17
|
return components;
|
|
22
18
|
}
|
|
23
|
-
//# sourceMappingURL=asComponentDict.js.map
|
package/utils/asStyleDict.js
CHANGED
|
@@ -1,62 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
-
if (!m) return o;
|
|
27
|
-
var i = m.call(o), r, ar = [], e;
|
|
28
|
-
try {
|
|
29
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
-
}
|
|
31
|
-
catch (error) { e = { error: error }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
-
}
|
|
36
|
-
finally { if (e) throw e.error; }
|
|
37
|
-
}
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
41
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
42
|
-
if (ar || !(i in from)) {
|
|
43
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
44
|
-
ar[i] = from[i];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.cloneStyledElement = cloneStyledElement;
|
|
51
|
-
var react_1 = require("react");
|
|
52
|
-
function cloneStyledElement(element, props) {
|
|
53
|
-
if (props === void 0) { props = {}; }
|
|
54
|
-
var children = [];
|
|
55
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
56
|
-
children[_i - 2] = arguments[_i];
|
|
57
|
-
}
|
|
58
|
-
var _a = props, className = _a.className, style = _a.style, otherProps = __rest(_a, ["className", "style"]);
|
|
59
|
-
var _b = element.props, elementClassName = _b.className, elementStyle = _b.style, otherElementProps = __rest(_b, ["className", "style"]);
|
|
60
|
-
return react_1.cloneElement.apply(void 0, __spreadArray([element, __assign(__assign({ className: "".concat(elementClassName !== null && elementClassName !== void 0 ? elementClassName : '', " ").concat(className !== null && className !== void 0 ? className : '').split(' ').filter(Boolean).join(' '), style: __assign(__assign({}, elementStyle !== null && elementStyle !== void 0 ? elementStyle : {}), style !== null && style !== void 0 ? style : {}) }, otherElementProps), otherProps)], __read(children), false));
|
|
1
|
+
import { cloneElement } from 'react';
|
|
2
|
+
function cloneStyledElement(element, props = {}, ...children) {
|
|
3
|
+
const { className, style, ...otherProps } = props;
|
|
4
|
+
const { className: elementClassName, style: elementStyle, ...otherElementProps } = element.props;
|
|
5
|
+
return cloneElement(element, {
|
|
6
|
+
className: `${elementClassName ?? ''} ${className ?? ''}`.split(' ').filter(Boolean).join(' '),
|
|
7
|
+
style: {
|
|
8
|
+
...elementStyle ?? {},
|
|
9
|
+
...style ?? {},
|
|
10
|
+
},
|
|
11
|
+
...otherElementProps,
|
|
12
|
+
...otherProps,
|
|
13
|
+
}, ...children);
|
|
61
14
|
}
|
|
62
|
-
|
|
15
|
+
export { cloneStyledElement };
|
package/utils/index.js
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./asClassNameDict"), exports);
|
|
18
|
-
__exportStar(require("./asComponentDict"), exports);
|
|
19
|
-
__exportStar(require("./asStyleDict"), exports);
|
|
20
|
-
__exportStar(require("./cloneStyledElement"), exports);
|
|
21
|
-
__exportStar(require("./styles"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from './asClassNameDict.js';
|
|
2
|
+
export * from './asComponentDict.js';
|
|
3
|
+
export * from './asStyleDict.js';
|
|
4
|
+
export * from './cloneStyledElement.js';
|
|
5
|
+
export * from './styles.js';
|
package/utils/styles.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.styles = styles;
|
|
15
|
-
function styles() {
|
|
16
|
-
var args = [];
|
|
17
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18
|
-
args[_i] = arguments[_i];
|
|
19
|
-
}
|
|
20
|
-
return args.reduce(function (out, curr) { return (__assign(__assign({}, out), curr || {})); }, {});
|
|
1
|
+
export function styles(...args) {
|
|
2
|
+
return args.reduce((out, curr) => ({
|
|
3
|
+
...out,
|
|
4
|
+
...curr || {},
|
|
5
|
+
}), {});
|
|
21
6
|
}
|
|
22
|
-
//# sourceMappingURL=styles.js.map
|