@simhub2/justflipit 3.2.2 → 4.0.1

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +21 -0
  3. package/README.md +258 -91
  4. package/dist/agent.cjs +63 -0
  5. package/dist/agent.cjs.map +7 -0
  6. package/dist/agent.d.cts +4 -0
  7. package/dist/agent.d.mts +4 -0
  8. package/dist/agent.d.ts +4 -0
  9. package/dist/agent.mjs +43 -0
  10. package/dist/agent.mjs.map +7 -0
  11. package/dist/justFlipIt-combined.js +295 -0
  12. package/dist/justFlipIt-combined.min.js +23 -0
  13. package/dist/justFlipIt-modern.js +271 -476
  14. package/dist/justFlipIt-modern.min.js +23 -1
  15. package/dist/justFlipIt-vanilla.js +272 -343
  16. package/dist/justFlipIt-vanilla.min.js +23 -1
  17. package/dist/justFlipIt.cjs +293 -0
  18. package/dist/justFlipIt.cjs.map +7 -0
  19. package/dist/justFlipIt.d.cts +4 -0
  20. package/dist/justFlipIt.d.mts +38 -0
  21. package/dist/justFlipIt.d.ts +38 -0
  22. package/dist/justFlipIt.js +269 -391
  23. package/dist/justFlipIt.js.map +7 -0
  24. package/dist/justFlipIt.min.js +23 -1
  25. package/dist/justFlipIt.min.js.map +7 -0
  26. package/dist/justFlipIt.mjs +272 -0
  27. package/dist/justFlipIt.mjs.map +7 -0
  28. package/dist/react.cjs +55 -0
  29. package/dist/react.cjs.map +7 -0
  30. package/dist/react.d.cts +3 -0
  31. package/dist/react.d.mts +3 -0
  32. package/dist/react.d.ts +3 -0
  33. package/dist/react.mjs +25 -0
  34. package/dist/react.mjs.map +7 -0
  35. package/dist/svelte.cjs +45 -0
  36. package/dist/svelte.cjs.map +7 -0
  37. package/dist/svelte.d.cts +3 -0
  38. package/dist/svelte.d.mts +3 -0
  39. package/dist/svelte.d.ts +3 -0
  40. package/dist/svelte.mjs +15 -0
  41. package/dist/svelte.mjs.map +7 -0
  42. package/dist/types/justFlipIt.d.ts +36 -59
  43. package/dist/vue.cjs +49 -0
  44. package/dist/vue.cjs.map +7 -0
  45. package/dist/vue.d.cts +3 -0
  46. package/dist/vue.d.mts +3 -0
  47. package/dist/vue.d.ts +3 -0
  48. package/dist/vue.mjs +19 -0
  49. package/dist/vue.mjs.map +7 -0
  50. package/package.json +117 -50
  51. package/src/justFlipIt-combined.js +0 -417
  52. package/src/justFlipIt-combined.min.js +0 -1
  53. package/src/justFlipIt-modern.js +0 -500
  54. package/src/justFlipIt-modern.min.js +0 -1
  55. package/src/justFlipIt-vanilla.js +0 -366
  56. package/src/justFlipIt-vanilla.min.js +0 -1
  57. package/src/justFlipIt.d.ts +0 -61
