@limetech/lime-elements 37.70.4 → 37.70.5
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/CHANGELOG.md +8 -0
- package/dist/collection/style/mixins.scss +0 -95
- package/dist/lime-elements/style/mixins.scss +0 -95
- package/dist/scss/mixins.scss +0 -95
- package/package.json +1 -1
- package/dist/collection/util/3d-tilt-hover-effect.js +0 -124
- package/dist/collection/util/3d-tilt-hover-effect.js.map +0 -1
- package/dist/types/util/3d-tilt-hover-effect.d.ts +0 -93
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [37.70.5](https://github.com/Lundalogik/lime-elements/compare/v37.70.4...v37.70.5) (2024-11-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Reverts
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
* Revert "chore(util): add a utility function to create an interactive 3D effect" ([f81fdb8](https://github.com/Lundalogik/lime-elements/commit/f81fdb8add98d0deadc4d8da59593af0433da43b))
|
|
8
|
+
|
|
1
9
|
## [37.70.4](https://github.com/Lundalogik/lime-elements/compare/v37.70.3...v37.70.4) (2024-11-26)
|
|
2
10
|
|
|
3
11
|
|
|
@@ -456,98 +456,3 @@ $clickable-normal-state-transitions: (
|
|
|
456
456
|
clip-path: inset(50%);
|
|
457
457
|
white-space: nowrap;
|
|
458
458
|
}
|
|
459
|
-
|
|
460
|
-
// This mixin designed to enhance the visual effects,
|
|
461
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
462
|
-
// is implemented in a component.
|
|
463
|
-
// This adds styles to a `<div class"limel-3d-hover-effect-glow" />`, needed to create
|
|
464
|
-
// a glow effect on a 3D element when the parent element is hovered.
|
|
465
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
466
|
-
// Parts of these styles are controlled by the `titleFollowingTheCursor` function.
|
|
467
|
-
@mixin limel-3d-hover-effect-glow($the3dElement, $border-radius) {
|
|
468
|
-
.limel-3d-hover-effect-glow {
|
|
469
|
-
transition:
|
|
470
|
-
background 0.4s ease,
|
|
471
|
-
opacity 0.4s ease;
|
|
472
|
-
pointer-events: none;
|
|
473
|
-
|
|
474
|
-
position: absolute;
|
|
475
|
-
inset: 0;
|
|
476
|
-
border-radius: $border-radius;
|
|
477
|
-
|
|
478
|
-
opacity: 0.1;
|
|
479
|
-
#{$the3dElement}:hover & {
|
|
480
|
-
opacity: 0.5;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
background-image: radial-gradient(
|
|
484
|
-
circle at var(--limel-3d-hover-effect-glow-position, 50% -20%),
|
|
485
|
-
rgb(var(--color-white), 0.3),
|
|
486
|
-
rgb(var(--color-white), 0)
|
|
487
|
-
);
|
|
488
|
-
|
|
489
|
-
mix-blend-mode: plus-lighter;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// These mixins below are designed to apply the necessary visual effects,
|
|
494
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
495
|
-
// is implemented in a component.
|
|
496
|
-
@mixin parent-of-the-3d-element {
|
|
497
|
-
isolation: isolate;
|
|
498
|
-
transform-style: preserve-3d;
|
|
499
|
-
perspective: 1000px;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
@mixin the-3d-element {
|
|
503
|
-
position: relative;
|
|
504
|
-
|
|
505
|
-
transition-duration: 0.8s;
|
|
506
|
-
transition-property: transform, box-shadow, background-color;
|
|
507
|
-
transition-timing-function: ease-out;
|
|
508
|
-
transform: scale3d(1, 1, 1) rotate3d(0, 0, 0, 0deg);
|
|
509
|
-
|
|
510
|
-
&:hover,
|
|
511
|
-
&:focus,
|
|
512
|
-
&:focus-visible,
|
|
513
|
-
&:focus-within {
|
|
514
|
-
will-change: background-color, box-shadow, transform;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
&:hover,
|
|
518
|
-
&:focus,
|
|
519
|
-
&:focus-visible,
|
|
520
|
-
&:active {
|
|
521
|
-
transition-duration: 0.2s;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
&:hover,
|
|
525
|
-
&:focus-visible {
|
|
526
|
-
box-shadow: var(--button-shadow-hovered);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
&:hover {
|
|
530
|
-
transform: scale3d(1.01, 1.01, 1.01)
|
|
531
|
-
rotate3d(var(--limel-3d-hover-effect-rotate3d));
|
|
532
|
-
}
|
|
533
|
-
&:focus-visible {
|
|
534
|
-
transform: scale3d(1.01, 1.01, 1.01);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
@mixin the-3d-element--clickable {
|
|
539
|
-
cursor: pointer;
|
|
540
|
-
box-shadow: var(--button-shadow-normal);
|
|
541
|
-
|
|
542
|
-
&:active {
|
|
543
|
-
transform: scale3d(1, 1, 1) rotate3d(0, 0, 0, 0deg);
|
|
544
|
-
box-shadow: var(--button-shadow-pressed);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
&:focus-visible {
|
|
548
|
-
box-shadow: var(--button-shadow-hovered), var(--shadow-depth-8-focused);
|
|
549
|
-
}
|
|
550
|
-
&:focus-visible:active {
|
|
551
|
-
box-shadow: var(--button-shadow-pressed), var(--shadow-depth-8-focused);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
@@ -456,98 +456,3 @@ $clickable-normal-state-transitions: (
|
|
|
456
456
|
clip-path: inset(50%);
|
|
457
457
|
white-space: nowrap;
|
|
458
458
|
}
|
|
459
|
-
|
|
460
|
-
// This mixin designed to enhance the visual effects,
|
|
461
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
462
|
-
// is implemented in a component.
|
|
463
|
-
// This adds styles to a `<div class"limel-3d-hover-effect-glow" />`, needed to create
|
|
464
|
-
// a glow effect on a 3D element when the parent element is hovered.
|
|
465
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
466
|
-
// Parts of these styles are controlled by the `titleFollowingTheCursor` function.
|
|
467
|
-
@mixin limel-3d-hover-effect-glow($the3dElement, $border-radius) {
|
|
468
|
-
.limel-3d-hover-effect-glow {
|
|
469
|
-
transition:
|
|
470
|
-
background 0.4s ease,
|
|
471
|
-
opacity 0.4s ease;
|
|
472
|
-
pointer-events: none;
|
|
473
|
-
|
|
474
|
-
position: absolute;
|
|
475
|
-
inset: 0;
|
|
476
|
-
border-radius: $border-radius;
|
|
477
|
-
|
|
478
|
-
opacity: 0.1;
|
|
479
|
-
#{$the3dElement}:hover & {
|
|
480
|
-
opacity: 0.5;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
background-image: radial-gradient(
|
|
484
|
-
circle at var(--limel-3d-hover-effect-glow-position, 50% -20%),
|
|
485
|
-
rgb(var(--color-white), 0.3),
|
|
486
|
-
rgb(var(--color-white), 0)
|
|
487
|
-
);
|
|
488
|
-
|
|
489
|
-
mix-blend-mode: plus-lighter;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// These mixins below are designed to apply the necessary visual effects,
|
|
494
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
495
|
-
// is implemented in a component.
|
|
496
|
-
@mixin parent-of-the-3d-element {
|
|
497
|
-
isolation: isolate;
|
|
498
|
-
transform-style: preserve-3d;
|
|
499
|
-
perspective: 1000px;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
@mixin the-3d-element {
|
|
503
|
-
position: relative;
|
|
504
|
-
|
|
505
|
-
transition-duration: 0.8s;
|
|
506
|
-
transition-property: transform, box-shadow, background-color;
|
|
507
|
-
transition-timing-function: ease-out;
|
|
508
|
-
transform: scale3d(1, 1, 1) rotate3d(0, 0, 0, 0deg);
|
|
509
|
-
|
|
510
|
-
&:hover,
|
|
511
|
-
&:focus,
|
|
512
|
-
&:focus-visible,
|
|
513
|
-
&:focus-within {
|
|
514
|
-
will-change: background-color, box-shadow, transform;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
&:hover,
|
|
518
|
-
&:focus,
|
|
519
|
-
&:focus-visible,
|
|
520
|
-
&:active {
|
|
521
|
-
transition-duration: 0.2s;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
&:hover,
|
|
525
|
-
&:focus-visible {
|
|
526
|
-
box-shadow: var(--button-shadow-hovered);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
&:hover {
|
|
530
|
-
transform: scale3d(1.01, 1.01, 1.01)
|
|
531
|
-
rotate3d(var(--limel-3d-hover-effect-rotate3d));
|
|
532
|
-
}
|
|
533
|
-
&:focus-visible {
|
|
534
|
-
transform: scale3d(1.01, 1.01, 1.01);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
@mixin the-3d-element--clickable {
|
|
539
|
-
cursor: pointer;
|
|
540
|
-
box-shadow: var(--button-shadow-normal);
|
|
541
|
-
|
|
542
|
-
&:active {
|
|
543
|
-
transform: scale3d(1, 1, 1) rotate3d(0, 0, 0, 0deg);
|
|
544
|
-
box-shadow: var(--button-shadow-pressed);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
&:focus-visible {
|
|
548
|
-
box-shadow: var(--button-shadow-hovered), var(--shadow-depth-8-focused);
|
|
549
|
-
}
|
|
550
|
-
&:focus-visible:active {
|
|
551
|
-
box-shadow: var(--button-shadow-pressed), var(--shadow-depth-8-focused);
|
|
552
|
-
}
|
|
553
|
-
}
|
package/dist/scss/mixins.scss
CHANGED
|
@@ -456,98 +456,3 @@ $clickable-normal-state-transitions: (
|
|
|
456
456
|
clip-path: inset(50%);
|
|
457
457
|
white-space: nowrap;
|
|
458
458
|
}
|
|
459
|
-
|
|
460
|
-
// This mixin designed to enhance the visual effects,
|
|
461
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
462
|
-
// is implemented in a component.
|
|
463
|
-
// This adds styles to a `<div class"limel-3d-hover-effect-glow" />`, needed to create
|
|
464
|
-
// a glow effect on a 3D element when the parent element is hovered.
|
|
465
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
466
|
-
// Parts of these styles are controlled by the `titleFollowingTheCursor` function.
|
|
467
|
-
@mixin limel-3d-hover-effect-glow($the3dElement, $border-radius) {
|
|
468
|
-
.limel-3d-hover-effect-glow {
|
|
469
|
-
transition:
|
|
470
|
-
background 0.4s ease,
|
|
471
|
-
opacity 0.4s ease;
|
|
472
|
-
pointer-events: none;
|
|
473
|
-
|
|
474
|
-
position: absolute;
|
|
475
|
-
inset: 0;
|
|
476
|
-
border-radius: $border-radius;
|
|
477
|
-
|
|
478
|
-
opacity: 0.1;
|
|
479
|
-
#{$the3dElement}:hover & {
|
|
480
|
-
opacity: 0.5;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
background-image: radial-gradient(
|
|
484
|
-
circle at var(--limel-3d-hover-effect-glow-position, 50% -20%),
|
|
485
|
-
rgb(var(--color-white), 0.3),
|
|
486
|
-
rgb(var(--color-white), 0)
|
|
487
|
-
);
|
|
488
|
-
|
|
489
|
-
mix-blend-mode: plus-lighter;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// These mixins below are designed to apply the necessary visual effects,
|
|
494
|
-
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
|
|
495
|
-
// is implemented in a component.
|
|
496
|
-
@mixin parent-of-the-3d-element {
|
|
497
|
-
isolation: isolate;
|
|
498
|
-
transform-style: preserve-3d;
|
|
499
|
-
perspective: 1000px;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
@mixin the-3d-element {
|
|
503
|
-
position: relative;
|
|
504
|
-
|
|
505
|
-
transition-duration: 0.8s;
|
|
506
|
-
transition-property: transform, box-shadow, background-color;
|
|
507
|
-
transition-timing-function: ease-out;
|
|
508
|
-
transform: scale3d(1, 1, 1) rotate3d(0, 0, 0, 0deg);
|
|
509
|
-
|
|
510
|
-
&:hover,
|
|
511
|
-
&:focus,
|
|
512
|
-
&:focus-visible,
|
|
513
|
-
&:focus-within {
|
|
514
|
-
will-change: background-color, box-shadow, transform;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
&:hover,
|
|
518
|
-
&:focus,
|
|
519
|
-
&:focus-visible,
|
|
520
|
-
&:active {
|
|
521
|
-
transition-duration: 0.2s;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
&:hover,
|
|
525
|
-
&:focus-visible {
|
|
526
|
-
box-shadow: var(--button-shadow-hovered);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
&:hover {
|
|
530
|
-
transform: scale3d(1.01, 1.01, 1.01)
|
|
531
|
-
rotate3d(var(--limel-3d-hover-effect-rotate3d));
|
|
532
|
-
}
|
|
533
|
-
&:focus-visible {
|
|
534
|
-
transform: scale3d(1.01, 1.01, 1.01);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
@mixin the-3d-element--clickable {
|
|
539
|
-
cursor: pointer;
|
|
540
|
-
box-shadow: var(--button-shadow-normal);
|
|
541
|
-
|
|
542
|
-
&:active {
|
|
543
|
-
transform: scale3d(1, 1, 1) rotate3d(0, 0, 0, 0deg);
|
|
544
|
-
box-shadow: var(--button-shadow-pressed);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
&:focus-visible {
|
|
548
|
-
box-shadow: var(--button-shadow-hovered), var(--shadow-depth-8-focused);
|
|
549
|
-
}
|
|
550
|
-
&:focus-visible:active {
|
|
551
|
-
box-shadow: var(--button-shadow-pressed), var(--shadow-depth-8-focused);
|
|
552
|
-
}
|
|
553
|
-
}
|
package/package.json
CHANGED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for creating a 3D tilt hover effect.
|
|
3
|
-
*
|
|
4
|
-
* This module provides functions that enables consumer components to display a nice 3D effect,
|
|
5
|
-
* when being hovered; enabling them to follow the cursor's position and tilt towards it.
|
|
6
|
-
*
|
|
7
|
-
* ## What you need, to make this work
|
|
8
|
-
* ### Typescript
|
|
9
|
-
* 1. Import the functions:
|
|
10
|
-
*
|
|
11
|
-
* ```tsx
|
|
12
|
-
* import {
|
|
13
|
-
* tiltFollowingTheCursor,
|
|
14
|
-
* handleMouseEnter,
|
|
15
|
-
* handleMouseLeave,
|
|
16
|
-
* } from './path/to/3d-tilt-hover-effect';
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* 2. In your component, define the necessary properties:
|
|
20
|
-
*
|
|
21
|
-
* ```tsx
|
|
22
|
-
* @Element() private element: HTMLElement;
|
|
23
|
-
* private the3dElementBounds: DOMRect;
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* 3. If your component does not already have event handlers,
|
|
27
|
-
* implement them using the imported functions from this file:
|
|
28
|
-
*
|
|
29
|
-
* ```tsx
|
|
30
|
-
* private handleMouseEnter = () => {
|
|
31
|
-
* handleMouseEnter(this.element, 'section', (bounds) => {
|
|
32
|
-
* this.the3dElementBounds = bounds;
|
|
33
|
-
* }, this.tiltFollowingTheCursor);
|
|
34
|
-
* };
|
|
35
|
-
*
|
|
36
|
-
* private handleMouseLeave = () => {
|
|
37
|
-
* handleMouseLeave(this.element, this.tiltFollowingTheCursor);
|
|
38
|
-
* };
|
|
39
|
-
*
|
|
40
|
-
* private tiltFollowingTheCursor = (e: MouseEvent) => {
|
|
41
|
-
* tiltFollowingTheCursor(e, this.the3dElementBounds, this.element);
|
|
42
|
-
* };
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* 4. Attach the event handlers to the relevant elements in your render method:
|
|
46
|
-
*
|
|
47
|
-
* ```tsx
|
|
48
|
-
* public render() {
|
|
49
|
-
* return (
|
|
50
|
-
* <section
|
|
51
|
-
* onMouseEnter={this.handleMouseEnter}
|
|
52
|
-
* onMouseLeave={this.handleMouseLeave}
|
|
53
|
-
* >
|
|
54
|
-
* Your content here
|
|
55
|
-
* </section>
|
|
56
|
-
* );
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* :::note
|
|
61
|
-
* - Ensure that the `element` and `the3dElementBounds` properties are properly
|
|
62
|
-
* defined in your component.
|
|
63
|
-
* - The `selector` parameter in `handleMouseEnter` should match the selector
|
|
64
|
-
* of the element you want to apply the 3D effect to.
|
|
65
|
-
* - The `tiltFollowingTheCursor` function calculates the 3D rotation and glow
|
|
66
|
-
* position based on the cursor's position relative to the element's bounds.
|
|
67
|
-
* :::
|
|
68
|
-
*
|
|
69
|
-
* ### HTML elements + CSS
|
|
70
|
-
* 1. Add a `<div class="limel-3d-hover-effect-glow" />` element to your component's template,
|
|
71
|
-
* inside the element you want to apply the 3D effect to, and preferably at the bottom of all
|
|
72
|
-
* other elements within that element (to avoid the need to specifying `z-index`es).
|
|
73
|
-
* 2. Add the following `mixin` to your component's SCSS file:
|
|
74
|
-
* `limel-3d-hover-effect-glow($the3dElement, $border-radius);`
|
|
75
|
-
*
|
|
76
|
-
* and don't forget to define the `$the3dElement` variables for the mixin to work
|
|
77
|
-
* (and optionally the `$border-radius`).
|
|
78
|
-
* 3. Keep in mind that the `<div class="limel-3d-hover-effect-glow" />` will be
|
|
79
|
-
* absolutely positioned inside the parent element, so make sure the parent element
|
|
80
|
-
* has `position` set.
|
|
81
|
-
* 4. Add the following `mixin` to the host element: `parent-of-the-3d-element`.
|
|
82
|
-
* 5. Add the following `mixin` to the 3D element: `the-3d-element`.
|
|
83
|
-
* 6. And if your element is supposed to be clickable, add this `mixin` as well: `the-3d-element--clickable`.
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
export const MOUSE_SCALE_FACTOR = 100;
|
|
87
|
-
export const ROTATION_DEGREE_MULTIPLIER = 1.6;
|
|
88
|
-
export const GLOW_POSITION_MULTIPLIER = 2;
|
|
89
|
-
export const CENTER_DIVISOR = 2;
|
|
90
|
-
export function tiltFollowingTheCursor(e, the3dElementBounds, element) {
|
|
91
|
-
const mouseX = e.clientX;
|
|
92
|
-
const mouseY = e.clientY;
|
|
93
|
-
const leftX = mouseX - the3dElementBounds.x;
|
|
94
|
-
const topY = mouseY - the3dElementBounds.y;
|
|
95
|
-
const center = {
|
|
96
|
-
x: leftX - the3dElementBounds.width / CENTER_DIVISOR,
|
|
97
|
-
y: topY - the3dElementBounds.height / CENTER_DIVISOR,
|
|
98
|
-
};
|
|
99
|
-
const distance = Math.sqrt(center.x ** CENTER_DIVISOR + center.y ** CENTER_DIVISOR);
|
|
100
|
-
const rotate3d = `
|
|
101
|
-
${center.y / MOUSE_SCALE_FACTOR},
|
|
102
|
-
${-center.x / MOUSE_SCALE_FACTOR},
|
|
103
|
-
0,
|
|
104
|
-
${Math.log(distance) * ROTATION_DEGREE_MULTIPLIER}deg
|
|
105
|
-
`;
|
|
106
|
-
element.style.setProperty('--limel-3d-hover-effect-rotate3d', rotate3d);
|
|
107
|
-
const glowPosition = `
|
|
108
|
-
${center.x * GLOW_POSITION_MULTIPLIER + the3dElementBounds.width / CENTER_DIVISOR}px
|
|
109
|
-
`;
|
|
110
|
-
element.style.setProperty('--limel-3d-hover-effect-glow-position', glowPosition);
|
|
111
|
-
}
|
|
112
|
-
export function handleMouseEnter(element, selector, setBounds, tiltCallback) {
|
|
113
|
-
const the3dElement = element.shadowRoot.querySelector(selector);
|
|
114
|
-
const bounds = the3dElement.getBoundingClientRect();
|
|
115
|
-
setBounds(bounds);
|
|
116
|
-
document.addEventListener('mousemove', tiltCallback);
|
|
117
|
-
}
|
|
118
|
-
export function handleMouseLeave(element, selector, tiltCallback) {
|
|
119
|
-
const the3dElement = element.shadowRoot.querySelector(selector);
|
|
120
|
-
document.removeEventListener('mousemove', tiltCallback);
|
|
121
|
-
the3dElement.style.removeProperty('--limel-3d-hover-effect-rotate3d');
|
|
122
|
-
the3dElement.style.removeProperty('--limel-3d-hover-effect-glow-position');
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=3d-tilt-hover-effect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"3d-tilt-hover-effect.js","sourceRoot":"","sources":["../../src/util/3d-tilt-hover-effect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AACtC,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,UAAU,sBAAsB,CAClC,CAAa,EACb,kBAA2B,EAC3B,OAAoB;EAEpB,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC;EACzB,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC;EACzB,MAAM,KAAK,GAAG,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC;EAC5C,MAAM,IAAI,GAAG,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC;EAC3C,MAAM,MAAM,GAAG;IACX,CAAC,EAAE,KAAK,GAAG,kBAAkB,CAAC,KAAK,GAAG,cAAc;IACpD,CAAC,EAAE,IAAI,GAAG,kBAAkB,CAAC,MAAM,GAAG,cAAc;GACvD,CAAC;EACF,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACtB,MAAM,CAAC,CAAC,IAAI,cAAc,GAAG,MAAM,CAAC,CAAC,IAAI,cAAc,CAC1D,CAAC;EAEF,MAAM,QAAQ,GAAG;UACX,MAAM,CAAC,CAAC,GAAG,kBAAkB;UAC7B,CAAC,MAAM,CAAC,CAAC,GAAG,kBAAkB;;UAE9B,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,0BAA0B;KACpD,CAAC;EACF,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,kCAAkC,EAAE,QAAQ,CAAC,CAAC;EAExE,MAAM,YAAY,GAAG;UACf,MAAM,CAAC,CAAC,GAAG,wBAAwB,GAAG,kBAAkB,CAAC,KAAK,GAAG,cAAc;KACpF,CAAC;EACF,OAAO,CAAC,KAAK,CAAC,WAAW,CACrB,uCAAuC,EACvC,YAAY,CACf,CAAC;AACN,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC5B,OAAoB,EACpB,QAAgB,EAChB,SAAoC,EACpC,YAAqC;EAErC,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CACjD,QAAQ,CACI,CAAC;EACjB,MAAM,MAAM,GAAG,YAAY,CAAC,qBAAqB,EAAE,CAAC;EACpD,SAAS,CAAC,MAAM,CAAC,CAAC;EAClB,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC5B,OAAoB,EACpB,QAAgB,EAChB,YAAqC;EAErC,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CACjD,QAAQ,CACI,CAAC;EACjB,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;EACxD,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,kCAAkC,CAAC,CAAC;EACtE,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,uCAAuC,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["/**\n * Utility functions for creating a 3D tilt hover effect.\n *\n * This module provides functions that enables consumer components to display a nice 3D effect,\n * when being hovered; enabling them to follow the cursor's position and tilt towards it.\n *\n * ## What you need, to make this work\n * ### Typescript\n * 1. Import the functions:\n *\n * ```tsx\n * import {\n * tiltFollowingTheCursor,\n * handleMouseEnter,\n * handleMouseLeave,\n * } from './path/to/3d-tilt-hover-effect';\n * ```\n *\n * 2. In your component, define the necessary properties:\n *\n * ```tsx\n * @Element() private element: HTMLElement;\n * private the3dElementBounds: DOMRect;\n * ```\n *\n * 3. If your component does not already have event handlers,\n * implement them using the imported functions from this file:\n *\n * ```tsx\n * private handleMouseEnter = () => {\n * handleMouseEnter(this.element, 'section', (bounds) => {\n * this.the3dElementBounds = bounds;\n * }, this.tiltFollowingTheCursor);\n * };\n *\n * private handleMouseLeave = () => {\n * handleMouseLeave(this.element, this.tiltFollowingTheCursor);\n * };\n *\n * private tiltFollowingTheCursor = (e: MouseEvent) => {\n * tiltFollowingTheCursor(e, this.the3dElementBounds, this.element);\n * };\n * ```\n *\n * 4. Attach the event handlers to the relevant elements in your render method:\n *\n * ```tsx\n * public render() {\n * return (\n * <section\n * onMouseEnter={this.handleMouseEnter}\n * onMouseLeave={this.handleMouseLeave}\n * >\n * Your content here\n * </section>\n * );\n * }\n * ```\n *\n * :::note\n * - Ensure that the `element` and `the3dElementBounds` properties are properly\n * defined in your component.\n * - The `selector` parameter in `handleMouseEnter` should match the selector\n * of the element you want to apply the 3D effect to.\n * - The `tiltFollowingTheCursor` function calculates the 3D rotation and glow\n * position based on the cursor's position relative to the element's bounds.\n * :::\n *\n * ### HTML elements + CSS\n * 1. Add a `<div class=\"limel-3d-hover-effect-glow\" />` element to your component's template,\n * inside the element you want to apply the 3D effect to, and preferably at the bottom of all\n * other elements within that element (to avoid the need to specifying `z-index`es).\n * 2. Add the following `mixin` to your component's SCSS file:\n * `limel-3d-hover-effect-glow($the3dElement, $border-radius);`\n *\n * and don't forget to define the `$the3dElement` variables for the mixin to work\n * (and optionally the `$border-radius`).\n * 3. Keep in mind that the `<div class=\"limel-3d-hover-effect-glow\" />` will be\n * absolutely positioned inside the parent element, so make sure the parent element\n * has `position` set.\n * 4. Add the following `mixin` to the host element: `parent-of-the-3d-element`.\n * 5. Add the following `mixin` to the 3D element: `the-3d-element`.\n * 6. And if your element is supposed to be clickable, add this `mixin` as well: `the-3d-element--clickable`.\n *\n */\n\nexport const MOUSE_SCALE_FACTOR = 100;\nexport const ROTATION_DEGREE_MULTIPLIER = 1.6;\nexport const GLOW_POSITION_MULTIPLIER = 2;\nexport const CENTER_DIVISOR = 2;\n\nexport function tiltFollowingTheCursor(\n e: MouseEvent,\n the3dElementBounds: DOMRect,\n element: HTMLElement,\n) {\n const mouseX = e.clientX;\n const mouseY = e.clientY;\n const leftX = mouseX - the3dElementBounds.x;\n const topY = mouseY - the3dElementBounds.y;\n const center = {\n x: leftX - the3dElementBounds.width / CENTER_DIVISOR,\n y: topY - the3dElementBounds.height / CENTER_DIVISOR,\n };\n const distance = Math.sqrt(\n center.x ** CENTER_DIVISOR + center.y ** CENTER_DIVISOR,\n );\n\n const rotate3d = `\n ${center.y / MOUSE_SCALE_FACTOR},\n ${-center.x / MOUSE_SCALE_FACTOR},\n 0,\n ${Math.log(distance) * ROTATION_DEGREE_MULTIPLIER}deg\n `;\n element.style.setProperty('--limel-3d-hover-effect-rotate3d', rotate3d);\n\n const glowPosition = `\n ${center.x * GLOW_POSITION_MULTIPLIER + the3dElementBounds.width / CENTER_DIVISOR}px\n `;\n element.style.setProperty(\n '--limel-3d-hover-effect-glow-position',\n glowPosition,\n );\n}\n\nexport function handleMouseEnter(\n element: HTMLElement,\n selector: string,\n setBounds: (bounds: DOMRect) => void,\n tiltCallback: (e: MouseEvent) => void,\n) {\n const the3dElement = element.shadowRoot.querySelector(\n selector,\n ) as HTMLElement;\n const bounds = the3dElement.getBoundingClientRect();\n setBounds(bounds);\n document.addEventListener('mousemove', tiltCallback);\n}\n\nexport function handleMouseLeave(\n element: HTMLElement,\n selector: string,\n tiltCallback: (e: MouseEvent) => void,\n) {\n const the3dElement = element.shadowRoot.querySelector(\n selector,\n ) as HTMLElement;\n document.removeEventListener('mousemove', tiltCallback);\n the3dElement.style.removeProperty('--limel-3d-hover-effect-rotate3d');\n the3dElement.style.removeProperty('--limel-3d-hover-effect-glow-position');\n}\n"]}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for creating a 3D tilt hover effect.
|
|
3
|
-
*
|
|
4
|
-
* This module provides functions that enables consumer components to display a nice 3D effect,
|
|
5
|
-
* when being hovered; enabling them to follow the cursor's position and tilt towards it.
|
|
6
|
-
*
|
|
7
|
-
* ## What you need, to make this work
|
|
8
|
-
* ### Typescript
|
|
9
|
-
* 1. Import the functions:
|
|
10
|
-
*
|
|
11
|
-
* ```tsx
|
|
12
|
-
* import {
|
|
13
|
-
* tiltFollowingTheCursor,
|
|
14
|
-
* handleMouseEnter,
|
|
15
|
-
* handleMouseLeave,
|
|
16
|
-
* } from './path/to/3d-tilt-hover-effect';
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* 2. In your component, define the necessary properties:
|
|
20
|
-
*
|
|
21
|
-
* ```tsx
|
|
22
|
-
* @Element() private element: HTMLElement;
|
|
23
|
-
* private the3dElementBounds: DOMRect;
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* 3. If your component does not already have event handlers,
|
|
27
|
-
* implement them using the imported functions from this file:
|
|
28
|
-
*
|
|
29
|
-
* ```tsx
|
|
30
|
-
* private handleMouseEnter = () => {
|
|
31
|
-
* handleMouseEnter(this.element, 'section', (bounds) => {
|
|
32
|
-
* this.the3dElementBounds = bounds;
|
|
33
|
-
* }, this.tiltFollowingTheCursor);
|
|
34
|
-
* };
|
|
35
|
-
*
|
|
36
|
-
* private handleMouseLeave = () => {
|
|
37
|
-
* handleMouseLeave(this.element, this.tiltFollowingTheCursor);
|
|
38
|
-
* };
|
|
39
|
-
*
|
|
40
|
-
* private tiltFollowingTheCursor = (e: MouseEvent) => {
|
|
41
|
-
* tiltFollowingTheCursor(e, this.the3dElementBounds, this.element);
|
|
42
|
-
* };
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* 4. Attach the event handlers to the relevant elements in your render method:
|
|
46
|
-
*
|
|
47
|
-
* ```tsx
|
|
48
|
-
* public render() {
|
|
49
|
-
* return (
|
|
50
|
-
* <section
|
|
51
|
-
* onMouseEnter={this.handleMouseEnter}
|
|
52
|
-
* onMouseLeave={this.handleMouseLeave}
|
|
53
|
-
* >
|
|
54
|
-
* Your content here
|
|
55
|
-
* </section>
|
|
56
|
-
* );
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* :::note
|
|
61
|
-
* - Ensure that the `element` and `the3dElementBounds` properties are properly
|
|
62
|
-
* defined in your component.
|
|
63
|
-
* - The `selector` parameter in `handleMouseEnter` should match the selector
|
|
64
|
-
* of the element you want to apply the 3D effect to.
|
|
65
|
-
* - The `tiltFollowingTheCursor` function calculates the 3D rotation and glow
|
|
66
|
-
* position based on the cursor's position relative to the element's bounds.
|
|
67
|
-
* :::
|
|
68
|
-
*
|
|
69
|
-
* ### HTML elements + CSS
|
|
70
|
-
* 1. Add a `<div class="limel-3d-hover-effect-glow" />` element to your component's template,
|
|
71
|
-
* inside the element you want to apply the 3D effect to, and preferably at the bottom of all
|
|
72
|
-
* other elements within that element (to avoid the need to specifying `z-index`es).
|
|
73
|
-
* 2. Add the following `mixin` to your component's SCSS file:
|
|
74
|
-
* `limel-3d-hover-effect-glow($the3dElement, $border-radius);`
|
|
75
|
-
*
|
|
76
|
-
* and don't forget to define the `$the3dElement` variables for the mixin to work
|
|
77
|
-
* (and optionally the `$border-radius`).
|
|
78
|
-
* 3. Keep in mind that the `<div class="limel-3d-hover-effect-glow" />` will be
|
|
79
|
-
* absolutely positioned inside the parent element, so make sure the parent element
|
|
80
|
-
* has `position` set.
|
|
81
|
-
* 4. Add the following `mixin` to the host element: `parent-of-the-3d-element`.
|
|
82
|
-
* 5. Add the following `mixin` to the 3D element: `the-3d-element`.
|
|
83
|
-
* 6. And if your element is supposed to be clickable, add this `mixin` as well: `the-3d-element--clickable`.
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
export declare const MOUSE_SCALE_FACTOR = 100;
|
|
87
|
-
export declare const ROTATION_DEGREE_MULTIPLIER = 1.6;
|
|
88
|
-
export declare const GLOW_POSITION_MULTIPLIER = 2;
|
|
89
|
-
export declare const CENTER_DIVISOR = 2;
|
|
90
|
-
export declare function tiltFollowingTheCursor(e: MouseEvent, the3dElementBounds: DOMRect, element: HTMLElement): void;
|
|
91
|
-
export declare function handleMouseEnter(element: HTMLElement, selector: string, setBounds: (bounds: DOMRect) => void, tiltCallback: (e: MouseEvent) => void): void;
|
|
92
|
-
export declare function handleMouseLeave(element: HTMLElement, selector: string, tiltCallback: (e: MouseEvent) => void): void;
|
|
93
|
-
//# sourceMappingURL=3d-tilt-hover-effect.d.ts.map
|