@studiometa/ui 1.0.0-rc.2 → 1.0.0-rc.3
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/Hoverable/Hoverable.d.ts +67 -0
- package/Hoverable/Hoverable.js +88 -0
- package/Hoverable/Hoverable.js.map +7 -0
- package/Hoverable/index.d.ts +1 -0
- package/Hoverable/index.js +2 -0
- package/Hoverable/index.js.map +7 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Base } from '@studiometa/js-toolkit';
|
|
2
|
+
import type { BaseConfig, BaseProps, PointerServiceProps } from '@studiometa/js-toolkit';
|
|
3
|
+
export interface HoverableProps extends BaseProps {
|
|
4
|
+
$refs: {
|
|
5
|
+
/**
|
|
6
|
+
* Target element that will be moved on hover.
|
|
7
|
+
*/
|
|
8
|
+
target: HTMLElement;
|
|
9
|
+
};
|
|
10
|
+
$options: {
|
|
11
|
+
/**
|
|
12
|
+
* A number between in the range `0–1` used to smoothen the transition between each position.
|
|
13
|
+
*/
|
|
14
|
+
sensitivity: number;
|
|
15
|
+
/**
|
|
16
|
+
* Wether to reverse the movement of the target or not.
|
|
17
|
+
*/
|
|
18
|
+
reversed: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Wether to stop moving the target when the mouse is not over the root element or not.
|
|
21
|
+
*/
|
|
22
|
+
contained: boolean;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
declare const Hoverable_base: import("@studiometa/js-toolkit").BaseDecorator<import("@studiometa/js-toolkit").RelativePointerInterface, Base<BaseProps>>;
|
|
26
|
+
/**
|
|
27
|
+
* Hoverable class.
|
|
28
|
+
* @see https://ui.studiometa.dev/-/components/Hoverable/
|
|
29
|
+
*/
|
|
30
|
+
export declare class Hoverable<T extends BaseProps = BaseProps> extends Hoverable_base<T & HoverableProps> {
|
|
31
|
+
/**
|
|
32
|
+
* Config.
|
|
33
|
+
*/
|
|
34
|
+
static config: BaseConfig;
|
|
35
|
+
props: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
dampedX: number;
|
|
39
|
+
dampedY: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The hoverable element, defaults to `this.$refs.target`.
|
|
43
|
+
*/
|
|
44
|
+
get target(): HTMLElement;
|
|
45
|
+
/**
|
|
46
|
+
* The bouding element, defaults to `this.$el`.
|
|
47
|
+
*/
|
|
48
|
+
get parent(): HTMLElement;
|
|
49
|
+
/**
|
|
50
|
+
* The bounds values in which the target can move.
|
|
51
|
+
*/
|
|
52
|
+
get bounds(): {
|
|
53
|
+
yMin: number;
|
|
54
|
+
yMax: number;
|
|
55
|
+
xMin: number;
|
|
56
|
+
xMax: number;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Update props when the mouse moves.
|
|
60
|
+
*/
|
|
61
|
+
movedrelative({ progress }: PointerServiceProps): void;
|
|
62
|
+
/**
|
|
63
|
+
* Update target position on each frame.
|
|
64
|
+
*/
|
|
65
|
+
ticked(): () => void;
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Base, withRelativePointer } from "@studiometa/js-toolkit";
|
|
2
|
+
import { map, transform, damp, getOffsetSizes, clamp01 } from "@studiometa/js-toolkit/utils";
|
|
3
|
+
class Hoverable extends withRelativePointer(Base) {
|
|
4
|
+
/**
|
|
5
|
+
* Config.
|
|
6
|
+
*/
|
|
7
|
+
static config = {
|
|
8
|
+
name: "Hoverable",
|
|
9
|
+
refs: ["target"],
|
|
10
|
+
options: {
|
|
11
|
+
sensitivity: {
|
|
12
|
+
type: Number,
|
|
13
|
+
default: 0.1
|
|
14
|
+
},
|
|
15
|
+
reversed: Boolean,
|
|
16
|
+
contained: Boolean
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
props = {
|
|
20
|
+
x: 0,
|
|
21
|
+
y: 0,
|
|
22
|
+
dampedX: 0,
|
|
23
|
+
dampedY: 0
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The hoverable element, defaults to `this.$refs.target`.
|
|
27
|
+
*/
|
|
28
|
+
get target() {
|
|
29
|
+
return this.$refs.target;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The bouding element, defaults to `this.$el`.
|
|
33
|
+
*/
|
|
34
|
+
get parent() {
|
|
35
|
+
return this.$el;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The bounds values in which the target can move.
|
|
39
|
+
*/
|
|
40
|
+
get bounds() {
|
|
41
|
+
const targetSizes = getOffsetSizes(this.target);
|
|
42
|
+
const parentSizes = getOffsetSizes(this.parent);
|
|
43
|
+
const xMin = targetSizes.x - parentSizes.x;
|
|
44
|
+
const yMin = targetSizes.y - parentSizes.y;
|
|
45
|
+
const xMax = xMin + targetSizes.width - parentSizes.width;
|
|
46
|
+
const yMax = yMin + targetSizes.height - parentSizes.height;
|
|
47
|
+
return {
|
|
48
|
+
yMin: yMin * -1,
|
|
49
|
+
yMax: yMax * -1,
|
|
50
|
+
xMin: xMin * -1,
|
|
51
|
+
xMax: xMax * -1
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Update props when the mouse moves.
|
|
56
|
+
*/
|
|
57
|
+
movedrelative({ progress }) {
|
|
58
|
+
const { bounds, props } = this;
|
|
59
|
+
const { reversed, contained } = this.$options;
|
|
60
|
+
const { x, y } = progress;
|
|
61
|
+
if (contained && (y < 0 || x < 0 || y > 1 || x > 1)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const from = reversed ? 1 : 0;
|
|
65
|
+
const to = reversed ? 0 : 1;
|
|
66
|
+
props.y = map(clamp01(y), from, to, bounds.yMin, bounds.yMax);
|
|
67
|
+
props.x = map(clamp01(x), from, to, bounds.xMin, bounds.xMax);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Update target position on each frame.
|
|
71
|
+
*/
|
|
72
|
+
ticked() {
|
|
73
|
+
const { props, target } = this;
|
|
74
|
+
const { sensitivity } = this.$options;
|
|
75
|
+
props.dampedY = damp(props.y, props.dampedY, sensitivity);
|
|
76
|
+
props.dampedX = damp(props.x, props.dampedX, sensitivity);
|
|
77
|
+
return () => {
|
|
78
|
+
transform(target, {
|
|
79
|
+
y: props.dampedY,
|
|
80
|
+
x: props.dampedX
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
Hoverable
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=Hoverable.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/ui/Hoverable/Hoverable.ts"],
|
|
4
|
+
"sourcesContent": ["import { Base, withRelativePointer } from '@studiometa/js-toolkit';\nimport type { BaseConfig, BaseProps, PointerServiceProps } from '@studiometa/js-toolkit';\nimport { map, transform, damp, getOffsetSizes, clamp01 } from '@studiometa/js-toolkit/utils';\n\nexport interface HoverableProps extends BaseProps {\n $refs: {\n /**\n * Target element that will be moved on hover.\n */\n target: HTMLElement;\n };\n $options: {\n /**\n * A number between in the range `0\u20131` used to smoothen the transition between each position.\n */\n sensitivity: number;\n /**\n * Wether to reverse the movement of the target or not.\n */\n reversed: boolean;\n /**\n * Wether to stop moving the target when the mouse is not over the root element or not.\n */\n contained: boolean;\n };\n}\n\n/**\n * Hoverable class.\n * @see https://ui.studiometa.dev/-/components/Hoverable/\n */\nexport class Hoverable<T extends BaseProps = BaseProps> extends withRelativePointer(Base)<\n T & HoverableProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'Hoverable',\n refs: ['target'],\n options: {\n sensitivity: {\n type: Number,\n default: 0.1,\n },\n reversed: Boolean,\n contained: Boolean,\n },\n };\n\n props = {\n x: 0,\n y: 0,\n dampedX: 0,\n dampedY: 0,\n };\n\n /**\n * The hoverable element, defaults to `this.$refs.target`.\n */\n get target(): HTMLElement {\n return this.$refs.target;\n }\n\n /**\n * The bouding element, defaults to `this.$el`.\n */\n get parent(): HTMLElement {\n return this.$el;\n }\n\n /**\n * The bounds values in which the target can move.\n */\n get bounds() {\n const targetSizes = getOffsetSizes(this.target);\n const parentSizes = getOffsetSizes(this.parent);\n const xMin = targetSizes.x - parentSizes.x;\n const yMin = targetSizes.y - parentSizes.y;\n const xMax = xMin + targetSizes.width - parentSizes.width;\n const yMax = yMin + targetSizes.height - parentSizes.height;\n\n return {\n yMin: yMin * -1,\n yMax: yMax * -1,\n xMin: xMin * -1,\n xMax: xMax * -1,\n };\n }\n\n /**\n * Update props when the mouse moves.\n */\n movedrelative({ progress }: PointerServiceProps) {\n const { bounds, props } = this;\n const { reversed, contained } = this.$options;\n const { x, y } = progress;\n\n // Stop updating when pointer is outside of the parent bounds\n if (contained && (y < 0 || x < 0 || y > 1 || x > 1)) {\n return;\n }\n\n const from = reversed ? 1 : 0;\n const to = reversed ? 0 : 1;\n\n props.y = map(clamp01(y), from, to, bounds.yMin, bounds.yMax);\n props.x = map(clamp01(x), from, to, bounds.xMin, bounds.xMax);\n }\n\n /**\n * Update target position on each frame.\n */\n ticked() {\n const { props, target } = this;\n const { sensitivity } = this.$options;\n props.dampedY = damp(props.y, props.dampedY, sensitivity);\n props.dampedX = damp(props.x, props.dampedX, sensitivity);\n\n return () => {\n transform(target, {\n y: props.dampedY,\n x: props.dampedX,\n });\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,MAAM,2BAA2B;AAE1C,SAAS,KAAK,WAAW,MAAM,gBAAgB,eAAe;AA6BvD,MAAM,kBAAmD,oBAAoB,IAAI,EAEtF;AAAA;AAAA;AAAA;AAAA,EAIA,OAAO,SAAqB;AAAA,IAC1B,MAAM;AAAA,IACN,MAAM,CAAC,QAAQ;AAAA,IACf,SAAS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,OAAO,IAAI;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS;AACP,UAAM,EAAE,OAAO,OAAO,IAAI;AAC1B,UAAM,EAAE,YAAY,IAAI,KAAK;AAC7B,UAAM,UAAU,KAAK,MAAM,GAAG,MAAM,SAAS,WAAW;AACxD,UAAM,UAAU,KAAK,MAAM,GAAG,MAAM,SAAS,WAAW;AAExD,WAAO,MAAM;AACX,gBAAU,QAAQ;AAAA,QAChB,GAAG,MAAM;AAAA,QACT,GAAG,MAAM;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Hoverable.js';
|
package/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './Draggable/index.js';
|
|
|
10
10
|
export * from './Figure/index.js';
|
|
11
11
|
export * from './FigureVideo/index.js';
|
|
12
12
|
export * from './Frame/index.js';
|
|
13
|
+
export * from './Hoverable/index.js';
|
|
13
14
|
export * from './LargeText/index.js';
|
|
14
15
|
export * from './LazyInclude/index.js';
|
|
15
16
|
export * from './Menu/index.js';
|
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./Draggable/index.js";
|
|
|
10
10
|
export * from "./Figure/index.js";
|
|
11
11
|
export * from "./FigureVideo/index.js";
|
|
12
12
|
export * from "./Frame/index.js";
|
|
13
|
+
export * from "./Hoverable/index.js";
|
|
13
14
|
export * from "./LargeText/index.js";
|
|
14
15
|
export * from "./LazyInclude/index.js";
|
|
15
16
|
export * from "./Menu/index.js";
|
package/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../packages/ui/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './Accordion/index.js';\nexport * from './Action/index.js';\nexport * from './AnchorNav/index.js';\nexport * from './AnchorScrollTo/index.js';\nexport * from './CircularMarquee/index.js';\nexport * from './Cursor/index.js';\nexport * from './Data/index.js';\nexport * from './decorators/index.js';\nexport * from './Draggable/index.js';\nexport * from './Figure/index.js';\nexport * from './FigureVideo/index.js';\nexport * from './Frame/index.js';\nexport * from './LargeText/index.js';\nexport * from './LazyInclude/index.js';\nexport * from './Menu/index.js';\nexport * from './Modal/index.js';\nexport * from './Panel/index.js';\nexport * from './Prefetch/index.js';\nexport * from './ScrollAnimation/index.js';\nexport * from './ScrollReveal/index.js';\nexport * from './Sentinel/index.js';\nexport * from './Slider/index.js';\nexport * from './Sticky/index.js';\nexport * from './Tabs/index.js';\nexport * from './Transition/index.js';\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from './Accordion/index.js';\nexport * from './Action/index.js';\nexport * from './AnchorNav/index.js';\nexport * from './AnchorScrollTo/index.js';\nexport * from './CircularMarquee/index.js';\nexport * from './Cursor/index.js';\nexport * from './Data/index.js';\nexport * from './decorators/index.js';\nexport * from './Draggable/index.js';\nexport * from './Figure/index.js';\nexport * from './FigureVideo/index.js';\nexport * from './Frame/index.js';\nexport * from './Hoverable/index.js';\nexport * from './LargeText/index.js';\nexport * from './LazyInclude/index.js';\nexport * from './Menu/index.js';\nexport * from './Modal/index.js';\nexport * from './Panel/index.js';\nexport * from './Prefetch/index.js';\nexport * from './ScrollAnimation/index.js';\nexport * from './ScrollReveal/index.js';\nexport * from './Sentinel/index.js';\nexport * from './Slider/index.js';\nexport * from './Sticky/index.js';\nexport * from './Tabs/index.js';\nexport * from './Transition/index.js';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|