@@ -1,366 +0,0 @@
1
- /*!
2
- * justFlipIt v3.1.0
3
- * https://github.com/SimHub/justFlipIt
4
- *
5
- * Copyright SimHub
6
- * Released under the MIT license
7
- *
8
- * Date: 2025
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
- Duration: 400,
164
- Easing: "ease-in-out",
165
- preserveClasses: true, // NEU
166
- preserveStyles: true, // NEU
167
- },
168
- options,
169
- );
170
- this.elementWidth = getStyle(element, "width");
171
- this.elementHeight = getStyle(element, "height");
172
- this.elementBackgroundColor = getStyle(element, "background-color");
173
- this.originalClassName = element.className;
174
- this.originalTagName = element.tagName.toLowerCase();
175
- this.originalId = element.id || "";
176
- if (this.settings.FlipX === true) {
177
- this.flipClass = "_flip_";
178
- this.backClass = "back";
179
- } else {
180
- this.flipClass = "_flipY_";
181
- this.backClass = "backY";
182
- }
183
- this._init();
184
- if (this.settings.Tilt) {
185
- this._setupTilt();
186
- }
187
- instanceMap.set(element, this);
188
- }
189
-
190
- _init() {
191
- const originalElement = this.element;
192
- const originalClassName = this.originalClassName;
193
-
194
- // Panel-Struktur erzeugen
195
- const hoverPanel = document.createElement(this.originalTagName);
196
- addClass(hoverPanel, "hover");
197
- addClass(hoverPanel, "_justFlipIt_panel");
198
- const frontWrapper = document.createElement("div");
199
- addClass(frontWrapper, "front");
200
- const backWrapper = document.createElement("div");
201
- addClass(backWrapper, this.backClass);
202
-
203
- // NEU: Klassen übernehmen (Panel, .front, .backY)
204
- if (this.settings.preserveClasses && originalElement.classList.length) {
205
- originalElement.classList.forEach((cls) => {
206
- if (!hoverPanel.classList.contains(cls)) {
207
- hoverPanel.classList.add(cls);
208
- }
209
- if (frontWrapper && !frontWrapper.classList.contains(cls)) {
210
- frontWrapper.classList.add(cls);
211
- }
212
- if (backWrapper && !backWrapper.classList.contains(cls)) {
213
- backWrapper.classList.add(cls);
214
- }
215
- });
216
- }
217
-
218
- // NEU: Inline-Styles übernehmen (nur auf Panel)
219
- if (
220
- this.settings.preserveStyles && originalElement.getAttribute("style")
221
- ) {
222
- hoverPanel.setAttribute(
223
- "style",
224
- (hoverPanel.getAttribute("style") || "") +
225
- ";" + originalElement.getAttribute("style"),
226
- );
227
- }
228
-
229
- // Nur den INHALT übernehmen!
230
- frontWrapper.innerHTML = originalElement.innerHTML;
231
-
232
- if (this.settings.Template) {
233
- backWrapper.innerHTML = this.settings.Template;
234
- } else {
235
- backWrapper.innerHTML = originalElement.innerHTML;
236
- }
237
-
238
- // Panel einfügen und Original entfernen
239
- originalElement.parentNode.insertBefore(hoverPanel, originalElement);
240
- hoverPanel.appendChild(frontWrapper);
241
- hoverPanel.appendChild(backWrapper);
242
- originalElement.parentNode.removeChild(originalElement);
243
-
244
- // Panel-Größe und Styles übernehmen
245
- hoverPanel.style.width = this.elementWidth;
246
- hoverPanel.style.height = this.elementHeight;
247
-
248
- // Custom Styles aus Option anwenden
249
- if (this.settings.Style && this.settings.Style.length) {
250
- this.settings.Style.forEach((styleObj) => {
251
- if (styleObj.el) {
252
- if (styleObj.el.toLowerCase() === "self") {
253
- Object.assign(hoverPanel.style, styleObj.style);
254
- } else {
255
- const targetElements = hoverPanel.querySelectorAll(styleObj.el);
256
- targetElements.forEach((el) => {
257
- Object.assign(el.style, styleObj.style);
258
- });
259
- }
260
- }
261
- });
262
- }
263
-
264
- // Events setzen
265
- this._setupEvents(hoverPanel);
266
-
267
- // Referenzen speichern
268
- this.hoverPanel = hoverPanel;
269
- this.frontWrapper = frontWrapper;
270
- this.backWrapper = backWrapper;
271
- }
272
-
273
- _setupTilt() {
274
- const handleMove = (e) => {
275
- const rect = this.hoverPanel.getBoundingClientRect();
276
- const x = (e.touches ? e.touches[0].clientX : e.clientX) - rect.left;
277
- const y = (e.touches ? e.touches[0].clientY : e.clientY) - rect.top;
278
- const centerX = rect.width / 2;
279
- const centerY = rect.height / 2;
280
- const rotateX = ((y - centerY) / centerY) * 10;
281
- const rotateY = (-(x - centerX) / centerX) * 10;
282
- this.hoverPanel.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale3d(1.05, 1.05, 1.05)`;
283
- };
284
-
285
- const handleEnter = () => {
286
- this.hoverPanel.style.transition = "all 0.2s ease-out";
287
- };
288
-
289
- const handleLeave = () => {
290
- this.hoverPanel.style.transform = `perspective(1000px) rotateX(0) rotateY(0) scale3d(1, 1, 1)`;
291
- this.hoverPanel.style.transition = "all 0.5s ease-in-out";
292
- };
293
-
294
- this.hoverPanel.addEventListener("mousemove", handleMove);
295
- this.hoverPanel.addEventListener("touchmove", handleMove);
296
- this.hoverPanel.addEventListener("mouseenter", handleEnter);
297
- this.hoverPanel.addEventListener("touchstart", handleEnter);
298
- this.hoverPanel.addEventListener("mouseleave", handleLeave);
299
- this.hoverPanel.addEventListener("touchend", handleLeave);
300
- }
301
-
302
- _setupEvents(hoverPanel) {
303
- if (this.settings.Tilt === 'only') return;
304
- if (this.settings.Click === true) {
305
- hoverPanel.addEventListener("click", (e) => {
306
- e.preventDefault();
307
- toggleClass(hoverPanel, this.flipClass);
308
- });
309
- } else if (typeof this.settings.Click === "string") {
310
- const clickElements = hoverPanel.querySelectorAll(this.settings.Click);
311
- clickElements.forEach((el) => {
312
- el.addEventListener("click", () => {
313
- toggleClass(hoverPanel, this.flipClass);
314
- });
315
- });
316
- } else {
317
- hoverPanel.addEventListener("mouseenter", () => {
318
- addClass(hoverPanel, this.flipClass);
319
- });
320
- hoverPanel.addEventListener("mouseleave", () => {
321
- removeClass(hoverPanel, this.flipClass);
322
- });
323
- }
324
- }
325
-
326
- destroy() {
327
- const hoverPanel = this.hoverPanel;
328
- const originalElement = hoverPanel.querySelector(".front > *");
329
- originalElement.className = this.originalClassName;
330
- hoverPanel.parentNode.insertBefore(originalElement, hoverPanel);
331
- hoverPanel.parentNode.removeChild(hoverPanel);
332
- instanceMap.delete(this.element);
333
- }
334
- }
335
-
336
- function justFlipIt(selector, options = {}) {
337
- if (typeof selector === "string") {
338
- const elements = document.querySelectorAll(selector);
339
- return Array.from(elements).map((el) => new JustFlipIt(el, options));
340
- } else if (selector instanceof Element) {
341
- return new JustFlipIt(selector, options);
342
- } else if (selector.length) {
343
- return Array.from(selector).map((el) => new JustFlipIt(el, options));
344
- }
345
- }
346
-
347
- justFlipIt.destroy = function (selector) {
348
- if (typeof selector === "string") {
349
- const elements = document.querySelectorAll(selector);
350
- Array.from(elements).forEach((el) => {
351
- const instance = instanceMap.get(el);
352
- if (instance) instance.destroy();
353
- });
354
- } else if (selector instanceof Element) {
355
- const instance = instanceMap.get(selector);
356
- if (instance) instance.destroy();
357
- } else if (selector.length) {
358
- Array.from(selector).forEach((el) => {
359
- const instance = instanceMap.get(el);
360
- if (instance) instance.destroy();
361
- });
362
- }
363
- };
364
-
365
- return justFlipIt;
366
- });
@@ -1 +0,0 @@
1
- (function(root,factory){if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof module==="object"&&module.exports){module.exports=factory()}else{root.justFlipIt=factory()}})(typeof self!=="undefined"?self:this,function(){"use strict";function addStyles(){if(document.querySelector('[data-justflipitstyle="justFlipIt_One"]')){return}const styleX=document.createElement("style");styleX.setAttribute("data-justflipitstyle","justFlipIt_One");styleX.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)}";const styleY=document.createElement("style");styleY.setAttribute("data-justflipitstyle","justFlipIt_Two");styleY.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)}";const styleTransparent=document.createElement("style");styleTransparent.setAttribute("data-justflipitstyle","justFlipIt_Transparent");styleTransparent.textContent="._justFlipIt_panel {background: transparent !important; box-shadow: none !important;}"+"._justFlipIt_panel > * {box-sizing: border-box;}";document.head.appendChild(styleX);document.head.appendChild(styleY);document.head.appendChild(styleTransparent)}function getStyle(element,property){return window.getComputedStyle(element,null).getPropertyValue(property)}function addClass(element,className){if(element.classList){element.classList.add(className)}else{element.className+=" "+className}}function removeClass(element,className){if(element.classList){element.classList.remove(className)}else{element.className=element.className.replace(new RegExp("(^|\\b)"+className.split(" ").join("|")+"(\\b|$)","gi")," ")}}function toggleClass(element,className){if(element.classList){element.classList.toggle(className)}else{var classes=element.className.split(" ");var existingIndex=classes.indexOf(className);if(existingIndex>=0){classes.splice(existingIndex,1)}else{classes.push(className)}element.className=classes.join(" ")}}function hasClass(element,className){if(element.classList){return element.classList.contains(className)}else{return new RegExp("(^| )"+className+"( |$)","gi").test(element.className)}}function copyStyles(src,dest){const computed=window.getComputedStyle(src);const properties=["background","backgroundColor","backgroundImage","backgroundPosition","backgroundRepeat","backgroundSize","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","border","borderTop","borderRight","borderBottom","borderLeft","boxShadow","color","opacity"];properties.forEach(prop=>{if(computed[prop]&&computed[prop]!=="none"&&computed[prop]!=="initial"&&computed[prop]!==""){dest.style[prop]=computed[prop]}})}function applyAnimationSettings(element,duration,easing){const transitionValue=`all ${duration/1e3}s ${easing}`;element.style.transition=transitionValue;element.style.WebkitTransition=transitionValue;element.style.MozTransition=transitionValue;element.style.msTransition=transitionValue;element.style.OTransition=transitionValue}const instanceMap=new WeakMap;class JustFlipIt{constructor(element,options={}){addStyles();this.element=element;this.settings=Object.assign({},{Template:"",Click:false,FlipX:false,Style:[],Duration:400,Easing:"ease-in-out",preserveClasses:true,preserveStyles:true},options);this.elementWidth=getStyle(element,"width");this.elementHeight=getStyle(element,"height");this.elementBackgroundColor=getStyle(element,"background-color");this.originalClassName=element.className;this.originalTagName=element.tagName.toLowerCase();this.originalId=element.id||"";if(this.settings.FlipX===true){this.flipClass="_flip_";this.backClass="back"}else{this.flipClass="_flipY_";this.backClass="backY"}this._init();if(this.settings.Tilt){this._setupTilt()}instanceMap.set(element,this)}_init(){const originalElement=this.element;const originalClassName=this.originalClassName;const hoverPanel=document.createElement(this.originalTagName);addClass(hoverPanel,"hover");addClass(hoverPanel,"_justFlipIt_panel");const frontWrapper=document.createElement("div");addClass(frontWrapper,"front");const backWrapper=document.createElement("div");addClass(backWrapper,this.backClass);if(this.settings.preserveClasses&&originalElement.classList.length){originalElement.classList.forEach(cls=>{if(!hoverPanel.classList.contains(cls)){hoverPanel.classList.add(cls)}if(frontWrapper&&!frontWrapper.classList.contains(cls)){frontWrapper.classList.add(cls)}if(backWrapper&&!backWrapper.classList.contains(cls)){backWrapper.classList.add(cls)}})}if(this.settings.preserveStyles&&originalElement.getAttribute("style")){hoverPanel.setAttribute("style",(hoverPanel.getAttribute("style")||"")+";"+originalElement.getAttribute("style"))}frontWrapper.innerHTML=originalElement.innerHTML;if(this.settings.Template){backWrapper.innerHTML=this.settings.Template}else{backWrapper.innerHTML=originalElement.innerHTML}originalElement.parentNode.insertBefore(hoverPanel,originalElement);hoverPanel.appendChild(frontWrapper);hoverPanel.appendChild(backWrapper);originalElement.parentNode.removeChild(originalElement);hoverPanel.style.width=this.elementWidth;hoverPanel.style.height=this.elementHeight;if(this.settings.Style&&this.settings.Style.length){this.settings.Style.forEach(styleObj=>{if(styleObj.el){if(styleObj.el.toLowerCase()==="self"){Object.assign(hoverPanel.style,styleObj.style)}else{const targetElements=hoverPanel.querySelectorAll(styleObj.el);targetElements.forEach(el=>{Object.assign(el.style,styleObj.style)})}}})}this._setupEvents(hoverPanel);this.hoverPanel=hoverPanel;this.frontWrapper=frontWrapper;this.backWrapper=backWrapper}_setupTilt(){const handleMove=e=>{const rect=this.hoverPanel.getBoundingClientRect();const x=(e.touches?e.touches[0].clientX:e.clientX)-rect.left;const y=(e.touches?e.touches[0].clientY:e.clientY)-rect.top;const centerX=rect.width/2;const centerY=rect.height/2;const rotateX=(y-centerY)/centerY*10;const rotateY=-(x-centerX)/centerX*10;this.hoverPanel.style.transform=`perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale3d(1.05, 1.05, 1.05)`};const handleEnter=()=>{this.hoverPanel.style.transition="all 0.2s ease-out"};const handleLeave=()=>{this.hoverPanel.style.transform=`perspective(1000px) rotateX(0) rotateY(0) scale3d(1, 1, 1)`;this.hoverPanel.style.transition="all 0.5s ease-in-out"};this.hoverPanel.addEventListener("mousemove",handleMove);this.hoverPanel.addEventListener("touchmove",handleMove);this.hoverPanel.addEventListener("mouseenter",handleEnter);this.hoverPanel.addEventListener("touchstart",handleEnter);this.hoverPanel.addEventListener("mouseleave",handleLeave);this.hoverPanel.addEventListener("touchend",handleLeave)}_setupEvents(hoverPanel){if(this.settings.Tilt==="only")return;if(this.settings.Click===true){hoverPanel.addEventListener("click",e=>{e.preventDefault();toggleClass(hoverPanel,this.flipClass)})}else if(typeof this.settings.Click==="string"){const clickElements=hoverPanel.querySelectorAll(this.settings.Click);clickElements.forEach(el=>{el.addEventListener("click",()=>{toggleClass(hoverPanel,this.flipClass)})})}else{hoverPanel.addEventListener("mouseenter",()=>{addClass(hoverPanel,this.flipClass)});hoverPanel.addEventListener("mouseleave",()=>{removeClass(hoverPanel,this.flipClass)})}}destroy(){const hoverPanel=this.hoverPanel;const originalElement=hoverPanel.querySelector(".front > *");originalElement.className=this.originalClassName;hoverPanel.parentNode.insertBefore(originalElement,hoverPanel);hoverPanel.parentNode.removeChild(hoverPanel);instanceMap.delete(this.element)}}function justFlipIt(selector,options={}){if(typeof selector==="string"){const elements=document.querySelectorAll(selector);return Array.from(elements).map(el=>new JustFlipIt(el,options))}else if(selector instanceof Element){return new JustFlipIt(selector,options)}else if(selector.length){return Array.from(selector).map(el=>new JustFlipIt(el,options))}}justFlipIt.destroy=function(selector){if(typeof selector==="string"){const elements=document.querySelectorAll(selector);Array.from(elements).forEach(el=>{const instance=instanceMap.get(el);if(instance)instance.destroy()})}else if(selector instanceof Element){const instance=instanceMap.get(selector);if(instance)instance.destroy()}else if(selector.length){Array.from(selector).forEach(el=>{const instance=instanceMap.get(el);if(instance)instance.destroy()})}};return justFlipIt});
@@ -1,61 +0,0 @@
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
- * If true, all CSS classes from the original element are copied to the flip panel (default: true)
30
- */
31
- preserveClasses?: boolean;
32
-
33
- /**
34
- * If true, all inline styles from the original element are copied to the flip panel (default: true)
35
- */
36
- preserveStyles?: boolean;
37
-
38
- /**
39
- * Enables 3D tilt effect.
40
- * - `true`: Combines flip and tilt.
41
- * - `'only'`: Enables only tilt.
42
- * - `false`: Disables tilt (default).
43
- */
44
- Tilt?: boolean | 'only';
45
- }
46
-
47
- /**
48
- * Destroy flip instances matching the selector
49
- */
50
- function destroy(selector: string | Element | NodeListOf<Element> | HTMLCollection): void;
51
- }
52
-
53
- /**
54
- * Initialize flip effect on matching elements
55
- */
56
- declare function justFlipIt(
57
- selector: string | Element | NodeListOf<Element> | HTMLCollection,
58
- options?: justFlipIt.Options
59
- ): any;
60
-
61
- export = justFlipIt;