@dpouris/gswap 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/example-1/index.html +13 -0
- package/examples/example-1/public/assets/1.jpg +0 -0
- package/examples/example-1/public/assets/2.jpg +0 -0
- package/examples/example-1/public/assets/3.webp +0 -0
- package/examples/example-1/script.js +29 -0
- package/index.js +10 -0
- package/package.json +4 -7
- package/src/index.d.ts +1 -0
- package/src/index.ts +1 -0
- package/{dist/src → src}/main.d.ts +0 -0
- package/{dist/src → src}/main.js +1 -1
- package/src/main.ts +213 -0
- package/tsconfig.json +102 -0
- package/{dist/types → types}/GallerySwapTypes.d.ts +0 -0
- package/{dist/types → types}/GallerySwapTypes.js +0 -0
- package/types/GallerySwapTypes.ts +15 -0
- package/dist/main.d.ts +0 -1
- package/dist/main.js +0 -166
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -5
- package/dist/types/GallerySwapType.d.ts +0 -14
- package/dist/types/GallerySwapType.js +0 -2
@@ -0,0 +1,13 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8" />
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7
|
+
<script src="./script.js" defer></script>
|
8
|
+
<title>Document</title>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<div id="gallery"></div>
|
12
|
+
</body>
|
13
|
+
</html>
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { GSwap } from "@dpouris/gswap";
|
2
|
+
|
3
|
+
const gallery = new GSwap(
|
4
|
+
document.getElementById("gallery"),
|
5
|
+
["./1.jpg", "./2.jpg", "./3.webp"],
|
6
|
+
{
|
7
|
+
animation: "fade",
|
8
|
+
animationDuration: "300",
|
9
|
+
navigation: true,
|
10
|
+
repeat: true,
|
11
|
+
imgDimensions: { height: 300, width: 300 },
|
12
|
+
}
|
13
|
+
);
|
14
|
+
|
15
|
+
// const stackBtn = document.createElement("button");
|
16
|
+
// const prevBtn = document.createElement("button");
|
17
|
+
// const nextBtn = document.createElement("button");
|
18
|
+
|
19
|
+
// stackBtn.onclick = gallery.stackImages;
|
20
|
+
// prevBtn.onclick = gallery.prev;
|
21
|
+
// nextBtn.onclick = gallery.next;
|
22
|
+
|
23
|
+
// // stackBtn.innerText = "Stack";
|
24
|
+
// prevBtn.innerText = "Prev";
|
25
|
+
// nextBtn.innerText = "Next";
|
26
|
+
|
27
|
+
// // document.body.appendChild(stackBtn);
|
28
|
+
// document.body.appendChild(prevBtn);
|
29
|
+
// document.body.appendChild(nextBtn);
|
package/index.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.GSwap = void 0;
|
4
|
+
var main_1 = require("./src/main");
|
5
|
+
Object.defineProperty(exports, "GSwap", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function () {
|
8
|
+
return main_1.GSwap;
|
9
|
+
},
|
10
|
+
});
|
package/package.json
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dpouris/gswap",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.5",
|
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
|
-
"files": [
|
8
|
-
"/dist",
|
9
|
-
"./README.md"
|
10
|
-
],
|
11
7
|
"directories": {
|
12
|
-
"example": "examples"
|
8
|
+
"example": "examples",
|
9
|
+
"gswap": "dist"
|
13
10
|
},
|
14
11
|
"scripts": {
|
15
12
|
"test": "echo \"Error: no test specified\" && exit 1"
|
@@ -18,6 +15,6 @@
|
|
18
15
|
"author": "dpouris",
|
19
16
|
"license": "ISC",
|
20
17
|
"dependencies": {
|
21
|
-
"@dpouris/gswap": "^0.0.
|
18
|
+
"@dpouris/gswap": "^0.0.3"
|
22
19
|
}
|
23
20
|
}
|
package/src/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { GSwap as GSwap } from "./main";
|
package/src/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { GSwap as GSwap } from "./main";
|
File without changes
|
package/{dist/src → src}/main.js
RENAMED
@@ -165,7 +165,7 @@ _GSwap_currentImg = new WeakMap(), _GSwap_createNavigation = new WeakMap(), _GSw
|
|
165
165
|
imgElement.src = image;
|
166
166
|
imgElement.width = this.options.imgDimensions.width;
|
167
167
|
imgElement.height = this.options.imgDimensions.height;
|
168
|
-
imgElement.style.transition = `all ${this.options.animationDuration}ms ease-out`;
|
168
|
+
imgElement.style.transition = `all ${this.options.animationDuration}ms ease-in-out`;
|
169
169
|
return imgElement;
|
170
170
|
});
|
171
171
|
}, _GSwap_appendElementsOnContainer = function _GSwap_appendElementsOnContainer() {
|
package/src/main.ts
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
import type { Options } from "../types/GallerySwapTypes";
|
2
|
+
|
3
|
+
export class GSwap {
|
4
|
+
containerElem: HTMLDivElement;
|
5
|
+
images: string[];
|
6
|
+
options: Options;
|
7
|
+
|
8
|
+
#currentImg: number = 0;
|
9
|
+
|
10
|
+
constructor(
|
11
|
+
containerElem: HTMLDivElement,
|
12
|
+
images: string[],
|
13
|
+
options: Options
|
14
|
+
) {
|
15
|
+
this.containerElem = containerElem;
|
16
|
+
this.images = images;
|
17
|
+
this.options = options;
|
18
|
+
|
19
|
+
this.options.imgDimensions = this.options
|
20
|
+
.imgDimensions!.hasOwnProperty("height")
|
21
|
+
.hasOwnProperty("width")
|
22
|
+
? this.options.imgDimensions
|
23
|
+
: { width: 300, height: 300 };
|
24
|
+
this.options.direction = this.options.direction;
|
25
|
+
this.options.animationDuration =
|
26
|
+
this.options.animationDuration === undefined
|
27
|
+
? 300
|
28
|
+
: this.options.animationDuration;
|
29
|
+
this.options.direction =
|
30
|
+
this.options.direction === undefined ? "left" : this.options.direction;
|
31
|
+
this.options.navigation =
|
32
|
+
this.options.navigation === undefined ? true : this.options.navigation;
|
33
|
+
|
34
|
+
this.#appendElementsOnContainer();
|
35
|
+
|
36
|
+
this.stackImages();
|
37
|
+
}
|
38
|
+
|
39
|
+
#createGSwapElement() {
|
40
|
+
const GSElement = document.createElement("div");
|
41
|
+
GSElement.classList.add("gallery-swap");
|
42
|
+
// GSElement.style.transition = `all ${this.options.animationDuration} ${this.options.animation}`;
|
43
|
+
GSElement.style.height = this.options.imgDimensions!.height * 2 + "px";
|
44
|
+
GSElement.style.width = this.options.imgDimensions!.width * 2 + "px";
|
45
|
+
GSElement.style.position = "relative";
|
46
|
+
// GSElement.style.animation = this.options.animation;
|
47
|
+
// GSElement.style.animationDuration = this.options.animationDuration;
|
48
|
+
|
49
|
+
// const imageContainer = document.createElement("div");
|
50
|
+
|
51
|
+
// Place images inside div container
|
52
|
+
const images = this.#createImageElements();
|
53
|
+
images.forEach((image) => {
|
54
|
+
GSElement.appendChild(image);
|
55
|
+
});
|
56
|
+
return GSElement;
|
57
|
+
}
|
58
|
+
|
59
|
+
#createImageElements() {
|
60
|
+
return this.images.map((image) => {
|
61
|
+
const imgElement = document.createElement("img");
|
62
|
+
if (image === this.images[this.images.length - 1]) {
|
63
|
+
imgElement.classList.add("active");
|
64
|
+
}
|
65
|
+
imgElement.src = image;
|
66
|
+
imgElement.width = this.options.imgDimensions!.width;
|
67
|
+
imgElement.height = this.options.imgDimensions!.height;
|
68
|
+
imgElement.style.transition = `all ${this.options.animationDuration}ms ease-in-out`;
|
69
|
+
return imgElement;
|
70
|
+
});
|
71
|
+
}
|
72
|
+
|
73
|
+
#createNavigation = () => {
|
74
|
+
const nav = document.createElement("nav");
|
75
|
+
nav.classList.add("gallery-swap-nav");
|
76
|
+
|
77
|
+
const navLeft = document.createElement("button");
|
78
|
+
navLeft.onclick = this.prev;
|
79
|
+
|
80
|
+
navLeft.innerHTML = "→";
|
81
|
+
navLeft.classList.add("gallery-swap-nav-left");
|
82
|
+
|
83
|
+
const navRight = document.createElement("button");
|
84
|
+
navRight.onclick = this.next;
|
85
|
+
navRight.innerHTML = "←";
|
86
|
+
navRight.classList.add("gallery-swap-nav-right");
|
87
|
+
|
88
|
+
if (this.options.navigation === "forwardOnly") {
|
89
|
+
nav.appendChild(navRight);
|
90
|
+
return nav;
|
91
|
+
}
|
92
|
+
if (this.options.navigation === "backOnly") {
|
93
|
+
nav.appendChild(navLeft);
|
94
|
+
return nav;
|
95
|
+
}
|
96
|
+
|
97
|
+
nav.appendChild(navLeft);
|
98
|
+
nav.appendChild(navRight);
|
99
|
+
|
100
|
+
return nav;
|
101
|
+
};
|
102
|
+
|
103
|
+
#appendElementsOnContainer() {
|
104
|
+
this.containerElem.innerHTML = "";
|
105
|
+
this.containerElem.appendChild(this.#createGSwapElement());
|
106
|
+
if (this.options.navigation === true) {
|
107
|
+
this.containerElem.appendChild(this.#createNavigation());
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
#shiftImagesToTheRight = () => {
|
112
|
+
const last = this.containerElem.children[0].lastElementChild!;
|
113
|
+
|
114
|
+
this.containerElem.children[0].insertAdjacentHTML(
|
115
|
+
"afterbegin",
|
116
|
+
last.outerHTML
|
117
|
+
);
|
118
|
+
|
119
|
+
last.remove();
|
120
|
+
};
|
121
|
+
#shiftImagesToTheLeft = () => {
|
122
|
+
const first = this.containerElem.children[0]
|
123
|
+
.firstElementChild! as HTMLImageElement;
|
124
|
+
this.containerElem.children[0].insertAdjacentHTML(
|
125
|
+
"beforeend",
|
126
|
+
first.outerHTML
|
127
|
+
);
|
128
|
+
first.style.opacity = "0";
|
129
|
+
|
130
|
+
first.remove();
|
131
|
+
|
132
|
+
// first.remove();
|
133
|
+
};
|
134
|
+
|
135
|
+
#findPrevActiveElem = () => {
|
136
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
137
|
+
const imgElem = image as HTMLImageElement;
|
138
|
+
if (imgElem.classList.contains("active")) {
|
139
|
+
imgElem.classList.remove("active");
|
140
|
+
}
|
141
|
+
});
|
142
|
+
const activeElem = this.containerElem.children[0]
|
143
|
+
.lastElementChild! as HTMLElement;
|
144
|
+
|
145
|
+
activeElem.style.opacity = "0";
|
146
|
+
setTimeout(() => {
|
147
|
+
activeElem.style.opacity = "1";
|
148
|
+
}, this.options.animationDuration);
|
149
|
+
|
150
|
+
activeElem.classList.add("active");
|
151
|
+
};
|
152
|
+
|
153
|
+
#findNextActiveElement = () => {
|
154
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
155
|
+
const imgElem = image as HTMLImageElement;
|
156
|
+
if (imgElem.classList.contains("active")) {
|
157
|
+
(imgElem as HTMLImageElement).classList.remove("active");
|
158
|
+
imgElem.style.opacity = "0";
|
159
|
+
setTimeout(() => {
|
160
|
+
imgElem.style.opacity = "1";
|
161
|
+
}, this.options.animationDuration);
|
162
|
+
}
|
163
|
+
});
|
164
|
+
const activeElem = this.containerElem.children[0].lastElementChild!;
|
165
|
+
|
166
|
+
activeElem.classList.add("active");
|
167
|
+
};
|
168
|
+
|
169
|
+
stackImages = () => {
|
170
|
+
let directionLeft: number;
|
171
|
+
let directionTop: number;
|
172
|
+
switch (this.options.direction) {
|
173
|
+
case "left":
|
174
|
+
directionLeft = 20;
|
175
|
+
directionTop = 20;
|
176
|
+
break;
|
177
|
+
case "right":
|
178
|
+
directionLeft = -20;
|
179
|
+
directionTop = 20;
|
180
|
+
break;
|
181
|
+
case "top":
|
182
|
+
directionLeft = 0;
|
183
|
+
directionTop = 20;
|
184
|
+
break;
|
185
|
+
case "bottom":
|
186
|
+
directionLeft = 0;
|
187
|
+
directionTop = -20;
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
let counter = 0;
|
191
|
+
this.containerElem.children[0].childNodes.forEach((image) => {
|
192
|
+
(image as HTMLImageElement).style.position = "absolute";
|
193
|
+
(image as HTMLImageElement).style.opacity = "1";
|
194
|
+
(image as HTMLImageElement).style.top =
|
195
|
+
(counter * directionTop).toString() + "px";
|
196
|
+
(image as HTMLImageElement).style.left =
|
197
|
+
(counter * directionLeft).toString() + "px";
|
198
|
+
counter++;
|
199
|
+
});
|
200
|
+
};
|
201
|
+
|
202
|
+
next = () => {
|
203
|
+
this.#shiftImagesToTheRight();
|
204
|
+
this.stackImages();
|
205
|
+
this.#findNextActiveElement();
|
206
|
+
};
|
207
|
+
|
208
|
+
prev = () => {
|
209
|
+
this.#shiftImagesToTheLeft();
|
210
|
+
this.stackImages();
|
211
|
+
this.#findPrevActiveElem();
|
212
|
+
};
|
213
|
+
}
|
package/tsconfig.json
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
4
|
+
|
5
|
+
/* Projects */
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
8
|
+
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
12
|
+
|
13
|
+
/* Language and Environment */
|
14
|
+
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
25
|
+
|
26
|
+
/* Modules */
|
27
|
+
"module": "commonjs" /* Specify what module code is generated. */,
|
28
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
29
|
+
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
30
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
31
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
32
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
33
|
+
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
34
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
35
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
36
|
+
// "resolveJsonModule": true, /* Enable importing .json files */
|
37
|
+
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
38
|
+
|
39
|
+
/* JavaScript Support */
|
40
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
|
41
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
42
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
|
43
|
+
|
44
|
+
/* Emit */
|
45
|
+
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
|
46
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
47
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
48
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
49
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
|
50
|
+
// "outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
51
|
+
// "removeComments": true, /* Disable emitting comments. */
|
52
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
53
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
54
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
|
55
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
56
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
57
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
58
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
59
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
60
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
61
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
62
|
+
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
63
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
64
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
65
|
+
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
66
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
67
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
68
|
+
|
69
|
+
/* Interop Constraints */
|
70
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
71
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
72
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
|
73
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
74
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
75
|
+
|
76
|
+
/* Type Checking */
|
77
|
+
"strict": true /* Enable all strict type-checking options. */,
|
78
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
|
79
|
+
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
|
80
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
81
|
+
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
|
82
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
83
|
+
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
|
84
|
+
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
|
85
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
86
|
+
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
|
87
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
|
88
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
89
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
90
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
91
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
92
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
93
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
|
94
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
95
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
96
|
+
|
97
|
+
/* Completeness */
|
98
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
99
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
100
|
+
},
|
101
|
+
"include": ["./src/**/*.ts"]
|
102
|
+
}
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export interface GallerySwap {
|
2
|
+
container: HTMLDivElement;
|
3
|
+
}
|
4
|
+
|
5
|
+
export type Options = {
|
6
|
+
animation?: string;
|
7
|
+
animationDuration?: number;
|
8
|
+
navigation?: boolean | "forwardOnly" | "backOnly";
|
9
|
+
repeat?: boolean;
|
10
|
+
direction?: "left" | "right" | "top" | "bottom";
|
11
|
+
imgDimensions?: {
|
12
|
+
height: number;
|
13
|
+
width: number;
|
14
|
+
};
|
15
|
+
};
|
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
|
-
};
|
package/dist/src/index.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { GSwap } from "./main";
|
package/dist/src/index.js
DELETED
@@ -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
|
-
};
|