@dpouris/gswap 0.0.3 → 0.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dpouris/gswap",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
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",
@@ -9,7 +9,8 @@
9
9
  "./README.md"
10
10
  ],
11
11
  "directories": {
12
- "example": "examples"
12
+ "example": "examples",
13
+ "gswap": "dist"
13
14
  },
14
15
  "scripts": {
15
16
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -18,6 +19,6 @@
18
19
  "author": "dpouris",
19
20
  "license": "ISC",
20
21
  "dependencies": {
21
- "@dpouris/gswap": "^0.0.1"
22
+ "@dpouris/gswap": "^0.0.3"
22
23
  }
23
24
  }
package/dist/main.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/main.js DELETED
@@ -1,166 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- export { GSwap as GSwap } from "./main";
package/dist/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GSwap = void 0;
4
- var main_1 = require("./main");
5
- Object.defineProperty(exports, "GSwap", { enumerable: true, get: function () { return main_1.GSwap; } });
@@ -1,14 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });