@dpouris/gswap 0.0.1-alpha → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +160 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +166 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/main.d.ts +11 -0
- package/dist/src/main.js +177 -0
- package/dist/types/GallerySwapType.d.ts +14 -0
- package/dist/types/GallerySwapType.js +2 -0
- package/dist/types/GallerySwapTypes.d.ts +14 -0
- package/dist/types/GallerySwapTypes.js +2 -0
- package/package.json +7 -3
package/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# GSwap 🌠
|
2
|
+
|
3
|
+
### Create a gallery of images with ease.
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
To get started, in your project folder, run:
|
8
|
+
|
9
|
+
```
|
10
|
+
npm i @dpouris/gswap
|
11
|
+
```
|
12
|
+
|
13
|
+
# Usage 🔨
|
14
|
+
|
15
|
+
First, import the library and create a new gswap instance:
|
16
|
+
|
17
|
+
```
|
18
|
+
import { GSwap } from '@dpouris/gswap';
|
19
|
+
|
20
|
+
...
|
21
|
+
|
22
|
+
const = document.getElementById("gallery")
|
23
|
+
|
24
|
+
const gswap = new GSwap({
|
25
|
+
containerElem: galleryContainer,
|
26
|
+
|
27
|
+
images: ["./1.jpg", "./2.jpg", "./3.webp"],
|
28
|
+
|
29
|
+
options : {
|
30
|
+
//animation: "fade", -> Todo
|
31
|
+
animationDuration: "300",
|
32
|
+
navigation: true,
|
33
|
+
// repeat: true, -> Todo
|
34
|
+
imgDimensions: { height: 300, width: 300 },
|
35
|
+
}
|
36
|
+
});
|
37
|
+
```
|
38
|
+
|
39
|
+
This will create a new instance of gswap and will place the gallery absolutely inside the container you specified.
|
40
|
+
|
41
|
+
- **containerElem** (_required_):
|
42
|
+
- The container (div) element where the gallery will be placed absolutely.
|
43
|
+
- **images** (_required_):
|
44
|
+
- An array of image paths.
|
45
|
+
- **options** (_optional_):
|
46
|
+
- An object of options.
|
47
|
+
- See the [options](#Options) section for more details.
|
48
|
+
|
49
|
+
# Options ⚙️
|
50
|
+
|
51
|
+
## **animation** (_fade_ | _slide_ | _none_) -> [wip]
|
52
|
+
|
53
|
+
Takes in an animation eg. fade or slide and applies it to the switching motion of the images.
|
54
|
+
|
55
|
+
- **fade**:
|
56
|
+
Fades the images in and out.
|
57
|
+
- **slide**:
|
58
|
+
Slides the images in and out.
|
59
|
+
- **none**:
|
60
|
+
Does not apply any animation.
|
61
|
+
|
62
|
+
- **Default**: fade
|
63
|
+
|
64
|
+
---
|
65
|
+
|
66
|
+
## **animationDuration** (_number_)
|
67
|
+
|
68
|
+
Takes in the duration of the animation that occurs upon switching the images and the speed at which the images move, in milliseconds. # 1000 = 1 second.
|
69
|
+
|
70
|
+
- **Default**: 300
|
71
|
+
|
72
|
+
---
|
73
|
+
|
74
|
+
## **navigation** (_boolean_ | forwardOnly | backOnly)
|
75
|
+
|
76
|
+
If true, the navigation arrows will be displayed. # true | false | "forwardOnly" | "backOnly"
|
77
|
+
|
78
|
+
- **forwardOnly**:
|
79
|
+
Only the forward arrow will be displayed.
|
80
|
+
- **backOnly**:
|
81
|
+
Only the back arrow will be displayed.
|
82
|
+
|
83
|
+
- **Default**: true
|
84
|
+
|
85
|
+
---
|
86
|
+
|
87
|
+
## **repeat** (_boolean_) -> [wip]
|
88
|
+
|
89
|
+
If true, the gallery will loop infinitely. # true || false
|
90
|
+
|
91
|
+
[wip]
|
92
|
+
|
93
|
+
- **Default**: true
|
94
|
+
|
95
|
+
## direction (_top_ | _bottom_ | _left_ | _right_)
|
96
|
+
|
97
|
+
The direction of the gallery. # top || bottom
|
98
|
+
|
99
|
+
## imgDimensions (_object_ : {height : number, width: number})
|
100
|
+
|
101
|
+
Takes in an object that contains the keys of width and height that will be applied as the dimensions of the images. # { height: 300, width: 300 }
|
102
|
+
|
103
|
+
Default: { height: 300, width: 300 }
|
104
|
+
|
105
|
+
# Methods 🧑💻
|
106
|
+
|
107
|
+
- [**gswap.next()**](<#gswap.next()>)
|
108
|
+
- [**gswap.prev()**](<#gswap.next()>)
|
109
|
+
- [**gswap.goTo(index)**](<#gswap.goTo(index)>) -> [wip]
|
110
|
+
- [**gswap.stackImages()**](<#gswap.stackImages()>)
|
111
|
+
|
112
|
+
---
|
113
|
+
|
114
|
+
## **gswap.next()**
|
115
|
+
|
116
|
+
Displays the next image in the gallery.
|
117
|
+
You can call the **next()** method by calling it from the gallery instance like so.
|
118
|
+
|
119
|
+
```
|
120
|
+
const gallery = new GSwap(...);
|
121
|
+
|
122
|
+
...
|
123
|
+
|
124
|
+
gallery.next();
|
125
|
+
```
|
126
|
+
|
127
|
+
OR
|
128
|
+
|
129
|
+
You can bind the **next()** method to an onclick event like so.
|
130
|
+
|
131
|
+
```
|
132
|
+
const gallery = new GSwap(...);
|
133
|
+
const nextBtn = document.getElementById('nextGalleryBtn')
|
134
|
+
|
135
|
+
nextBtn.onclick = gallery.next;
|
136
|
+
```
|
137
|
+
|
138
|
+
**The same concept applies for the .prev() method the only difference being the it moves backwards through the images.**
|
139
|
+
|
140
|
+
## **gswap.goTo(index)** -> wip
|
141
|
+
|
142
|
+
Takes in an index and displays the image at that index.
|
143
|
+
|
144
|
+
[wip]
|
145
|
+
|
146
|
+
## **gswap.stackImages()**
|
147
|
+
|
148
|
+
Stacks the images in the gallery in case their position was altered.
|
149
|
+
|
150
|
+
Can be called from the gallery instance like so.
|
151
|
+
|
152
|
+
```
|
153
|
+
const gallery = new GSwap(...);
|
154
|
+
|
155
|
+
...
|
156
|
+
|
157
|
+
gallery.stackImages();
|
158
|
+
```
|
159
|
+
|
160
|
+
Thank you for trying out my first library and I hope you enjoy it. 🫡
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { GSwap as GSwap } from "./src/main";
|
package/dist/index.js
ADDED
package/dist/main.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/main.js
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
6
|
+
};
|
7
|
+
var _GSwap_instances, _GSwap_currentImg, _GSwap_createGSwapElement, _GSwap_createImageElements, _GSwap_createNavigation, _GSwap_appendElementsOnContainer, _GSwap_shiftImagesToTheRight, _GSwap_shiftImagesToTheLeft, _GSwap_findPrevActiveElem, _GSwap_findNextActiveElement;
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
class GSwap {
|
10
|
+
constructor(containerElem, images, options) {
|
11
|
+
_GSwap_instances.add(this);
|
12
|
+
_GSwap_currentImg.set(this, 0);
|
13
|
+
_GSwap_createNavigation.set(this, () => {
|
14
|
+
const nav = document.createElement("nav");
|
15
|
+
nav.classList.add("gallery-swap-nav");
|
16
|
+
const navLeft = document.createElement("button");
|
17
|
+
navLeft.onclick = this.prev;
|
18
|
+
navLeft.innerText = "Left";
|
19
|
+
navLeft.classList.add("gallery-swap-nav-left");
|
20
|
+
const navRight = document.createElement("button");
|
21
|
+
navRight.onclick = this.next;
|
22
|
+
navRight.innerText = "Right";
|
23
|
+
navRight.classList.add("gallery-swap-nav-right");
|
24
|
+
if (this.options.navigation === "forwardOnly") {
|
25
|
+
nav.appendChild(navRight);
|
26
|
+
return nav;
|
27
|
+
}
|
28
|
+
if (this.options.navigation === "backOnly") {
|
29
|
+
nav.appendChild(navLeft);
|
30
|
+
return nav;
|
31
|
+
}
|
32
|
+
nav.appendChild(navLeft);
|
33
|
+
nav.appendChild(navRight);
|
34
|
+
return nav;
|
35
|
+
});
|
36
|
+
_GSwap_shiftImagesToTheRight.set(this, () => {
|
37
|
+
const last = this.containerElem.children[0].lastElementChild;
|
38
|
+
this.containerElem.children[0].insertAdjacentHTML("afterbegin", last.outerHTML);
|
39
|
+
last.remove();
|
40
|
+
});
|
41
|
+
_GSwap_shiftImagesToTheLeft.set(this, () => {
|
42
|
+
const first = this.containerElem.children[0]
|
43
|
+
.firstElementChild;
|
44
|
+
this.containerElem.children[0].insertAdjacentHTML("beforeend", first.outerHTML);
|
45
|
+
first.style.opacity = "0";
|
46
|
+
first.remove();
|
47
|
+
// first.remove();
|
48
|
+
});
|
49
|
+
_GSwap_findPrevActiveElem.set(this, () => {
|
50
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
51
|
+
const imgElem = image;
|
52
|
+
if (imgElem.classList.contains("active")) {
|
53
|
+
imgElem.classList.remove("active");
|
54
|
+
}
|
55
|
+
});
|
56
|
+
const activeElem = this.containerElem.children[0]
|
57
|
+
.lastElementChild;
|
58
|
+
activeElem.style.opacity = "0";
|
59
|
+
setTimeout(() => {
|
60
|
+
activeElem.style.opacity = "1";
|
61
|
+
}, parseInt(this.options.animationDuration));
|
62
|
+
activeElem.classList.add("active");
|
63
|
+
});
|
64
|
+
_GSwap_findNextActiveElement.set(this, () => {
|
65
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
66
|
+
const imgElem = image;
|
67
|
+
if (imgElem.classList.contains("active")) {
|
68
|
+
imgElem.classList.remove("active");
|
69
|
+
imgElem.style.opacity = "0";
|
70
|
+
setTimeout(() => {
|
71
|
+
imgElem.style.opacity = "1";
|
72
|
+
}, parseInt(this.options.animationDuration));
|
73
|
+
}
|
74
|
+
});
|
75
|
+
const activeElem = this.containerElem.children[0].lastElementChild;
|
76
|
+
activeElem.classList.add("active");
|
77
|
+
});
|
78
|
+
this.stackImages = () => {
|
79
|
+
let directionLeft;
|
80
|
+
let directionTop;
|
81
|
+
switch (this.options.direction) {
|
82
|
+
case "left":
|
83
|
+
directionLeft = 20;
|
84
|
+
directionTop = 20;
|
85
|
+
break;
|
86
|
+
case "right":
|
87
|
+
directionLeft = -20;
|
88
|
+
directionTop = 20;
|
89
|
+
break;
|
90
|
+
case "top":
|
91
|
+
directionLeft = 0;
|
92
|
+
directionTop = 20;
|
93
|
+
break;
|
94
|
+
case "bottom":
|
95
|
+
directionLeft = 0;
|
96
|
+
directionTop = -20;
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
let counter = 0;
|
100
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
101
|
+
image.style.position = "absolute";
|
102
|
+
image.style.opacity = "1";
|
103
|
+
image.style.top =
|
104
|
+
(counter * directionTop).toString() + "px";
|
105
|
+
image.style.left =
|
106
|
+
(counter * directionLeft).toString() + "px";
|
107
|
+
counter++;
|
108
|
+
});
|
109
|
+
};
|
110
|
+
this.next = () => {
|
111
|
+
__classPrivateFieldGet(this, _GSwap_shiftImagesToTheRight, "f").call(this);
|
112
|
+
this.stackImages();
|
113
|
+
__classPrivateFieldGet(this, _GSwap_findNextActiveElement, "f").call(this);
|
114
|
+
};
|
115
|
+
this.prev = () => {
|
116
|
+
__classPrivateFieldGet(this, _GSwap_shiftImagesToTheLeft, "f").call(this);
|
117
|
+
this.stackImages();
|
118
|
+
__classPrivateFieldGet(this, _GSwap_findPrevActiveElem, "f").call(this);
|
119
|
+
};
|
120
|
+
this.containerElem = containerElem;
|
121
|
+
this.images = images;
|
122
|
+
this.options = options;
|
123
|
+
this.options.direction = this.options.direction
|
124
|
+
? this.options.direction
|
125
|
+
: "left";
|
126
|
+
this.options.navigation =
|
127
|
+
this.options.navigation === undefined ? true : this.options.navigation;
|
128
|
+
__classPrivateFieldGet(this, _GSwap_instances, "m", _GSwap_appendElementsOnContainer).call(this);
|
129
|
+
this.stackImages();
|
130
|
+
}
|
131
|
+
}
|
132
|
+
_GSwap_currentImg = new WeakMap(), _GSwap_createNavigation = new WeakMap(), _GSwap_shiftImagesToTheRight = new WeakMap(), _GSwap_shiftImagesToTheLeft = new WeakMap(), _GSwap_findPrevActiveElem = new WeakMap(), _GSwap_findNextActiveElement = new WeakMap(), _GSwap_instances = new WeakSet(), _GSwap_createGSwapElement = function _GSwap_createGSwapElement() {
|
133
|
+
const GSElement = document.createElement("div");
|
134
|
+
GSElement.classList.add("gallery-swap");
|
135
|
+
// GSElement.style.transition = `all ${this.options.animationDuration} ${this.options.animation}`;
|
136
|
+
GSElement.style.height = this.options.imgDimensions.height * 2 + "px";
|
137
|
+
GSElement.style.width = this.options.imgDimensions.width * 2 + "px";
|
138
|
+
GSElement.style.position = "relative";
|
139
|
+
// GSElement.style.animation = this.options.animation;
|
140
|
+
// GSElement.style.animationDuration = this.options.animationDuration;
|
141
|
+
// const imageContainer = document.createElement("div");
|
142
|
+
// Place images inside div container
|
143
|
+
const images = __classPrivateFieldGet(this, _GSwap_instances, "m", _GSwap_createImageElements).call(this);
|
144
|
+
images.forEach((image) => {
|
145
|
+
GSElement.appendChild(image);
|
146
|
+
});
|
147
|
+
return GSElement;
|
148
|
+
}, _GSwap_createImageElements = function _GSwap_createImageElements() {
|
149
|
+
return this.images.map((image) => {
|
150
|
+
const imgElement = document.createElement("img");
|
151
|
+
if (image === this.images[this.images.length - 1]) {
|
152
|
+
imgElement.classList.add("active");
|
153
|
+
}
|
154
|
+
imgElement.src = image;
|
155
|
+
imgElement.width = this.options.imgDimensions.width;
|
156
|
+
imgElement.height = this.options.imgDimensions.height;
|
157
|
+
imgElement.style.transition = `all ${this.options.animationDuration}ms ease-out`;
|
158
|
+
return imgElement;
|
159
|
+
});
|
160
|
+
}, _GSwap_appendElementsOnContainer = function _GSwap_appendElementsOnContainer() {
|
161
|
+
this.containerElem.innerHTML = "";
|
162
|
+
this.containerElem.appendChild(__classPrivateFieldGet(this, _GSwap_instances, "m", _GSwap_createGSwapElement).call(this));
|
163
|
+
if (this.options.navigation === true) {
|
164
|
+
this.containerElem.appendChild(__classPrivateFieldGet(this, _GSwap_createNavigation, "f").call(this));
|
165
|
+
}
|
166
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { GSwap as GSwap } from "./main";
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { Options } from "../types/GallerySwapTypes";
|
2
|
+
export declare class GSwap {
|
3
|
+
#private;
|
4
|
+
containerElem: HTMLDivElement;
|
5
|
+
images: string[];
|
6
|
+
options: Options;
|
7
|
+
constructor(containerElem: HTMLDivElement, images: string[], options: Options);
|
8
|
+
stackImages: () => void;
|
9
|
+
next: () => void;
|
10
|
+
prev: () => void;
|
11
|
+
}
|
package/dist/src/main.js
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
6
|
+
};
|
7
|
+
var _GSwap_instances, _GSwap_currentImg, _GSwap_createGSwapElement, _GSwap_createImageElements, _GSwap_createNavigation, _GSwap_appendElementsOnContainer, _GSwap_shiftImagesToTheRight, _GSwap_shiftImagesToTheLeft, _GSwap_findPrevActiveElem, _GSwap_findNextActiveElement;
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.GSwap = void 0;
|
10
|
+
class GSwap {
|
11
|
+
constructor(containerElem, images, options) {
|
12
|
+
_GSwap_instances.add(this);
|
13
|
+
_GSwap_currentImg.set(this, 0);
|
14
|
+
_GSwap_createNavigation.set(this, () => {
|
15
|
+
const nav = document.createElement("nav");
|
16
|
+
nav.classList.add("gallery-swap-nav");
|
17
|
+
const navLeft = document.createElement("button");
|
18
|
+
navLeft.onclick = this.prev;
|
19
|
+
navLeft.innerHTML = "→";
|
20
|
+
navLeft.classList.add("gallery-swap-nav-left");
|
21
|
+
const navRight = document.createElement("button");
|
22
|
+
navRight.onclick = this.next;
|
23
|
+
navRight.innerHTML = "←";
|
24
|
+
navRight.classList.add("gallery-swap-nav-right");
|
25
|
+
if (this.options.navigation === "forwardOnly") {
|
26
|
+
nav.appendChild(navRight);
|
27
|
+
return nav;
|
28
|
+
}
|
29
|
+
if (this.options.navigation === "backOnly") {
|
30
|
+
nav.appendChild(navLeft);
|
31
|
+
return nav;
|
32
|
+
}
|
33
|
+
nav.appendChild(navLeft);
|
34
|
+
nav.appendChild(navRight);
|
35
|
+
return nav;
|
36
|
+
});
|
37
|
+
_GSwap_shiftImagesToTheRight.set(this, () => {
|
38
|
+
const last = this.containerElem.children[0].lastElementChild;
|
39
|
+
this.containerElem.children[0].insertAdjacentHTML("afterbegin", last.outerHTML);
|
40
|
+
last.remove();
|
41
|
+
});
|
42
|
+
_GSwap_shiftImagesToTheLeft.set(this, () => {
|
43
|
+
const first = this.containerElem.children[0]
|
44
|
+
.firstElementChild;
|
45
|
+
this.containerElem.children[0].insertAdjacentHTML("beforeend", first.outerHTML);
|
46
|
+
first.style.opacity = "0";
|
47
|
+
first.remove();
|
48
|
+
// first.remove();
|
49
|
+
});
|
50
|
+
_GSwap_findPrevActiveElem.set(this, () => {
|
51
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
52
|
+
const imgElem = image;
|
53
|
+
if (imgElem.classList.contains("active")) {
|
54
|
+
imgElem.classList.remove("active");
|
55
|
+
}
|
56
|
+
});
|
57
|
+
const activeElem = this.containerElem.children[0]
|
58
|
+
.lastElementChild;
|
59
|
+
activeElem.style.opacity = "0";
|
60
|
+
setTimeout(() => {
|
61
|
+
activeElem.style.opacity = "1";
|
62
|
+
}, this.options.animationDuration);
|
63
|
+
activeElem.classList.add("active");
|
64
|
+
});
|
65
|
+
_GSwap_findNextActiveElement.set(this, () => {
|
66
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
67
|
+
const imgElem = image;
|
68
|
+
if (imgElem.classList.contains("active")) {
|
69
|
+
imgElem.classList.remove("active");
|
70
|
+
imgElem.style.opacity = "0";
|
71
|
+
setTimeout(() => {
|
72
|
+
imgElem.style.opacity = "1";
|
73
|
+
}, this.options.animationDuration);
|
74
|
+
}
|
75
|
+
});
|
76
|
+
const activeElem = this.containerElem.children[0].lastElementChild;
|
77
|
+
activeElem.classList.add("active");
|
78
|
+
});
|
79
|
+
this.stackImages = () => {
|
80
|
+
let directionLeft;
|
81
|
+
let directionTop;
|
82
|
+
switch (this.options.direction) {
|
83
|
+
case "left":
|
84
|
+
directionLeft = 20;
|
85
|
+
directionTop = 20;
|
86
|
+
break;
|
87
|
+
case "right":
|
88
|
+
directionLeft = -20;
|
89
|
+
directionTop = 20;
|
90
|
+
break;
|
91
|
+
case "top":
|
92
|
+
directionLeft = 0;
|
93
|
+
directionTop = 20;
|
94
|
+
break;
|
95
|
+
case "bottom":
|
96
|
+
directionLeft = 0;
|
97
|
+
directionTop = -20;
|
98
|
+
break;
|
99
|
+
}
|
100
|
+
let counter = 0;
|
101
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
102
|
+
image.style.position = "absolute";
|
103
|
+
image.style.opacity = "1";
|
104
|
+
image.style.top =
|
105
|
+
(counter * directionTop).toString() + "px";
|
106
|
+
image.style.left =
|
107
|
+
(counter * directionLeft).toString() + "px";
|
108
|
+
counter++;
|
109
|
+
});
|
110
|
+
};
|
111
|
+
this.next = () => {
|
112
|
+
__classPrivateFieldGet(this, _GSwap_shiftImagesToTheRight, "f").call(this);
|
113
|
+
this.stackImages();
|
114
|
+
__classPrivateFieldGet(this, _GSwap_findNextActiveElement, "f").call(this);
|
115
|
+
};
|
116
|
+
this.prev = () => {
|
117
|
+
__classPrivateFieldGet(this, _GSwap_shiftImagesToTheLeft, "f").call(this);
|
118
|
+
this.stackImages();
|
119
|
+
__classPrivateFieldGet(this, _GSwap_findPrevActiveElem, "f").call(this);
|
120
|
+
};
|
121
|
+
this.containerElem = containerElem;
|
122
|
+
this.images = images;
|
123
|
+
this.options = options;
|
124
|
+
this.options.imgDimensions = this.options
|
125
|
+
.imgDimensions.hasOwnProperty("height")
|
126
|
+
.hasOwnProperty("width")
|
127
|
+
? this.options.imgDimensions
|
128
|
+
: { width: 300, height: 300 };
|
129
|
+
this.options.direction = this.options.direction;
|
130
|
+
this.options.animationDuration =
|
131
|
+
this.options.animationDuration === undefined
|
132
|
+
? 300
|
133
|
+
: this.options.animationDuration;
|
134
|
+
this.options.direction =
|
135
|
+
this.options.direction === undefined ? "left" : this.options.direction;
|
136
|
+
this.options.navigation =
|
137
|
+
this.options.navigation === undefined ? true : this.options.navigation;
|
138
|
+
__classPrivateFieldGet(this, _GSwap_instances, "m", _GSwap_appendElementsOnContainer).call(this);
|
139
|
+
this.stackImages();
|
140
|
+
}
|
141
|
+
}
|
142
|
+
exports.GSwap = GSwap;
|
143
|
+
_GSwap_currentImg = new WeakMap(), _GSwap_createNavigation = new WeakMap(), _GSwap_shiftImagesToTheRight = new WeakMap(), _GSwap_shiftImagesToTheLeft = new WeakMap(), _GSwap_findPrevActiveElem = new WeakMap(), _GSwap_findNextActiveElement = new WeakMap(), _GSwap_instances = new WeakSet(), _GSwap_createGSwapElement = function _GSwap_createGSwapElement() {
|
144
|
+
const GSElement = document.createElement("div");
|
145
|
+
GSElement.classList.add("gallery-swap");
|
146
|
+
// GSElement.style.transition = `all ${this.options.animationDuration} ${this.options.animation}`;
|
147
|
+
GSElement.style.height = this.options.imgDimensions.height * 2 + "px";
|
148
|
+
GSElement.style.width = this.options.imgDimensions.width * 2 + "px";
|
149
|
+
GSElement.style.position = "relative";
|
150
|
+
// GSElement.style.animation = this.options.animation;
|
151
|
+
// GSElement.style.animationDuration = this.options.animationDuration;
|
152
|
+
// const imageContainer = document.createElement("div");
|
153
|
+
// Place images inside div container
|
154
|
+
const images = __classPrivateFieldGet(this, _GSwap_instances, "m", _GSwap_createImageElements).call(this);
|
155
|
+
images.forEach((image) => {
|
156
|
+
GSElement.appendChild(image);
|
157
|
+
});
|
158
|
+
return GSElement;
|
159
|
+
}, _GSwap_createImageElements = function _GSwap_createImageElements() {
|
160
|
+
return this.images.map((image) => {
|
161
|
+
const imgElement = document.createElement("img");
|
162
|
+
if (image === this.images[this.images.length - 1]) {
|
163
|
+
imgElement.classList.add("active");
|
164
|
+
}
|
165
|
+
imgElement.src = image;
|
166
|
+
imgElement.width = this.options.imgDimensions.width;
|
167
|
+
imgElement.height = this.options.imgDimensions.height;
|
168
|
+
imgElement.style.transition = `all ${this.options.animationDuration}ms ease-in-out`;
|
169
|
+
return imgElement;
|
170
|
+
});
|
171
|
+
}, _GSwap_appendElementsOnContainer = function _GSwap_appendElementsOnContainer() {
|
172
|
+
this.containerElem.innerHTML = "";
|
173
|
+
this.containerElem.appendChild(__classPrivateFieldGet(this, _GSwap_instances, "m", _GSwap_createGSwapElement).call(this));
|
174
|
+
if (this.options.navigation === true) {
|
175
|
+
this.containerElem.appendChild(__classPrivateFieldGet(this, _GSwap_createNavigation, "f").call(this));
|
176
|
+
}
|
177
|
+
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export interface GallerySwap {
|
2
|
+
container: HTMLDivElement;
|
3
|
+
}
|
4
|
+
export declare type Options = {
|
5
|
+
animation: string;
|
6
|
+
animationDuration: string;
|
7
|
+
navigation: boolean | "forwardOnly" | "backOnly";
|
8
|
+
repeat?: boolean;
|
9
|
+
direction?: "left" | "right" | "top" | "bottom";
|
10
|
+
imgDimensions: {
|
11
|
+
height: number;
|
12
|
+
width: number;
|
13
|
+
};
|
14
|
+
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export interface GallerySwap {
|
2
|
+
container: HTMLDivElement;
|
3
|
+
}
|
4
|
+
export declare type Options = {
|
5
|
+
animation?: string;
|
6
|
+
animationDuration?: number;
|
7
|
+
navigation?: boolean | "forwardOnly" | "backOnly";
|
8
|
+
repeat?: boolean;
|
9
|
+
direction?: "left" | "right" | "top" | "bottom";
|
10
|
+
imgDimensions?: {
|
11
|
+
height: number;
|
12
|
+
width: number;
|
13
|
+
};
|
14
|
+
};
|
package/package.json
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dpouris/gswap",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
4
|
"description": "A library for swapping between images in a gallery",
|
5
5
|
"main": "./dist/main.js",
|
6
6
|
"types": "./dist/main.d.ts",
|
7
7
|
"files": [
|
8
|
-
"
|
8
|
+
"/dist",
|
9
|
+
"./README.md"
|
9
10
|
],
|
10
11
|
"directories": {
|
11
12
|
"example": "examples"
|
@@ -15,5 +16,8 @@
|
|
15
16
|
},
|
16
17
|
"keywords": [],
|
17
18
|
"author": "dpouris",
|
18
|
-
"license": "ISC"
|
19
|
+
"license": "ISC",
|
20
|
+
"dependencies": {
|
21
|
+
"@dpouris/gswap": "^0.0.1"
|
22
|
+
}
|
19
23
|
}
|