@simhub2/justflipit 3.0.0

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.
@@ -0,0 +1,329 @@
1
+ /*!
2
+ * Vanilla JS justFlipIt v3.0.0
3
+ * https://github.com/SimHub/justFlipIt
4
+ *
5
+ * Copyright simon Lackmann
6
+ * Released under the MIT license
7
+ *
8
+ * Date: 2023
9
+ */
10
+
11
+ (function (root, factory) {
12
+ if (typeof define === "function" && define.amd) {
13
+ define([], factory);
14
+ } else if (typeof module === "object" && module.exports) {
15
+ module.exports = factory();
16
+ } else {
17
+ root.justFlipIt = factory();
18
+ }
19
+ })(typeof self !== "undefined" ? self : this, function () {
20
+ "use strict";
21
+
22
+ function addStyles() {
23
+ if (document.querySelector('[data-justflipitstyle="justFlipIt_One"]')) {
24
+ return;
25
+ }
26
+ const styleX = document.createElement("style");
27
+ styleX.setAttribute("data-justflipitstyle", "justFlipIt_One");
28
+ styleX.textContent =
29
+ "._justFlipIt_panel {perspective:1000px;-webkit-perspective:1000px;-moz-perspective:1000px;}" +
30
+ "._justFlipIt_panel .front{height:inherit;width:inherit;position:absolute;top:0;z-index:900;-webkit-transform:rotateX(0) rotateX(0);-moz-transform:rotateX(0) rotateX(0);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}" +
31
+ "._justFlipIt_panel .back{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;-webkit-transform:rotateX(-180deg);-moz-transform:rotateX(-180deg);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}" +
32
+ "._justFlipIt_panel._flip_ .front{z-index:900;-webkit-transform:rotateX(180deg);-moz-transform:rotateX(180deg)}" +
33
+ "._justFlipIt_panel._flip_ .back{z-index:1000;-webkit-transform:rotateX(0) rotateX(0);-moz-transform:rotateX(0) rotateX(0)}";
34
+ const styleY = document.createElement("style");
35
+ styleY.setAttribute("data-justflipitstyle", "justFlipIt_Two");
36
+ styleY.textContent =
37
+ "._justFlipIt_panel .backY{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;-webkit-transform:rotateY(-180deg);-moz-transform:rotateY(-180deg);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}" +
38
+ "._justFlipIt_panel._flipY_ .front{z-index:900;-webkit-transform:rotateY(180deg);-moz-transform:rotateY(180deg)}" +
39
+ "._justFlipIt_panel._flipY_ .backY{z-index:1000;-webkit-transform:rotateX(0) rotateY(0);-moz-transform:rotateX(0) rotateY(0)}";
40
+
41
+ // PATCH: Füge Transparency-Style hinzu
42
+ const styleTransparent = document.createElement("style");
43
+ styleTransparent.setAttribute(
44
+ "data-justflipitstyle",
45
+ "justFlipIt_Transparent",
46
+ );
47
+ styleTransparent.textContent =
48
+ "._justFlipIt_panel {background: transparent !important; box-shadow: none !important;}" +
49
+ "._justFlipIt_panel > * {box-sizing: border-box;}";
50
+
51
+ document.head.appendChild(styleX);
52
+ document.head.appendChild(styleY);
53
+ document.head.appendChild(styleTransparent);
54
+ }
55
+
56
+ function getStyle(element, property) {
57
+ return window.getComputedStyle(element, null).getPropertyValue(property);
58
+ }
59
+ function addClass(element, className) {
60
+ if (element.classList) {
61
+ element.classList.add(className);
62
+ } else {
63
+ element.className += " " + className;
64
+ }
65
+ }
66
+ function removeClass(element, className) {
67
+ if (element.classList) {
68
+ element.classList.remove(className);
69
+ } else {
70
+ element.className = element.className.replace(
71
+ new RegExp(
72
+ "(^|\\b)" + className.split(" ").join("|") + "(\\b|$)",
73
+ "gi",
74
+ ),
75
+ " ",
76
+ );
77
+ }
78
+ }
79
+ function toggleClass(element, className) {
80
+ if (element.classList) {
81
+ element.classList.toggle(className);
82
+ } else {
83
+ var classes = element.className.split(" ");
84
+ var existingIndex = classes.indexOf(className);
85
+ if (existingIndex >= 0) {
86
+ classes.splice(existingIndex, 1);
87
+ } else {
88
+ classes.push(className);
89
+ }
90
+ element.className = classes.join(" ");
91
+ }
92
+ }
93
+ function hasClass(element, className) {
94
+ if (element.classList) {
95
+ return element.classList.contains(className);
96
+ } else {
97
+ return new RegExp("(^| )" + className + "( |$)", "gi").test(
98
+ element.className,
99
+ );
100
+ }
101
+ }
102
+
103
+ // PATCH: Verbesserte Style-Kopierfunktion
104
+ function copyStyles(src, dest) {
105
+ const computed = window.getComputedStyle(src);
106
+ // Kopiere alle visuellen Eigenschaften
107
+ const properties = [
108
+ "background",
109
+ "backgroundColor",
110
+ "backgroundImage",
111
+ "backgroundPosition",
112
+ "backgroundRepeat",
113
+ "backgroundSize",
114
+ "borderRadius",
115
+ "borderTopLeftRadius",
116
+ "borderTopRightRadius",
117
+ "borderBottomLeftRadius",
118
+ "borderBottomRightRadius",
119
+ "border",
120
+ "borderTop",
121
+ "borderRight",
122
+ "borderBottom",
123
+ "borderLeft",
124
+ "boxShadow",
125
+ "color",
126
+ "opacity",
127
+ ];
128
+ properties.forEach((prop) => {
129
+ if (
130
+ computed[prop] &&
131
+ computed[prop] !== "none" &&
132
+ computed[prop] !== "initial" &&
133
+ computed[prop] !== ""
134
+ ) {
135
+ dest.style[prop] = computed[prop];
136
+ }
137
+ });
138
+ }
139
+
140
+ // NEU: Funktion zur Anwendung der benutzerdefinierten Animationseinstellungen
141
+ function applyAnimationSettings(element, duration, easing) {
142
+ const transitionValue = `all ${duration / 1000}s ${easing}`;
143
+ element.style.transition = transitionValue;
144
+ element.style.WebkitTransition = transitionValue;
145
+ element.style.MozTransition = transitionValue;
146
+ element.style.msTransition = transitionValue;
147
+ element.style.OTransition = transitionValue;
148
+ }
149
+
150
+ const instanceMap = new WeakMap();
151
+
152
+ class JustFlipIt {
153
+ constructor(element, options = {}) {
154
+ addStyles();
155
+ this.element = element;
156
+ this.settings = Object.assign(
157
+ {},
158
+ {
159
+ Template: "",
160
+ Click: false,
161
+ FlipX: false,
162
+ Style: [],
163
+ // NEU: Standard-Animationsoptionen
164
+ Duration: 400,
165
+ Easing: "ease-in-out",
166
+ },
167
+ options,
168
+ );
169
+ this.elementWidth = getStyle(element, "width");
170
+ this.elementHeight = getStyle(element, "height");
171
+ this.elementBackgroundColor = getStyle(element, "background-color");
172
+ this.originalClassName = element.className;
173
+ this.originalTagName = element.tagName.toLowerCase();
174
+ this.originalId = element.id || "";
175
+ if (this.settings.FlipX === true) {
176
+ this.flipClass = "_flip_";
177
+ this.backClass = "back";
178
+ } else {
179
+ this.flipClass = "_flipY_";
180
+ this.backClass = "backY";
181
+ }
182
+ this._init();
183
+ instanceMap.set(element, this);
184
+ }
185
+
186
+ _init() {
187
+ const originalElement = this.element;
188
+ const originalClassName = this.originalClassName;
189
+ const hoverPanel = document.createElement(this.originalTagName);
190
+ addClass(hoverPanel, "hover");
191
+ addClass(hoverPanel, "_justFlipIt_panel");
192
+ const frontWrapper = document.createElement("div");
193
+ addClass(frontWrapper, "front");
194
+ const clone = originalElement.cloneNode(true);
195
+ clone.className = "";
196
+ const backWrapper = document.createElement("div");
197
+ addClass(backWrapper, this.backClass);
198
+ if (originalClassName) {
199
+ originalClassName.split(" ").forEach((cls) => {
200
+ if (cls) addClass(backWrapper, cls);
201
+ });
202
+ }
203
+
204
+ // PATCH: Styles übernehmen und Original komplett transparent machen
205
+ copyStyles(originalElement, frontWrapper);
206
+ copyStyles(originalElement, backWrapper);
207
+
208
+ // Mache das Original komplett transparent und ohne Border/Shadow/usw.
209
+ originalElement.style.all = "inherit"; // Reset alles zur Sicherheit
210
+ originalElement.style.background = "transparent";
211
+ originalElement.style.backgroundColor = "transparent";
212
+ originalElement.style.backgroundImage = "none";
213
+ originalElement.style.border = "none";
214
+ originalElement.style.borderRadius = "0";
215
+ originalElement.style.boxShadow = "none";
216
+ originalElement.style.outline = "none";
217
+
218
+ // NEU: Wende benutzerdefinierte Animationseinstellungen an
219
+ applyAnimationSettings(
220
+ frontWrapper,
221
+ this.settings.Duration,
222
+ this.settings.Easing,
223
+ );
224
+ applyAnimationSettings(
225
+ backWrapper,
226
+ this.settings.Duration,
227
+ this.settings.Easing,
228
+ );
229
+
230
+ if (this.settings.Template) {
231
+ backWrapper.innerHTML = this.settings.Template;
232
+ } else {
233
+ backWrapper.appendChild(clone);
234
+ }
235
+ originalElement.parentNode.insertBefore(hoverPanel, originalElement);
236
+ frontWrapper.appendChild(originalElement);
237
+ hoverPanel.appendChild(frontWrapper);
238
+ hoverPanel.appendChild(backWrapper);
239
+ if (originalClassName) {
240
+ originalClassName.split(" ").forEach((cls) => {
241
+ if (cls) addClass(hoverPanel, cls);
242
+ });
243
+ }
244
+ hoverPanel.style.width = this.elementWidth;
245
+ hoverPanel.style.height = this.elementHeight;
246
+ if (this.settings.Style && this.settings.Style.length) {
247
+ this.settings.Style.forEach((styleObj) => {
248
+ if (styleObj.el) {
249
+ if (styleObj.el.toLowerCase() === "self") {
250
+ Object.assign(hoverPanel.style, styleObj.style);
251
+ } else {
252
+ const targetElements = hoverPanel.querySelectorAll(styleObj.el);
253
+ targetElements.forEach((el) => {
254
+ Object.assign(el.style, styleObj.style);
255
+ });
256
+ }
257
+ }
258
+ });
259
+ }
260
+ this._setupEvents(hoverPanel);
261
+ this.hoverPanel = hoverPanel;
262
+ this.frontWrapper = frontWrapper;
263
+ this.backWrapper = backWrapper;
264
+ }
265
+
266
+ _setupEvents(hoverPanel) {
267
+ if (this.settings.Click === true) {
268
+ hoverPanel.addEventListener("click", (e) => {
269
+ e.preventDefault();
270
+ toggleClass(hoverPanel, this.flipClass);
271
+ });
272
+ } else if (typeof this.settings.Click === "string") {
273
+ const clickElements = hoverPanel.querySelectorAll(this.settings.Click);
274
+ clickElements.forEach((el) => {
275
+ el.addEventListener("click", () => {
276
+ toggleClass(hoverPanel, this.flipClass);
277
+ });
278
+ });
279
+ } else {
280
+ hoverPanel.addEventListener("mouseenter", () => {
281
+ addClass(hoverPanel, this.flipClass);
282
+ });
283
+ hoverPanel.addEventListener("mouseleave", () => {
284
+ removeClass(hoverPanel, this.flipClass);
285
+ });
286
+ }
287
+ }
288
+
289
+ destroy() {
290
+ const hoverPanel = this.hoverPanel;
291
+ const originalElement = hoverPanel.querySelector(".front > *");
292
+ originalElement.className = this.originalClassName;
293
+ hoverPanel.parentNode.insertBefore(originalElement, hoverPanel);
294
+ hoverPanel.parentNode.removeChild(hoverPanel);
295
+ instanceMap.delete(this.element);
296
+ }
297
+ }
298
+
299
+ function justFlipIt(selector, options = {}) {
300
+ if (typeof selector === "string") {
301
+ const elements = document.querySelectorAll(selector);
302
+ return Array.from(elements).map((el) => new JustFlipIt(el, options));
303
+ } else if (selector instanceof Element) {
304
+ return new JustFlipIt(selector, options);
305
+ } else if (selector.length) {
306
+ return Array.from(selector).map((el) => new JustFlipIt(el, options));
307
+ }
308
+ }
309
+
310
+ justFlipIt.destroy = function (selector) {
311
+ if (typeof selector === "string") {
312
+ const elements = document.querySelectorAll(selector);
313
+ Array.from(elements).forEach((el) => {
314
+ const instance = instanceMap.get(el);
315
+ if (instance) instance.destroy();
316
+ });
317
+ } else if (selector instanceof Element) {
318
+ const instance = instanceMap.get(selector);
319
+ if (instance) instance.destroy();
320
+ } else if (selector.length) {
321
+ Array.from(selector).forEach((el) => {
322
+ const instance = instanceMap.get(el);
323
+ if (instance) instance.destroy();
324
+ });
325
+ }
326
+ };
327
+
328
+ return justFlipIt;
329
+ });
@@ -0,0 +1 @@
1
+ ((t,e)=>{"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():t.justFlipIt=e()})("undefined"!=typeof self?self:this,function(){function a(t,e){return window.getComputedStyle(t,null).getPropertyValue(e)}function o(t,e){t.classList?t.classList.add(e):t.className+=" "+e}function e(t,e){var i,s;t.classList?t.classList.toggle(e):(0<=(s=(i=t.className.split(" ")).indexOf(e))?i.splice(s,1):i.push(e),t.className=i.join(" "))}function r(t,e){let i=window.getComputedStyle(t);["background","backgroundColor","backgroundImage","backgroundPosition","backgroundRepeat","backgroundSize","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","border","borderTop","borderRight","borderBottom","borderLeft","boxShadow","color","opacity"].forEach(t=>{i[t]&&"none"!==i[t]&&"initial"!==i[t]&&""!==i[t]&&(e.style[t]=i[t])})}function l(t,e,i){e=`all ${e/1e3}s `+i;t.style.transition=e,t.style.WebkitTransition=e,t.style.MozTransition=e,t.style.msTransition=e,t.style.OTransition=e}let d=new WeakMap;class s{constructor(t,e={}){var i,s,n;document.querySelector('[data-justflipitstyle="justFlipIt_One"]')||((i=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_One"),i.textContent="._justFlipIt_panel {perspective:1000px;-webkit-perspective:1000px;-moz-perspective:1000px;}._justFlipIt_panel .front{height:inherit;width:inherit;position:absolute;top:0;z-index:900;-webkit-transform:rotateX(0) rotateX(0);-moz-transform:rotateX(0) rotateX(0);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel .back{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;-webkit-transform:rotateX(-180deg);-moz-transform:rotateX(-180deg);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel._flip_ .front{z-index:900;-webkit-transform:rotateX(180deg);-moz-transform:rotateX(180deg)}._justFlipIt_panel._flip_ .back{z-index:1000;-webkit-transform:rotateX(0) rotateX(0);-moz-transform:rotateX(0) rotateX(0)}",(s=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_Two"),s.textContent="._justFlipIt_panel .backY{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;-webkit-transform:rotateY(-180deg);-moz-transform:rotateY(-180deg);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel._flipY_ .front{z-index:900;-webkit-transform:rotateY(180deg);-moz-transform:rotateY(180deg)}._justFlipIt_panel._flipY_ .backY{z-index:1000;-webkit-transform:rotateX(0) rotateY(0);-moz-transform:rotateX(0) rotateY(0)}",(n=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_Transparent"),n.textContent="._justFlipIt_panel {background: transparent !important; box-shadow: none !important;}._justFlipIt_panel > * {box-sizing: border-box;}",document.head.appendChild(i),document.head.appendChild(s),document.head.appendChild(n)),this.element=t,this.settings=Object.assign({},{Template:"",Click:!1,FlipX:!1,Style:[],Duration:400,Easing:"ease-in-out"},e),this.elementWidth=a(t,"width"),this.elementHeight=a(t,"height"),this.elementBackgroundColor=a(t,"background-color"),this.originalClassName=t.className,this.originalTagName=t.tagName.toLowerCase(),this.originalId=t.id||"",!0===this.settings.FlipX?(this.flipClass="_flip_",this.backClass="back"):(this.flipClass="_flipY_",this.backClass="backY"),this._init(),d.set(t,this)}_init(){var t=this.element,e=this.originalClassName;let i=document.createElement(this.originalTagName);o(i,"hover"),o(i,"_justFlipIt_panel");var s=document.createElement("div"),n=(o(s,"front"),t.cloneNode(!0));n.className="";let a=document.createElement("div");o(a,this.backClass),e&&e.split(" ").forEach(t=>{t&&o(a,t)}),r(t,s),r(t,a),t.style.all="inherit",t.style.background="transparent",t.style.backgroundColor="transparent",t.style.backgroundImage="none",t.style.border="none",t.style.borderRadius="0",t.style.boxShadow="none",t.style.outline="none",l(s,this.settings.Duration,this.settings.Easing),l(a,this.settings.Duration,this.settings.Easing),this.settings.Template?a.innerHTML=this.settings.Template:a.appendChild(n),t.parentNode.insertBefore(i,t),s.appendChild(t),i.appendChild(s),i.appendChild(a),e&&e.split(" ").forEach(t=>{t&&o(i,t)}),i.style.width=this.elementWidth,i.style.height=this.elementHeight,this.settings.Style&&this.settings.Style.length&&this.settings.Style.forEach(e=>{e.el&&("self"===e.el.toLowerCase()?Object.assign(i.style,e.style):i.querySelectorAll(e.el).forEach(t=>{Object.assign(t.style,e.style)}))}),this._setupEvents(i),this.hoverPanel=i,this.frontWrapper=s,this.backWrapper=a}_setupEvents(i){!0===this.settings.Click?i.addEventListener("click",t=>{t.preventDefault(),e(i,this.flipClass)}):"string"==typeof this.settings.Click?i.querySelectorAll(this.settings.Click).forEach(t=>{t.addEventListener("click",()=>{e(i,this.flipClass)})}):(i.addEventListener("mouseenter",()=>{o(i,this.flipClass)}),i.addEventListener("mouseleave",()=>{var t,e;t=i,e=this.flipClass,t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," ")}))}destroy(){var t=this.hoverPanel,e=t.querySelector(".front > *");e.className=this.originalClassName,t.parentNode.insertBefore(e,t),t.parentNode.removeChild(t),d.delete(this.element)}}function t(t,e={}){var i;return"string"==typeof t?(i=document.querySelectorAll(t),Array.from(i).map(t=>new s(t,e))):t instanceof Element?new s(t,e):t.length?Array.from(t).map(t=>new s(t,e)):void 0}return t.destroy=function(t){var e;"string"==typeof t?(e=document.querySelectorAll(t),Array.from(e).forEach(t=>{t=d.get(t);t&&t.destroy()})):t instanceof Element?(e=d.get(t))&&e.destroy():t.length&&Array.from(t).forEach(t=>{t=d.get(t);t&&t.destroy()})},t});
@@ -0,0 +1,43 @@
1
+ declare namespace justFlipIt {
2
+ interface StyleOption {
3
+ el: string;
4
+ style: Partial<CSSStyleDeclaration>;
5
+ }
6
+
7
+ interface Options {
8
+ /**
9
+ * Template for the back side of the flipped element
10
+ */
11
+ Template?: string;
12
+
13
+ /**
14
+ * Click behavior. True for click toggle, selector string for delegated click, false for hover
15
+ */
16
+ Click?: boolean | string;
17
+
18
+ /**
19
+ * Flip direction. True for X-axis, false for Y-axis
20
+ */
21
+ FlipX?: boolean;
22
+
23
+ /**
24
+ * Custom styles to apply to elements
25
+ */
26
+ Style?: StyleOption[];
27
+ }
28
+
29
+ /**
30
+ * Destroy flip instances matching the selector
31
+ */
32
+ function destroy(selector: string | Element | NodeListOf<Element> | HTMLCollection): void;
33
+ }
34
+
35
+ /**
36
+ * Initialize flip effect on matching elements
37
+ */
38
+ declare function justFlipIt(
39
+ selector: string | Element | NodeListOf<Element> | HTMLCollection,
40
+ options?: justFlipIt.Options
41
+ ): any;
42
+
43
+ export = justFlipIt;