@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.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +258 -91
- package/dist/agent.cjs +63 -0
- package/dist/agent.cjs.map +7 -0
- package/dist/agent.d.cts +4 -0
- package/dist/agent.d.mts +4 -0
- package/dist/agent.d.ts +4 -0
- package/dist/agent.mjs +43 -0
- package/dist/agent.mjs.map +7 -0
- package/dist/justFlipIt-combined.js +295 -0
- package/dist/justFlipIt-combined.min.js +23 -0
- package/dist/justFlipIt-modern.js +271 -476
- package/dist/justFlipIt-modern.min.js +23 -1
- package/dist/justFlipIt-vanilla.js +272 -343
- package/dist/justFlipIt-vanilla.min.js +23 -1
- package/dist/justFlipIt.cjs +293 -0
- package/dist/justFlipIt.cjs.map +7 -0
- package/dist/justFlipIt.d.cts +4 -0
- package/dist/justFlipIt.d.mts +38 -0
- package/dist/justFlipIt.d.ts +38 -0
- package/dist/justFlipIt.js +269 -391
- package/dist/justFlipIt.js.map +7 -0
- package/dist/justFlipIt.min.js +23 -1
- package/dist/justFlipIt.min.js.map +7 -0
- package/dist/justFlipIt.mjs +272 -0
- package/dist/justFlipIt.mjs.map +7 -0
- package/dist/react.cjs +55 -0
- package/dist/react.cjs.map +7 -0
- package/dist/react.d.cts +3 -0
- package/dist/react.d.mts +3 -0
- package/dist/react.d.ts +3 -0
- package/dist/react.mjs +25 -0
- package/dist/react.mjs.map +7 -0
- package/dist/svelte.cjs +45 -0
- package/dist/svelte.cjs.map +7 -0
- package/dist/svelte.d.cts +3 -0
- package/dist/svelte.d.mts +3 -0
- package/dist/svelte.d.ts +3 -0
- package/dist/svelte.mjs +15 -0
- package/dist/svelte.mjs.map +7 -0
- package/dist/types/justFlipIt.d.ts +36 -59
- package/dist/vue.cjs +49 -0
- package/dist/vue.cjs.map +7 -0
- package/dist/vue.d.cts +3 -0
- package/dist/vue.d.mts +3 -0
- package/dist/vue.d.ts +3 -0
- package/dist/vue.mjs +19 -0
- package/dist/vue.mjs.map +7 -0
- package/package.json +117 -50
- package/src/justFlipIt-combined.js +0 -417
- package/src/justFlipIt-combined.min.js +0 -1
- package/src/justFlipIt-modern.js +0 -500
- package/src/justFlipIt-modern.min.js +0 -1
- package/src/justFlipIt-vanilla.js +0 -366
- package/src/justFlipIt-vanilla.min.js +0 -1
- package/src/justFlipIt.d.ts +0 -61
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/core.js"],
|
|
4
|
+
"sourcesContent": ["const instances = new WeakMap();\nconst defaults = { Click: false, FlipX: false, Duration: 400, Easing: 'cubic-bezier(.22,.61,.36,1)', Tilt: false, Effect: 'flip', ReducedMotion: true, preserveClasses: true, preserveStyles: true, Style: [] };\nconst css = `\n._justFlipIt_panel{position:relative;display:grid;perspective:var(--jfi-perspective,1000px);isolation:isolate}\n._justFlipIt_panel>[data-jfi-face]{grid-area:1/1;min-width:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;transition:transform var(--jfi-duration) var(--jfi-easing),opacity var(--jfi-duration) var(--jfi-easing);transform-origin:center}\n._justFlipIt_panel>[data-jfi-face=back],._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=front]{pointer-events:none}\n._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=back]{pointer-events:auto}\n._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=front]{transform:rotateY(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=back]{transform:rotateY(-180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateY(180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateY(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=front]{transform:rotateX(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=back]{transform:rotateX(-180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateX(180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateX(0deg)}\n._justFlipIt_panel[data-jfi-effect=fade]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back]{opacity:0}\n._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=front],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{opacity:0}\n._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{opacity:1}\n._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{transform:scale(.94)}\n._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{transform:scale(1)}\n._justFlipIt_panel[data-jfi-reduced=true]>[data-jfi-face]{transition:none!important}\n@media(prefers-reduced-motion:reduce){._justFlipIt_panel:not([data-jfi-motion=allow])>[data-jfi-face]{transition:none!important}}\n`;\nfunction styles(doc) {\n if (doc.querySelector('style[data-justflipitstyle=\"v4\"]')) return;\n const style = doc.createElement('style');\n style.dataset.justflipitstyle = 'v4'; style.textContent = css; doc.head.append(style);\n}\nfunction validate(options) {\n if (options.Duration !== undefined && (!Number.isFinite(options.Duration) || options.Duration < 0)) throw new TypeError('Duration must be a non-negative finite number');\n if (options.Effect !== undefined && !['flip', 'fade', 'scale'].includes(options.Effect)) throw new TypeError('Unknown Effect');\n if (options.Tilt && typeof options.Tilt === 'object') {\n for (const key of ['max', 'perspective', 'scale']) {\n if (options.Tilt[key] !== undefined && (!Number.isFinite(options.Tilt[key]) || options.Tilt[key] < 0)) throw new TypeError(`Invalid Tilt.${key}`);\n }\n }\n}\nexport class FlipController {\n constructor(element, options = {}) {\n validate(options);\n if (!element || element.nodeType !== 1) throw new TypeError('Expected an HTML element');\n this.element = element; this.settings = { ...defaults, ...options }; this.flipped = false; this.destroyed = false;\n this.cleanups = []; this.restores = []; this.win = element.ownerDocument.defaultView;\n const doc = element.ownerDocument; styles(doc);\n this.managed = !!options.Faces;\n if (this.managed) {\n this.hoverPanel = element;\n this.frontWrapper = element.querySelector(options.Faces.front);\n this.backWrapper = element.querySelector(options.Faces.back);\n if (!this.frontWrapper || !this.backWrapper || this.frontWrapper === this.backWrapper || this.frontWrapper.parentNode !== element || this.backWrapper.parentNode !== element) throw new TypeError('Faces must select two distinct direct children');\n } else {\n if (!element.parentNode) throw new TypeError('Element must have a parent');\n this.hoverPanel = doc.createElement('div');\n this.frontWrapper = doc.createElement('div'); this.backWrapper = doc.createElement('div');\n if (this.settings.preserveClasses) this.hoverPanel.className = element.className;\n if (this.settings.preserveStyles) this.hoverPanel.style.cssText = element.style.cssText;\n element.before(this.hoverPanel); this.hoverPanel.append(this.frontWrapper, this.backWrapper);\n this.frontWrapper.append(element);\n if (options.Template !== undefined) this.backWrapper.innerHTML = options.Template;\n else {\n const clone = element.cloneNode(true);\n clone.removeAttribute('id'); clone.querySelectorAll('[id]').forEach(node => node.removeAttribute('id'));\n this.backWrapper.append(clone);\n }\n }\n const panel = this.hoverPanel;\n for (const node of [panel, this.frontWrapper, this.backWrapper]) {\n const owned = node === panel ? ['class', 'style', 'tabindex', 'data-jfi-axis', 'data-jfi-effect', 'data-jfi-motion', 'data-jfi-flipped', 'data-jfi-reduced'] : ['style', 'data-jfi-face', 'aria-hidden', 'inert'];\n const attrs = owned.map(name => [name, node.getAttribute(name)]);\n const inert = node.inert || false;\n this.restores.push(() => { node.inert = inert; for (const [name, value] of attrs) { if (value === null) node.removeAttribute(name); else node.setAttribute(name, value); } });\n }\n panel.classList.add('_justFlipIt_panel');\n this.frontWrapper.dataset.jfiFace = 'front'; this.backWrapper.dataset.jfiFace = 'back';\n this.motion = this.win.matchMedia?.('(prefers-reduced-motion: reduce)');\n const motionChange = () => { this.resetTilt(); this.render(); };\n this.motion?.addEventListener('change', motionChange);\n this.cleanups.push(() => this.motion?.removeEventListener('change', motionChange));\n this.configure(); this.events(); this.render();\n instances.set(element, this); instances.set(panel, this);\n }\n listen(type, handler, options) { this.hoverPanel.addEventListener(type, handler, options); this.cleanups.push(() => this.hoverPanel.removeEventListener(type, handler, options)); }\n get reduced() { return this.settings.ReducedMotion !== false && !!this.motion?.matches; }\n configure() {\n const s = this.settings, p = this.hoverPanel;\n p.style.setProperty('--jfi-duration', `${s.Duration}ms`); p.style.setProperty('--jfi-easing', s.Easing);\n p.dataset.jfiAxis = s.FlipX ? 'x' : 'y'; p.dataset.jfiEffect = s.Effect;\n p.dataset.jfiMotion = s.ReducedMotion === false ? 'allow' : 'respect';\n for (const item of s.Style || []) {\n const targets = item.el === 'self' ? [p] : p.querySelectorAll(item.el);\n targets.forEach(node => Object.assign(node.style, item.style));\n }\n // A generic keyboard focus target avoids button roles around interactive children.\n if (s.Tilt !== 'only' && !p.hasAttribute('tabindex')) p.tabIndex = 0;\n }\n events() {\n this.listen('click', event => {\n if (this.settings.Tilt === 'only') return;\n const trigger = this.settings.Click;\n if (trigger === true || (trigger && [].concat(trigger).some(selector => event.target.closest?.(selector) && this.hoverPanel.contains(event.target.closest(selector))))) this.toggle();\n });\n this.listen('keydown', event => {\n if (event.target !== this.hoverPanel || this.settings.Tilt === 'only') return;\n if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); this.toggle(); }\n if (event.key === 'Escape') this.flip(false);\n });\n this.listen('pointerenter', event => { if (!this.settings.Click && this.settings.Tilt !== 'only' && event.pointerType !== 'touch') this.flip(true); });\n this.listen('pointerleave', event => {\n // Touch release also emits pointerleave. The tap must survive it.\n if (event.pointerType === 'touch') return;\n this.resetTilt();\n if (!this.settings.Click && this.settings.Tilt !== 'only') this.flip(false);\n });\n this.listen('pointerdown', event => {\n if (event.pointerType !== 'touch' || event.isPrimary === false || this.touch) return;\n this.resetTilt();\n this.touch = { id: event.pointerId, x: event.clientX, y: event.clientY, moved: false };\n this.queueTilt(event, this.touch);\n }, { passive: true });\n this.listen('pointermove', event => {\n if (event.pointerType !== 'touch') {\n if (!this.touch) this.queueTilt(event);\n return;\n }\n const touch = this.touch;\n if (!touch || touch.id !== event.pointerId) return;\n touch.moved ||= this.touchMoved(event, touch);\n this.queueTilt(event, touch);\n }, { passive: true });\n this.listen('pointerup', event => {\n const touch = this.finishTouch(event);\n if (!touch || touch.moved || this.touchMoved(event, touch)) return;\n // Explicit click triggers continue to use the browser's click event.\n if (!this.settings.Click && this.settings.Tilt !== 'only') this.toggle();\n });\n this.listen('pointercancel', event => {\n if (event.pointerType === 'touch') this.finishTouch(event);\n else this.resetTilt();\n });\n this.listen('lostpointercapture', event => this.finishTouch(event));\n this.baseTransform = this.hoverPanel.style.transform;\n }\n touchMoved(event, touch) {\n return Math.hypot(event.clientX - touch.x, event.clientY - touch.y) > 10;\n }\n finishTouch(event) {\n const touch = this.touch;\n if (event.pointerType !== 'touch' || !touch || touch.id !== event.pointerId) return;\n this.touch = null;\n this.resetTilt();\n return touch;\n }\n queueTilt(event, touch) {\n if (!this.settings.Tilt || this.reduced) return;\n this.point = [event.clientX, event.clientY];\n if (this.frame) return;\n this.frame = this.win.requestAnimationFrame(() => {\n this.frame = 0;\n // Keep the touch reference box stable as the panel rotates.\n const rect = touch\n ? (touch.rect ??= this.hoverPanel.getBoundingClientRect())\n : this.hoverPanel.getBoundingClientRect();\n if (!rect.width || !rect.height) return;\n const { max = 10, perspective = 1000, scale = 1.03 } = this.settings.Tilt;\n const x = Math.max(-1, Math.min(1, (this.point[0] - rect.left) / rect.width * 2 - 1));\n const y = Math.max(-1, Math.min(1, (this.point[1] - rect.top) / rect.height * 2 - 1));\n this.hoverPanel.style.transform = `perspective(${perspective}px) rotateX(${-y * max}deg) rotateY(${x * max}deg) scale(${scale})`;\n });\n }\n resetTilt() { if (this.frame) this.win.cancelAnimationFrame(this.frame); this.frame = 0; this.hoverPanel.style.transform = this.baseTransform || ''; }\n render() {\n this.hoverPanel.dataset.jfiFlipped = String(this.flipped); this.hoverPanel.dataset.jfiReduced = String(this.reduced);\n for (const [node, hidden] of [[this.frontWrapper, this.flipped], [this.backWrapper, !this.flipped]]) { node.setAttribute('aria-hidden', String(hidden)); node.inert = hidden; }\n }\n flip(value = true) {\n if (this.destroyed || this.flipped === !!value) return this;\n const active = this.element.ownerDocument.activeElement;\n if ((value ? this.frontWrapper : this.backWrapper).contains(active)) this.hoverPanel.focus({ preventScroll: true });\n this.flipped = !!value; this.render();\n this.hoverPanel.dispatchEvent(new this.win.CustomEvent('justflipit:change', { bubbles: true, detail: this.getState() }));\n return this;\n }\n toggle() { return this.flip(!this.flipped); }\n update(options = {}) {\n if (this.destroyed) return this;\n if ('Faces' in options) throw new TypeError('Faces cannot change after initialization');\n validate(options);\n if (this.managed && 'Template' in options) throw new TypeError('Render framework face content with the framework');\n this.settings = { ...this.settings, ...options };\n if ('Template' in options) {\n if (this.managed) throw new TypeError('Render framework face content with the framework');\n this.backWrapper.innerHTML = options.Template;\n }\n this.resetTilt(); this.configure(); this.render(); return this;\n }\n getState() { return { flipped: this.flipped, destroyed: this.destroyed, effect: this.settings.Effect }; }\n destroy() {\n if (this.destroyed) return;\n this.resetTilt(); this.cleanups.forEach(fn => fn());\n this.restores.forEach(fn => fn());\n if (!this.managed) { this.hoverPanel.replaceWith(this.element); }\n instances.delete(this.element); instances.delete(this.hoverPanel); this.destroyed = true;\n }\n}\nfunction elements(target) {\n if (typeof target === 'string') return typeof document === 'undefined' ? [] : Array.from(document.querySelectorAll(target));\n if (target?.nodeType === 1) return [target];\n return target ? Array.from(target) : [];\n}\nexport default function justFlipIt(target, options) {\n const result = elements(target).map(element => instances.get(element) || new FlipController(element, options));\n return target?.nodeType === 1 ? result[0] : result;\n}\njustFlipIt.destroy = target => elements(target).forEach(element => instances.get(element)?.destroy());\njustFlipIt.get = element => instances.get(element);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,YAAY,oBAAI,QAAQ;AAC9B,MAAM,WAAW,EAAE,OAAO,OAAO,OAAO,OAAO,UAAU,KAAK,QAAQ,+BAA+B,MAAM,OAAO,QAAQ,QAAQ,eAAe,MAAM,iBAAiB,MAAM,gBAAgB,MAAM,OAAO,CAAC,EAAE;AAC9M,MAAM,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBZ,WAAS,OAAO,KAAK;AACnB,QAAI,IAAI,cAAc,kCAAkC,EAAG;AAC3D,UAAM,QAAQ,IAAI,cAAc,OAAO;AACvC,UAAM,QAAQ,kBAAkB;AAAM,UAAM,cAAc;AAAK,QAAI,KAAK,OAAO,KAAK;AAAA,EACtF;AACA,WAAS,SAAS,SAAS;AACzB,QAAI,QAAQ,aAAa,WAAc,CAAC,OAAO,SAAS,QAAQ,QAAQ,KAAK,QAAQ,WAAW,GAAI,OAAM,IAAI,UAAU,+CAA+C;AACvK,QAAI,QAAQ,WAAW,UAAa,CAAC,CAAC,QAAQ,QAAQ,OAAO,EAAE,SAAS,QAAQ,MAAM,EAAG,OAAM,IAAI,UAAU,gBAAgB;AAC7H,QAAI,QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAAU;AACpD,iBAAW,OAAO,CAAC,OAAO,eAAe,OAAO,GAAG;AACjD,YAAI,QAAQ,KAAK,GAAG,MAAM,WAAc,CAAC,OAAO,SAAS,QAAQ,KAAK,GAAG,CAAC,KAAK,QAAQ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AO,KAAK,IAAI,eAAe,SAAS,OAAO,CAAC;AAC7G,WAAO,QAAQ,aAAa,IAAI,OAAO,CAAC,IAAI;AAAA,EAC9C;AACA,aAAW,UAAU,YAAU,SAAS,MAAM,EAAE,QAAQ,aAAW,UAAU,IAAI,OAAO,GAAG,QAAQ,CAAC;AACpG,aAAW,MAAM,aAAW,UAAU,IAAI,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/justFlipIt.min.js
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
(function(root,factory){if(typeof define==="function"&&define.amd){define(["jquery"],function(jQuery){return factory(jQuery||root.jQuery||root.$)})}else if(typeof module==="object"&&module.exports){var jQuery=typeof window!=="undefined"?window.jQuery:undefined;if(!jQuery){try{jQuery=require("jquery")}catch(e){jQuery=null}}module.exports=factory(jQuery)}else{root.justFlipIt=factory(root.jQuery||root.$)}})(typeof self!=="undefined"?self:this,function(jQuery){"use strict";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(function(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}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)}}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()})}};if(jQuery){jQuery.fn.justFlipIt=function(options){return this.each(function(){if(!jQuery.data(this,"plugin_justFlipIt")){jQuery.data(this,"plugin_justFlipIt",new JustFlipIt(this,options))}})};jQuery.fn.destroy=function(){return this.each(function(){const instance=instanceMap.get(this);if(instance){instance.destroy();jQuery.removeData(this,"plugin_justFlipIt")}})};var api=function(selector,options){if(typeof selector==="string"){return jQuery(selector).justFlipIt(options)}else if(selector instanceof Element){return jQuery(selector).justFlipIt(options)}else if(selector instanceof jQuery){return selector.justFlipIt(options)}};api.destroy=function(selector){if(typeof selector==="string"){jQuery(selector).destroy()}else if(selector instanceof Element){jQuery(selector).destroy()}else if(selector instanceof jQuery){selector.destroy()}};return api}return justFlipIt});
|
|
1
|
+
var JustFlipItModule=(()=>{var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var b=(i,t)=>{for(var e in t)d(i,e,{get:t[e],enumerable:!0})},_=(i,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of T(t))!v.call(i,s)&&s!==e&&d(i,s,{get:()=>t[s],enumerable:!(a=g(t,s))||a.enumerable});return i};var w=i=>_(d({},"__esModule",{value:!0}),i);var I={};b(I,{FlipController:()=>c,default:()=>h});var n=new WeakMap,k={Click:!1,FlipX:!1,Duration:400,Easing:"cubic-bezier(.22,.61,.36,1)",Tilt:!1,Effect:"flip",ReducedMotion:!0,preserveClasses:!0,preserveStyles:!0,Style:[]},F=`
|
|
2
|
+
._justFlipIt_panel{position:relative;display:grid;perspective:var(--jfi-perspective,1000px);isolation:isolate}
|
|
3
|
+
._justFlipIt_panel>[data-jfi-face]{grid-area:1/1;min-width:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;transition:transform var(--jfi-duration) var(--jfi-easing),opacity var(--jfi-duration) var(--jfi-easing);transform-origin:center}
|
|
4
|
+
._justFlipIt_panel>[data-jfi-face=back],._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=front]{pointer-events:none}
|
|
5
|
+
._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=back]{pointer-events:auto}
|
|
6
|
+
._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=front]{transform:rotateY(0deg)}
|
|
7
|
+
._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=back]{transform:rotateY(-180deg)}
|
|
8
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateY(180deg)}
|
|
9
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateY(0deg)}
|
|
10
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=front]{transform:rotateX(0deg)}
|
|
11
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=back]{transform:rotateX(-180deg)}
|
|
12
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateX(180deg)}
|
|
13
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateX(0deg)}
|
|
14
|
+
._justFlipIt_panel[data-jfi-effect=fade]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back]{opacity:0}
|
|
15
|
+
._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=front],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{opacity:0}
|
|
16
|
+
._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{opacity:1}
|
|
17
|
+
._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{transform:scale(.94)}
|
|
18
|
+
._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{transform:scale(1)}
|
|
19
|
+
._justFlipIt_panel[data-jfi-reduced=true]>[data-jfi-face]{transition:none!important}
|
|
20
|
+
@media(prefers-reduced-motion:reduce){._justFlipIt_panel:not([data-jfi-motion=allow])>[data-jfi-face]{transition:none!important}}
|
|
21
|
+
`;function E(i){if(i.querySelector('style[data-justflipitstyle="v4"]'))return;let t=i.createElement("style");t.dataset.justflipitstyle="v4",t.textContent=F,i.head.append(t)}function j(i){if(i.Duration!==void 0&&(!Number.isFinite(i.Duration)||i.Duration<0))throw new TypeError("Duration must be a non-negative finite number");if(i.Effect!==void 0&&!["flip","fade","scale"].includes(i.Effect))throw new TypeError("Unknown Effect");if(i.Tilt&&typeof i.Tilt=="object"){for(let t of["max","perspective","scale"])if(i.Tilt[t]!==void 0&&(!Number.isFinite(i.Tilt[t])||i.Tilt[t]<0))throw new TypeError(`Invalid Tilt.${t}`)}}var c=class{constructor(t,e={}){if(j(e),!t||t.nodeType!==1)throw new TypeError("Expected an HTML element");this.element=t,this.settings={...k,...e},this.flipped=!1,this.destroyed=!1,this.cleanups=[],this.restores=[],this.win=t.ownerDocument.defaultView;let a=t.ownerDocument;if(E(a),this.managed=!!e.Faces,this.managed){if(this.hoverPanel=t,this.frontWrapper=t.querySelector(e.Faces.front),this.backWrapper=t.querySelector(e.Faces.back),!this.frontWrapper||!this.backWrapper||this.frontWrapper===this.backWrapper||this.frontWrapper.parentNode!==t||this.backWrapper.parentNode!==t)throw new TypeError("Faces must select two distinct direct children")}else{if(!t.parentNode)throw new TypeError("Element must have a parent");if(this.hoverPanel=a.createElement("div"),this.frontWrapper=a.createElement("div"),this.backWrapper=a.createElement("div"),this.settings.preserveClasses&&(this.hoverPanel.className=t.className),this.settings.preserveStyles&&(this.hoverPanel.style.cssText=t.style.cssText),t.before(this.hoverPanel),this.hoverPanel.append(this.frontWrapper,this.backWrapper),this.frontWrapper.append(t),e.Template!==void 0)this.backWrapper.innerHTML=e.Template;else{let r=t.cloneNode(!0);r.removeAttribute("id"),r.querySelectorAll("[id]").forEach(l=>l.removeAttribute("id")),this.backWrapper.append(r)}}let s=this.hoverPanel;for(let r of[s,this.frontWrapper,this.backWrapper]){let p=(r===s?["class","style","tabindex","data-jfi-axis","data-jfi-effect","data-jfi-motion","data-jfi-flipped","data-jfi-reduced"]:["style","data-jfi-face","aria-hidden","inert"]).map(o=>[o,r.getAttribute(o)]),y=r.inert||!1;this.restores.push(()=>{r.inert=y;for(let[o,u]of p)u===null?r.removeAttribute(o):r.setAttribute(o,u)})}s.classList.add("_justFlipIt_panel"),this.frontWrapper.dataset.jfiFace="front",this.backWrapper.dataset.jfiFace="back",this.motion=this.win.matchMedia?.("(prefers-reduced-motion: reduce)");let f=()=>{this.resetTilt(),this.render()};this.motion?.addEventListener("change",f),this.cleanups.push(()=>this.motion?.removeEventListener("change",f)),this.configure(),this.events(),this.render(),n.set(t,this),n.set(s,this)}listen(t,e,a){this.hoverPanel.addEventListener(t,e,a),this.cleanups.push(()=>this.hoverPanel.removeEventListener(t,e,a))}get reduced(){return this.settings.ReducedMotion!==!1&&!!this.motion?.matches}configure(){let t=this.settings,e=this.hoverPanel;e.style.setProperty("--jfi-duration",`${t.Duration}ms`),e.style.setProperty("--jfi-easing",t.Easing),e.dataset.jfiAxis=t.FlipX?"x":"y",e.dataset.jfiEffect=t.Effect,e.dataset.jfiMotion=t.ReducedMotion===!1?"allow":"respect";for(let a of t.Style||[])(a.el==="self"?[e]:e.querySelectorAll(a.el)).forEach(f=>Object.assign(f.style,a.style));t.Tilt!=="only"&&!e.hasAttribute("tabindex")&&(e.tabIndex=0)}events(){this.listen("click",t=>{if(this.settings.Tilt==="only")return;let e=this.settings.Click;(e===!0||e&&[].concat(e).some(a=>t.target.closest?.(a)&&this.hoverPanel.contains(t.target.closest(a))))&&this.toggle()}),this.listen("keydown",t=>{t.target!==this.hoverPanel||this.settings.Tilt==="only"||((t.key==="Enter"||t.key===" ")&&(t.preventDefault(),this.toggle()),t.key==="Escape"&&this.flip(!1))}),this.listen("pointerenter",t=>{!this.settings.Click&&this.settings.Tilt!=="only"&&t.pointerType!=="touch"&&this.flip(!0)}),this.listen("pointerleave",t=>{t.pointerType!=="touch"&&(this.resetTilt(),!this.settings.Click&&this.settings.Tilt!=="only"&&this.flip(!1))}),this.listen("pointerdown",t=>{t.pointerType!=="touch"||t.isPrimary===!1||this.touch||(this.resetTilt(),this.touch={id:t.pointerId,x:t.clientX,y:t.clientY,moved:!1},this.queueTilt(t,this.touch))},{passive:!0}),this.listen("pointermove",t=>{if(t.pointerType!=="touch"){this.touch||this.queueTilt(t);return}let e=this.touch;!e||e.id!==t.pointerId||(e.moved||(e.moved=this.touchMoved(t,e)),this.queueTilt(t,e))},{passive:!0}),this.listen("pointerup",t=>{let e=this.finishTouch(t);!e||e.moved||this.touchMoved(t,e)||!this.settings.Click&&this.settings.Tilt!=="only"&&this.toggle()}),this.listen("pointercancel",t=>{t.pointerType==="touch"?this.finishTouch(t):this.resetTilt()}),this.listen("lostpointercapture",t=>this.finishTouch(t)),this.baseTransform=this.hoverPanel.style.transform}touchMoved(t,e){return Math.hypot(t.clientX-e.x,t.clientY-e.y)>10}finishTouch(t){let e=this.touch;if(!(t.pointerType!=="touch"||!e||e.id!==t.pointerId))return this.touch=null,this.resetTilt(),e}queueTilt(t,e){!this.settings.Tilt||this.reduced||(this.point=[t.clientX,t.clientY],!this.frame&&(this.frame=this.win.requestAnimationFrame(()=>{this.frame=0;let a=e?e.rect??(e.rect=this.hoverPanel.getBoundingClientRect()):this.hoverPanel.getBoundingClientRect();if(!a.width||!a.height)return;let{max:s=10,perspective:f=1e3,scale:r=1.03}=this.settings.Tilt,l=Math.max(-1,Math.min(1,(this.point[0]-a.left)/a.width*2-1)),p=Math.max(-1,Math.min(1,(this.point[1]-a.top)/a.height*2-1));this.hoverPanel.style.transform=`perspective(${f}px) rotateX(${-p*s}deg) rotateY(${l*s}deg) scale(${r})`})))}resetTilt(){this.frame&&this.win.cancelAnimationFrame(this.frame),this.frame=0,this.hoverPanel.style.transform=this.baseTransform||""}render(){this.hoverPanel.dataset.jfiFlipped=String(this.flipped),this.hoverPanel.dataset.jfiReduced=String(this.reduced);for(let[t,e]of[[this.frontWrapper,this.flipped],[this.backWrapper,!this.flipped]])t.setAttribute("aria-hidden",String(e)),t.inert=e}flip(t=!0){if(this.destroyed||this.flipped===!!t)return this;let e=this.element.ownerDocument.activeElement;return(t?this.frontWrapper:this.backWrapper).contains(e)&&this.hoverPanel.focus({preventScroll:!0}),this.flipped=!!t,this.render(),this.hoverPanel.dispatchEvent(new this.win.CustomEvent("justflipit:change",{bubbles:!0,detail:this.getState()})),this}toggle(){return this.flip(!this.flipped)}update(t={}){if(this.destroyed)return this;if("Faces"in t)throw new TypeError("Faces cannot change after initialization");if(j(t),this.managed&&"Template"in t)throw new TypeError("Render framework face content with the framework");if(this.settings={...this.settings,...t},"Template"in t){if(this.managed)throw new TypeError("Render framework face content with the framework");this.backWrapper.innerHTML=t.Template}return this.resetTilt(),this.configure(),this.render(),this}getState(){return{flipped:this.flipped,destroyed:this.destroyed,effect:this.settings.Effect}}destroy(){this.destroyed||(this.resetTilt(),this.cleanups.forEach(t=>t()),this.restores.forEach(t=>t()),this.managed||this.hoverPanel.replaceWith(this.element),n.delete(this.element),n.delete(this.hoverPanel),this.destroyed=!0)}};function m(i){return typeof i=="string"?typeof document>"u"?[]:Array.from(document.querySelectorAll(i)):i?.nodeType===1?[i]:i?Array.from(i):[]}function h(i,t){let e=m(i).map(a=>n.get(a)||new c(a,t));return i?.nodeType===1?e[0]:e}h.destroy=i=>m(i).forEach(t=>n.get(t)?.destroy());h.get=i=>n.get(i);return w(I);})();
|
|
22
|
+
globalThis.justFlipIt = JustFlipItModule.default;
|
|
23
|
+
//# sourceMappingURL=justFlipIt.min.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/core.js"],
|
|
4
|
+
"sourcesContent": ["const instances = new WeakMap();\nconst defaults = { Click: false, FlipX: false, Duration: 400, Easing: 'cubic-bezier(.22,.61,.36,1)', Tilt: false, Effect: 'flip', ReducedMotion: true, preserveClasses: true, preserveStyles: true, Style: [] };\nconst css = `\n._justFlipIt_panel{position:relative;display:grid;perspective:var(--jfi-perspective,1000px);isolation:isolate}\n._justFlipIt_panel>[data-jfi-face]{grid-area:1/1;min-width:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;transition:transform var(--jfi-duration) var(--jfi-easing),opacity var(--jfi-duration) var(--jfi-easing);transform-origin:center}\n._justFlipIt_panel>[data-jfi-face=back],._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=front]{pointer-events:none}\n._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=back]{pointer-events:auto}\n._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=front]{transform:rotateY(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=back]{transform:rotateY(-180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateY(180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateY(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=front]{transform:rotateX(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=back]{transform:rotateX(-180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateX(180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateX(0deg)}\n._justFlipIt_panel[data-jfi-effect=fade]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back]{opacity:0}\n._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=front],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{opacity:0}\n._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{opacity:1}\n._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{transform:scale(.94)}\n._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{transform:scale(1)}\n._justFlipIt_panel[data-jfi-reduced=true]>[data-jfi-face]{transition:none!important}\n@media(prefers-reduced-motion:reduce){._justFlipIt_panel:not([data-jfi-motion=allow])>[data-jfi-face]{transition:none!important}}\n`;\nfunction styles(doc) {\n if (doc.querySelector('style[data-justflipitstyle=\"v4\"]')) return;\n const style = doc.createElement('style');\n style.dataset.justflipitstyle = 'v4'; style.textContent = css; doc.head.append(style);\n}\nfunction validate(options) {\n if (options.Duration !== undefined && (!Number.isFinite(options.Duration) || options.Duration < 0)) throw new TypeError('Duration must be a non-negative finite number');\n if (options.Effect !== undefined && !['flip', 'fade', 'scale'].includes(options.Effect)) throw new TypeError('Unknown Effect');\n if (options.Tilt && typeof options.Tilt === 'object') {\n for (const key of ['max', 'perspective', 'scale']) {\n if (options.Tilt[key] !== undefined && (!Number.isFinite(options.Tilt[key]) || options.Tilt[key] < 0)) throw new TypeError(`Invalid Tilt.${key}`);\n }\n }\n}\nexport class FlipController {\n constructor(element, options = {}) {\n validate(options);\n if (!element || element.nodeType !== 1) throw new TypeError('Expected an HTML element');\n this.element = element; this.settings = { ...defaults, ...options }; this.flipped = false; this.destroyed = false;\n this.cleanups = []; this.restores = []; this.win = element.ownerDocument.defaultView;\n const doc = element.ownerDocument; styles(doc);\n this.managed = !!options.Faces;\n if (this.managed) {\n this.hoverPanel = element;\n this.frontWrapper = element.querySelector(options.Faces.front);\n this.backWrapper = element.querySelector(options.Faces.back);\n if (!this.frontWrapper || !this.backWrapper || this.frontWrapper === this.backWrapper || this.frontWrapper.parentNode !== element || this.backWrapper.parentNode !== element) throw new TypeError('Faces must select two distinct direct children');\n } else {\n if (!element.parentNode) throw new TypeError('Element must have a parent');\n this.hoverPanel = doc.createElement('div');\n this.frontWrapper = doc.createElement('div'); this.backWrapper = doc.createElement('div');\n if (this.settings.preserveClasses) this.hoverPanel.className = element.className;\n if (this.settings.preserveStyles) this.hoverPanel.style.cssText = element.style.cssText;\n element.before(this.hoverPanel); this.hoverPanel.append(this.frontWrapper, this.backWrapper);\n this.frontWrapper.append(element);\n if (options.Template !== undefined) this.backWrapper.innerHTML = options.Template;\n else {\n const clone = element.cloneNode(true);\n clone.removeAttribute('id'); clone.querySelectorAll('[id]').forEach(node => node.removeAttribute('id'));\n this.backWrapper.append(clone);\n }\n }\n const panel = this.hoverPanel;\n for (const node of [panel, this.frontWrapper, this.backWrapper]) {\n const owned = node === panel ? ['class', 'style', 'tabindex', 'data-jfi-axis', 'data-jfi-effect', 'data-jfi-motion', 'data-jfi-flipped', 'data-jfi-reduced'] : ['style', 'data-jfi-face', 'aria-hidden', 'inert'];\n const attrs = owned.map(name => [name, node.getAttribute(name)]);\n const inert = node.inert || false;\n this.restores.push(() => { node.inert = inert; for (const [name, value] of attrs) { if (value === null) node.removeAttribute(name); else node.setAttribute(name, value); } });\n }\n panel.classList.add('_justFlipIt_panel');\n this.frontWrapper.dataset.jfiFace = 'front'; this.backWrapper.dataset.jfiFace = 'back';\n this.motion = this.win.matchMedia?.('(prefers-reduced-motion: reduce)');\n const motionChange = () => { this.resetTilt(); this.render(); };\n this.motion?.addEventListener('change', motionChange);\n this.cleanups.push(() => this.motion?.removeEventListener('change', motionChange));\n this.configure(); this.events(); this.render();\n instances.set(element, this); instances.set(panel, this);\n }\n listen(type, handler, options) { this.hoverPanel.addEventListener(type, handler, options); this.cleanups.push(() => this.hoverPanel.removeEventListener(type, handler, options)); }\n get reduced() { return this.settings.ReducedMotion !== false && !!this.motion?.matches; }\n configure() {\n const s = this.settings, p = this.hoverPanel;\n p.style.setProperty('--jfi-duration', `${s.Duration}ms`); p.style.setProperty('--jfi-easing', s.Easing);\n p.dataset.jfiAxis = s.FlipX ? 'x' : 'y'; p.dataset.jfiEffect = s.Effect;\n p.dataset.jfiMotion = s.ReducedMotion === false ? 'allow' : 'respect';\n for (const item of s.Style || []) {\n const targets = item.el === 'self' ? [p] : p.querySelectorAll(item.el);\n targets.forEach(node => Object.assign(node.style, item.style));\n }\n // A generic keyboard focus target avoids button roles around interactive children.\n if (s.Tilt !== 'only' && !p.hasAttribute('tabindex')) p.tabIndex = 0;\n }\n events() {\n this.listen('click', event => {\n if (this.settings.Tilt === 'only') return;\n const trigger = this.settings.Click;\n if (trigger === true || (trigger && [].concat(trigger).some(selector => event.target.closest?.(selector) && this.hoverPanel.contains(event.target.closest(selector))))) this.toggle();\n });\n this.listen('keydown', event => {\n if (event.target !== this.hoverPanel || this.settings.Tilt === 'only') return;\n if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); this.toggle(); }\n if (event.key === 'Escape') this.flip(false);\n });\n this.listen('pointerenter', event => { if (!this.settings.Click && this.settings.Tilt !== 'only' && event.pointerType !== 'touch') this.flip(true); });\n this.listen('pointerleave', event => {\n // Touch release also emits pointerleave. The tap must survive it.\n if (event.pointerType === 'touch') return;\n this.resetTilt();\n if (!this.settings.Click && this.settings.Tilt !== 'only') this.flip(false);\n });\n this.listen('pointerdown', event => {\n if (event.pointerType !== 'touch' || event.isPrimary === false || this.touch) return;\n this.resetTilt();\n this.touch = { id: event.pointerId, x: event.clientX, y: event.clientY, moved: false };\n this.queueTilt(event, this.touch);\n }, { passive: true });\n this.listen('pointermove', event => {\n if (event.pointerType !== 'touch') {\n if (!this.touch) this.queueTilt(event);\n return;\n }\n const touch = this.touch;\n if (!touch || touch.id !== event.pointerId) return;\n touch.moved ||= this.touchMoved(event, touch);\n this.queueTilt(event, touch);\n }, { passive: true });\n this.listen('pointerup', event => {\n const touch = this.finishTouch(event);\n if (!touch || touch.moved || this.touchMoved(event, touch)) return;\n // Explicit click triggers continue to use the browser's click event.\n if (!this.settings.Click && this.settings.Tilt !== 'only') this.toggle();\n });\n this.listen('pointercancel', event => {\n if (event.pointerType === 'touch') this.finishTouch(event);\n else this.resetTilt();\n });\n this.listen('lostpointercapture', event => this.finishTouch(event));\n this.baseTransform = this.hoverPanel.style.transform;\n }\n touchMoved(event, touch) {\n return Math.hypot(event.clientX - touch.x, event.clientY - touch.y) > 10;\n }\n finishTouch(event) {\n const touch = this.touch;\n if (event.pointerType !== 'touch' || !touch || touch.id !== event.pointerId) return;\n this.touch = null;\n this.resetTilt();\n return touch;\n }\n queueTilt(event, touch) {\n if (!this.settings.Tilt || this.reduced) return;\n this.point = [event.clientX, event.clientY];\n if (this.frame) return;\n this.frame = this.win.requestAnimationFrame(() => {\n this.frame = 0;\n // Keep the touch reference box stable as the panel rotates.\n const rect = touch\n ? (touch.rect ??= this.hoverPanel.getBoundingClientRect())\n : this.hoverPanel.getBoundingClientRect();\n if (!rect.width || !rect.height) return;\n const { max = 10, perspective = 1000, scale = 1.03 } = this.settings.Tilt;\n const x = Math.max(-1, Math.min(1, (this.point[0] - rect.left) / rect.width * 2 - 1));\n const y = Math.max(-1, Math.min(1, (this.point[1] - rect.top) / rect.height * 2 - 1));\n this.hoverPanel.style.transform = `perspective(${perspective}px) rotateX(${-y * max}deg) rotateY(${x * max}deg) scale(${scale})`;\n });\n }\n resetTilt() { if (this.frame) this.win.cancelAnimationFrame(this.frame); this.frame = 0; this.hoverPanel.style.transform = this.baseTransform || ''; }\n render() {\n this.hoverPanel.dataset.jfiFlipped = String(this.flipped); this.hoverPanel.dataset.jfiReduced = String(this.reduced);\n for (const [node, hidden] of [[this.frontWrapper, this.flipped], [this.backWrapper, !this.flipped]]) { node.setAttribute('aria-hidden', String(hidden)); node.inert = hidden; }\n }\n flip(value = true) {\n if (this.destroyed || this.flipped === !!value) return this;\n const active = this.element.ownerDocument.activeElement;\n if ((value ? this.frontWrapper : this.backWrapper).contains(active)) this.hoverPanel.focus({ preventScroll: true });\n this.flipped = !!value; this.render();\n this.hoverPanel.dispatchEvent(new this.win.CustomEvent('justflipit:change', { bubbles: true, detail: this.getState() }));\n return this;\n }\n toggle() { return this.flip(!this.flipped); }\n update(options = {}) {\n if (this.destroyed) return this;\n if ('Faces' in options) throw new TypeError('Faces cannot change after initialization');\n validate(options);\n if (this.managed && 'Template' in options) throw new TypeError('Render framework face content with the framework');\n this.settings = { ...this.settings, ...options };\n if ('Template' in options) {\n if (this.managed) throw new TypeError('Render framework face content with the framework');\n this.backWrapper.innerHTML = options.Template;\n }\n this.resetTilt(); this.configure(); this.render(); return this;\n }\n getState() { return { flipped: this.flipped, destroyed: this.destroyed, effect: this.settings.Effect }; }\n destroy() {\n if (this.destroyed) return;\n this.resetTilt(); this.cleanups.forEach(fn => fn());\n this.restores.forEach(fn => fn());\n if (!this.managed) { this.hoverPanel.replaceWith(this.element); }\n instances.delete(this.element); instances.delete(this.hoverPanel); this.destroyed = true;\n }\n}\nfunction elements(target) {\n if (typeof target === 'string') return typeof document === 'undefined' ? [] : Array.from(document.querySelectorAll(target));\n if (target?.nodeType === 1) return [target];\n return target ? Array.from(target) : [];\n}\nexport default function justFlipIt(target, options) {\n const result = elements(target).map(element => instances.get(element) || new FlipController(element, options));\n return target?.nodeType === 1 ? result[0] : result;\n}\njustFlipIt.destroy = target => elements(target).forEach(element => instances.get(element)?.destroy());\njustFlipIt.get = element => instances.get(element);\n"],
|
|
5
|
+
"mappings": "ubAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,YAAAC,IAAA,IAAMC,EAAY,IAAI,QAChBC,EAAW,CAAE,MAAO,GAAO,MAAO,GAAO,SAAU,IAAK,OAAQ,8BAA+B,KAAM,GAAO,OAAQ,OAAQ,cAAe,GAAM,gBAAiB,GAAM,eAAgB,GAAM,MAAO,CAAC,CAAE,EACxMC,EAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBZ,SAASC,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KAAKA,CAAM,EAAI,CAAC,CACxC,CACe,SAARtC,EAA4BsC,EAAQ9B,EAAS,CAClD,IAAM+B,EAASF,EAASC,CAAM,EAAE,IAAI5B,GAAWT,EAAU,IAAIS,CAAO,GAAK,IAAIX,EAAeW,EAASF,CAAO,CAAC,EAC7G,OAAO8B,GAAQ,WAAa,EAAIC,EAAO,CAAC,EAAIA,CAC9C,CACAvC,EAAW,QAAUsC,GAAUD,EAASC,CAAM,EAAE,QAAQ5B,GAAWT,EAAU,IAAIS,CAAO,GAAG,QAAQ,CAAC,EACpGV,EAAW,IAAMU,GAAWT,EAAU,IAAIS,CAAO",
|
|
6
|
+
"names": ["core_exports", "__export", "FlipController", "justFlipIt", "instances", "defaults", "css", "styles", "doc", "style", "validate", "options", "key", "element", "clone", "node", "panel", "attrs", "name", "inert", "value", "motionChange", "type", "handler", "s", "p", "item", "event", "trigger", "selector", "touch", "rect", "max", "perspective", "scale", "x", "y", "hidden", "active", "fn", "elements", "target", "result"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// src/core.js
|
|
2
|
+
var instances = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
var defaults = { Click: false, FlipX: false, Duration: 400, Easing: "cubic-bezier(.22,.61,.36,1)", Tilt: false, Effect: "flip", ReducedMotion: true, preserveClasses: true, preserveStyles: true, Style: [] };
|
|
4
|
+
var css = `
|
|
5
|
+
._justFlipIt_panel{position:relative;display:grid;perspective:var(--jfi-perspective,1000px);isolation:isolate}
|
|
6
|
+
._justFlipIt_panel>[data-jfi-face]{grid-area:1/1;min-width:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;transition:transform var(--jfi-duration) var(--jfi-easing),opacity var(--jfi-duration) var(--jfi-easing);transform-origin:center}
|
|
7
|
+
._justFlipIt_panel>[data-jfi-face=back],._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=front]{pointer-events:none}
|
|
8
|
+
._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=back]{pointer-events:auto}
|
|
9
|
+
._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=front]{transform:rotateY(0deg)}
|
|
10
|
+
._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=back]{transform:rotateY(-180deg)}
|
|
11
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateY(180deg)}
|
|
12
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateY(0deg)}
|
|
13
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=front]{transform:rotateX(0deg)}
|
|
14
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=back]{transform:rotateX(-180deg)}
|
|
15
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateX(180deg)}
|
|
16
|
+
._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateX(0deg)}
|
|
17
|
+
._justFlipIt_panel[data-jfi-effect=fade]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back]{opacity:0}
|
|
18
|
+
._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=front],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{opacity:0}
|
|
19
|
+
._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{opacity:1}
|
|
20
|
+
._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{transform:scale(.94)}
|
|
21
|
+
._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{transform:scale(1)}
|
|
22
|
+
._justFlipIt_panel[data-jfi-reduced=true]>[data-jfi-face]{transition:none!important}
|
|
23
|
+
@media(prefers-reduced-motion:reduce){._justFlipIt_panel:not([data-jfi-motion=allow])>[data-jfi-face]{transition:none!important}}
|
|
24
|
+
`;
|
|
25
|
+
function styles(doc) {
|
|
26
|
+
if (doc.querySelector('style[data-justflipitstyle="v4"]')) return;
|
|
27
|
+
const style = doc.createElement("style");
|
|
28
|
+
style.dataset.justflipitstyle = "v4";
|
|
29
|
+
style.textContent = css;
|
|
30
|
+
doc.head.append(style);
|
|
31
|
+
}
|
|
32
|
+
function validate(options) {
|
|
33
|
+
if (options.Duration !== void 0 && (!Number.isFinite(options.Duration) || options.Duration < 0)) throw new TypeError("Duration must be a non-negative finite number");
|
|
34
|
+
if (options.Effect !== void 0 && !["flip", "fade", "scale"].includes(options.Effect)) throw new TypeError("Unknown Effect");
|
|
35
|
+
if (options.Tilt && typeof options.Tilt === "object") {
|
|
36
|
+
for (const key of ["max", "perspective", "scale"]) {
|
|
37
|
+
if (options.Tilt[key] !== void 0 && (!Number.isFinite(options.Tilt[key]) || options.Tilt[key] < 0)) throw new TypeError(`Invalid Tilt.${key}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
var FlipController = class {
|
|
42
|
+
constructor(element, options = {}) {
|
|
43
|
+
validate(options);
|
|
44
|
+
if (!element || element.nodeType !== 1) throw new TypeError("Expected an HTML element");
|
|
45
|
+
this.element = element;
|
|
46
|
+
this.settings = { ...defaults, ...options };
|
|
47
|
+
this.flipped = false;
|
|
48
|
+
this.destroyed = false;
|
|
49
|
+
this.cleanups = [];
|
|
50
|
+
this.restores = [];
|
|
51
|
+
this.win = element.ownerDocument.defaultView;
|
|
52
|
+
const doc = element.ownerDocument;
|
|
53
|
+
styles(doc);
|
|
54
|
+
this.managed = !!options.Faces;
|
|
55
|
+
if (this.managed) {
|
|
56
|
+
this.hoverPanel = element;
|
|
57
|
+
this.frontWrapper = element.querySelector(options.Faces.front);
|
|
58
|
+
this.backWrapper = element.querySelector(options.Faces.back);
|
|
59
|
+
if (!this.frontWrapper || !this.backWrapper || this.frontWrapper === this.backWrapper || this.frontWrapper.parentNode !== element || this.backWrapper.parentNode !== element) throw new TypeError("Faces must select two distinct direct children");
|
|
60
|
+
} else {
|
|
61
|
+
if (!element.parentNode) throw new TypeError("Element must have a parent");
|
|
62
|
+
this.hoverPanel = doc.createElement("div");
|
|
63
|
+
this.frontWrapper = doc.createElement("div");
|
|
64
|
+
this.backWrapper = doc.createElement("div");
|
|
65
|
+
if (this.settings.preserveClasses) this.hoverPanel.className = element.className;
|
|
66
|
+
if (this.settings.preserveStyles) this.hoverPanel.style.cssText = element.style.cssText;
|
|
67
|
+
element.before(this.hoverPanel);
|
|
68
|
+
this.hoverPanel.append(this.frontWrapper, this.backWrapper);
|
|
69
|
+
this.frontWrapper.append(element);
|
|
70
|
+
if (options.Template !== void 0) this.backWrapper.innerHTML = options.Template;
|
|
71
|
+
else {
|
|
72
|
+
const clone = element.cloneNode(true);
|
|
73
|
+
clone.removeAttribute("id");
|
|
74
|
+
clone.querySelectorAll("[id]").forEach((node) => node.removeAttribute("id"));
|
|
75
|
+
this.backWrapper.append(clone);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const panel = this.hoverPanel;
|
|
79
|
+
for (const node of [panel, this.frontWrapper, this.backWrapper]) {
|
|
80
|
+
const owned = node === panel ? ["class", "style", "tabindex", "data-jfi-axis", "data-jfi-effect", "data-jfi-motion", "data-jfi-flipped", "data-jfi-reduced"] : ["style", "data-jfi-face", "aria-hidden", "inert"];
|
|
81
|
+
const attrs = owned.map((name) => [name, node.getAttribute(name)]);
|
|
82
|
+
const inert = node.inert || false;
|
|
83
|
+
this.restores.push(() => {
|
|
84
|
+
node.inert = inert;
|
|
85
|
+
for (const [name, value] of attrs) {
|
|
86
|
+
if (value === null) node.removeAttribute(name);
|
|
87
|
+
else node.setAttribute(name, value);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
panel.classList.add("_justFlipIt_panel");
|
|
92
|
+
this.frontWrapper.dataset.jfiFace = "front";
|
|
93
|
+
this.backWrapper.dataset.jfiFace = "back";
|
|
94
|
+
this.motion = this.win.matchMedia?.("(prefers-reduced-motion: reduce)");
|
|
95
|
+
const motionChange = () => {
|
|
96
|
+
this.resetTilt();
|
|
97
|
+
this.render();
|
|
98
|
+
};
|
|
99
|
+
this.motion?.addEventListener("change", motionChange);
|
|
100
|
+
this.cleanups.push(() => this.motion?.removeEventListener("change", motionChange));
|
|
101
|
+
this.configure();
|
|
102
|
+
this.events();
|
|
103
|
+
this.render();
|
|
104
|
+
instances.set(element, this);
|
|
105
|
+
instances.set(panel, this);
|
|
106
|
+
}
|
|
107
|
+
listen(type, handler, options) {
|
|
108
|
+
this.hoverPanel.addEventListener(type, handler, options);
|
|
109
|
+
this.cleanups.push(() => this.hoverPanel.removeEventListener(type, handler, options));
|
|
110
|
+
}
|
|
111
|
+
get reduced() {
|
|
112
|
+
return this.settings.ReducedMotion !== false && !!this.motion?.matches;
|
|
113
|
+
}
|
|
114
|
+
configure() {
|
|
115
|
+
const s = this.settings, p = this.hoverPanel;
|
|
116
|
+
p.style.setProperty("--jfi-duration", `${s.Duration}ms`);
|
|
117
|
+
p.style.setProperty("--jfi-easing", s.Easing);
|
|
118
|
+
p.dataset.jfiAxis = s.FlipX ? "x" : "y";
|
|
119
|
+
p.dataset.jfiEffect = s.Effect;
|
|
120
|
+
p.dataset.jfiMotion = s.ReducedMotion === false ? "allow" : "respect";
|
|
121
|
+
for (const item of s.Style || []) {
|
|
122
|
+
const targets = item.el === "self" ? [p] : p.querySelectorAll(item.el);
|
|
123
|
+
targets.forEach((node) => Object.assign(node.style, item.style));
|
|
124
|
+
}
|
|
125
|
+
if (s.Tilt !== "only" && !p.hasAttribute("tabindex")) p.tabIndex = 0;
|
|
126
|
+
}
|
|
127
|
+
events() {
|
|
128
|
+
this.listen("click", (event) => {
|
|
129
|
+
if (this.settings.Tilt === "only") return;
|
|
130
|
+
const trigger = this.settings.Click;
|
|
131
|
+
if (trigger === true || trigger && [].concat(trigger).some((selector) => event.target.closest?.(selector) && this.hoverPanel.contains(event.target.closest(selector)))) this.toggle();
|
|
132
|
+
});
|
|
133
|
+
this.listen("keydown", (event) => {
|
|
134
|
+
if (event.target !== this.hoverPanel || this.settings.Tilt === "only") return;
|
|
135
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
this.toggle();
|
|
138
|
+
}
|
|
139
|
+
if (event.key === "Escape") this.flip(false);
|
|
140
|
+
});
|
|
141
|
+
this.listen("pointerenter", (event) => {
|
|
142
|
+
if (!this.settings.Click && this.settings.Tilt !== "only" && event.pointerType !== "touch") this.flip(true);
|
|
143
|
+
});
|
|
144
|
+
this.listen("pointerleave", (event) => {
|
|
145
|
+
if (event.pointerType === "touch") return;
|
|
146
|
+
this.resetTilt();
|
|
147
|
+
if (!this.settings.Click && this.settings.Tilt !== "only") this.flip(false);
|
|
148
|
+
});
|
|
149
|
+
this.listen("pointerdown", (event) => {
|
|
150
|
+
if (event.pointerType !== "touch" || event.isPrimary === false || this.touch) return;
|
|
151
|
+
this.resetTilt();
|
|
152
|
+
this.touch = { id: event.pointerId, x: event.clientX, y: event.clientY, moved: false };
|
|
153
|
+
this.queueTilt(event, this.touch);
|
|
154
|
+
}, { passive: true });
|
|
155
|
+
this.listen("pointermove", (event) => {
|
|
156
|
+
if (event.pointerType !== "touch") {
|
|
157
|
+
if (!this.touch) this.queueTilt(event);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const touch = this.touch;
|
|
161
|
+
if (!touch || touch.id !== event.pointerId) return;
|
|
162
|
+
touch.moved || (touch.moved = this.touchMoved(event, touch));
|
|
163
|
+
this.queueTilt(event, touch);
|
|
164
|
+
}, { passive: true });
|
|
165
|
+
this.listen("pointerup", (event) => {
|
|
166
|
+
const touch = this.finishTouch(event);
|
|
167
|
+
if (!touch || touch.moved || this.touchMoved(event, touch)) return;
|
|
168
|
+
if (!this.settings.Click && this.settings.Tilt !== "only") this.toggle();
|
|
169
|
+
});
|
|
170
|
+
this.listen("pointercancel", (event) => {
|
|
171
|
+
if (event.pointerType === "touch") this.finishTouch(event);
|
|
172
|
+
else this.resetTilt();
|
|
173
|
+
});
|
|
174
|
+
this.listen("lostpointercapture", (event) => this.finishTouch(event));
|
|
175
|
+
this.baseTransform = this.hoverPanel.style.transform;
|
|
176
|
+
}
|
|
177
|
+
touchMoved(event, touch) {
|
|
178
|
+
return Math.hypot(event.clientX - touch.x, event.clientY - touch.y) > 10;
|
|
179
|
+
}
|
|
180
|
+
finishTouch(event) {
|
|
181
|
+
const touch = this.touch;
|
|
182
|
+
if (event.pointerType !== "touch" || !touch || touch.id !== event.pointerId) return;
|
|
183
|
+
this.touch = null;
|
|
184
|
+
this.resetTilt();
|
|
185
|
+
return touch;
|
|
186
|
+
}
|
|
187
|
+
queueTilt(event, touch) {
|
|
188
|
+
if (!this.settings.Tilt || this.reduced) return;
|
|
189
|
+
this.point = [event.clientX, event.clientY];
|
|
190
|
+
if (this.frame) return;
|
|
191
|
+
this.frame = this.win.requestAnimationFrame(() => {
|
|
192
|
+
this.frame = 0;
|
|
193
|
+
const rect = touch ? touch.rect ?? (touch.rect = this.hoverPanel.getBoundingClientRect()) : this.hoverPanel.getBoundingClientRect();
|
|
194
|
+
if (!rect.width || !rect.height) return;
|
|
195
|
+
const { max = 10, perspective = 1e3, scale = 1.03 } = this.settings.Tilt;
|
|
196
|
+
const x = Math.max(-1, Math.min(1, (this.point[0] - rect.left) / rect.width * 2 - 1));
|
|
197
|
+
const y = Math.max(-1, Math.min(1, (this.point[1] - rect.top) / rect.height * 2 - 1));
|
|
198
|
+
this.hoverPanel.style.transform = `perspective(${perspective}px) rotateX(${-y * max}deg) rotateY(${x * max}deg) scale(${scale})`;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
resetTilt() {
|
|
202
|
+
if (this.frame) this.win.cancelAnimationFrame(this.frame);
|
|
203
|
+
this.frame = 0;
|
|
204
|
+
this.hoverPanel.style.transform = this.baseTransform || "";
|
|
205
|
+
}
|
|
206
|
+
render() {
|
|
207
|
+
this.hoverPanel.dataset.jfiFlipped = String(this.flipped);
|
|
208
|
+
this.hoverPanel.dataset.jfiReduced = String(this.reduced);
|
|
209
|
+
for (const [node, hidden] of [[this.frontWrapper, this.flipped], [this.backWrapper, !this.flipped]]) {
|
|
210
|
+
node.setAttribute("aria-hidden", String(hidden));
|
|
211
|
+
node.inert = hidden;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
flip(value = true) {
|
|
215
|
+
if (this.destroyed || this.flipped === !!value) return this;
|
|
216
|
+
const active = this.element.ownerDocument.activeElement;
|
|
217
|
+
if ((value ? this.frontWrapper : this.backWrapper).contains(active)) this.hoverPanel.focus({ preventScroll: true });
|
|
218
|
+
this.flipped = !!value;
|
|
219
|
+
this.render();
|
|
220
|
+
this.hoverPanel.dispatchEvent(new this.win.CustomEvent("justflipit:change", { bubbles: true, detail: this.getState() }));
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
toggle() {
|
|
224
|
+
return this.flip(!this.flipped);
|
|
225
|
+
}
|
|
226
|
+
update(options = {}) {
|
|
227
|
+
if (this.destroyed) return this;
|
|
228
|
+
if ("Faces" in options) throw new TypeError("Faces cannot change after initialization");
|
|
229
|
+
validate(options);
|
|
230
|
+
if (this.managed && "Template" in options) throw new TypeError("Render framework face content with the framework");
|
|
231
|
+
this.settings = { ...this.settings, ...options };
|
|
232
|
+
if ("Template" in options) {
|
|
233
|
+
if (this.managed) throw new TypeError("Render framework face content with the framework");
|
|
234
|
+
this.backWrapper.innerHTML = options.Template;
|
|
235
|
+
}
|
|
236
|
+
this.resetTilt();
|
|
237
|
+
this.configure();
|
|
238
|
+
this.render();
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
getState() {
|
|
242
|
+
return { flipped: this.flipped, destroyed: this.destroyed, effect: this.settings.Effect };
|
|
243
|
+
}
|
|
244
|
+
destroy() {
|
|
245
|
+
if (this.destroyed) return;
|
|
246
|
+
this.resetTilt();
|
|
247
|
+
this.cleanups.forEach((fn) => fn());
|
|
248
|
+
this.restores.forEach((fn) => fn());
|
|
249
|
+
if (!this.managed) {
|
|
250
|
+
this.hoverPanel.replaceWith(this.element);
|
|
251
|
+
}
|
|
252
|
+
instances.delete(this.element);
|
|
253
|
+
instances.delete(this.hoverPanel);
|
|
254
|
+
this.destroyed = true;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
function elements(target) {
|
|
258
|
+
if (typeof target === "string") return typeof document === "undefined" ? [] : Array.from(document.querySelectorAll(target));
|
|
259
|
+
if (target?.nodeType === 1) return [target];
|
|
260
|
+
return target ? Array.from(target) : [];
|
|
261
|
+
}
|
|
262
|
+
function justFlipIt(target, options) {
|
|
263
|
+
const result = elements(target).map((element) => instances.get(element) || new FlipController(element, options));
|
|
264
|
+
return target?.nodeType === 1 ? result[0] : result;
|
|
265
|
+
}
|
|
266
|
+
justFlipIt.destroy = (target) => elements(target).forEach((element) => instances.get(element)?.destroy());
|
|
267
|
+
justFlipIt.get = (element) => instances.get(element);
|
|
268
|
+
export {
|
|
269
|
+
FlipController,
|
|
270
|
+
justFlipIt as default
|
|
271
|
+
};
|
|
272
|
+
//# sourceMappingURL=justFlipIt.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/core.js"],
|
|
4
|
+
"sourcesContent": ["const instances = new WeakMap();\nconst defaults = { Click: false, FlipX: false, Duration: 400, Easing: 'cubic-bezier(.22,.61,.36,1)', Tilt: false, Effect: 'flip', ReducedMotion: true, preserveClasses: true, preserveStyles: true, Style: [] };\nconst css = `\n._justFlipIt_panel{position:relative;display:grid;perspective:var(--jfi-perspective,1000px);isolation:isolate}\n._justFlipIt_panel>[data-jfi-face]{grid-area:1/1;min-width:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;transition:transform var(--jfi-duration) var(--jfi-easing),opacity var(--jfi-duration) var(--jfi-easing);transform-origin:center}\n._justFlipIt_panel>[data-jfi-face=back],._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=front]{pointer-events:none}\n._justFlipIt_panel[data-jfi-flipped=true]>[data-jfi-face=back]{pointer-events:auto}\n._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=front]{transform:rotateY(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip]>[data-jfi-face=back]{transform:rotateY(-180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateY(180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateY(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=front]{transform:rotateX(0deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x]>[data-jfi-face=back]{transform:rotateX(-180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=front]{transform:rotateX(180deg)}\n._justFlipIt_panel[data-jfi-effect=flip][data-jfi-axis=x][data-jfi-flipped=true]>[data-jfi-face=back]{transform:rotateX(0deg)}\n._justFlipIt_panel[data-jfi-effect=fade]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back]{opacity:0}\n._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=front],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{opacity:0}\n._justFlipIt_panel[data-jfi-effect=fade][data-jfi-flipped=true]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{opacity:1}\n._justFlipIt_panel[data-jfi-effect=scale]>[data-jfi-face=back],._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=front]{transform:scale(.94)}\n._justFlipIt_panel[data-jfi-effect=scale][data-jfi-flipped=true]>[data-jfi-face=back]{transform:scale(1)}\n._justFlipIt_panel[data-jfi-reduced=true]>[data-jfi-face]{transition:none!important}\n@media(prefers-reduced-motion:reduce){._justFlipIt_panel:not([data-jfi-motion=allow])>[data-jfi-face]{transition:none!important}}\n`;\nfunction styles(doc) {\n if (doc.querySelector('style[data-justflipitstyle=\"v4\"]')) return;\n const style = doc.createElement('style');\n style.dataset.justflipitstyle = 'v4'; style.textContent = css; doc.head.append(style);\n}\nfunction validate(options) {\n if (options.Duration !== undefined && (!Number.isFinite(options.Duration) || options.Duration < 0)) throw new TypeError('Duration must be a non-negative finite number');\n if (options.Effect !== undefined && !['flip', 'fade', 'scale'].includes(options.Effect)) throw new TypeError('Unknown Effect');\n if (options.Tilt && typeof options.Tilt === 'object') {\n for (const key of ['max', 'perspective', 'scale']) {\n if (options.Tilt[key] !== undefined && (!Number.isFinite(options.Tilt[key]) || options.Tilt[key] < 0)) throw new TypeError(`Invalid Tilt.${key}`);\n }\n }\n}\nexport class FlipController {\n constructor(element, options = {}) {\n validate(options);\n if (!element || element.nodeType !== 1) throw new TypeError('Expected an HTML element');\n this.element = element; this.settings = { ...defaults, ...options }; this.flipped = false; this.destroyed = false;\n this.cleanups = []; this.restores = []; this.win = element.ownerDocument.defaultView;\n const doc = element.ownerDocument; styles(doc);\n this.managed = !!options.Faces;\n if (this.managed) {\n this.hoverPanel = element;\n this.frontWrapper = element.querySelector(options.Faces.front);\n this.backWrapper = element.querySelector(options.Faces.back);\n if (!this.frontWrapper || !this.backWrapper || this.frontWrapper === this.backWrapper || this.frontWrapper.parentNode !== element || this.backWrapper.parentNode !== element) throw new TypeError('Faces must select two distinct direct children');\n } else {\n if (!element.parentNode) throw new TypeError('Element must have a parent');\n this.hoverPanel = doc.createElement('div');\n this.frontWrapper = doc.createElement('div'); this.backWrapper = doc.createElement('div');\n if (this.settings.preserveClasses) this.hoverPanel.className = element.className;\n if (this.settings.preserveStyles) this.hoverPanel.style.cssText = element.style.cssText;\n element.before(this.hoverPanel); this.hoverPanel.append(this.frontWrapper, this.backWrapper);\n this.frontWrapper.append(element);\n if (options.Template !== undefined) this.backWrapper.innerHTML = options.Template;\n else {\n const clone = element.cloneNode(true);\n clone.removeAttribute('id'); clone.querySelectorAll('[id]').forEach(node => node.removeAttribute('id'));\n this.backWrapper.append(clone);\n }\n }\n const panel = this.hoverPanel;\n for (const node of [panel, this.frontWrapper, this.backWrapper]) {\n const owned = node === panel ? ['class', 'style', 'tabindex', 'data-jfi-axis', 'data-jfi-effect', 'data-jfi-motion', 'data-jfi-flipped', 'data-jfi-reduced'] : ['style', 'data-jfi-face', 'aria-hidden', 'inert'];\n const attrs = owned.map(name => [name, node.getAttribute(name)]);\n const inert = node.inert || false;\n this.restores.push(() => { node.inert = inert; for (const [name, value] of attrs) { if (value === null) node.removeAttribute(name); else node.setAttribute(name, value); } });\n }\n panel.classList.add('_justFlipIt_panel');\n this.frontWrapper.dataset.jfiFace = 'front'; this.backWrapper.dataset.jfiFace = 'back';\n this.motion = this.win.matchMedia?.('(prefers-reduced-motion: reduce)');\n const motionChange = () => { this.resetTilt(); this.render(); };\n this.motion?.addEventListener('change', motionChange);\n this.cleanups.push(() => this.motion?.removeEventListener('change', motionChange));\n this.configure(); this.events(); this.render();\n instances.set(element, this); instances.set(panel, this);\n }\n listen(type, handler, options) { this.hoverPanel.addEventListener(type, handler, options); this.cleanups.push(() => this.hoverPanel.removeEventListener(type, handler, options)); }\n get reduced() { return this.settings.ReducedMotion !== false && !!this.motion?.matches; }\n configure() {\n const s = this.settings, p = this.hoverPanel;\n p.style.setProperty('--jfi-duration', `${s.Duration}ms`); p.style.setProperty('--jfi-easing', s.Easing);\n p.dataset.jfiAxis = s.FlipX ? 'x' : 'y'; p.dataset.jfiEffect = s.Effect;\n p.dataset.jfiMotion = s.ReducedMotion === false ? 'allow' : 'respect';\n for (const item of s.Style || []) {\n const targets = item.el === 'self' ? [p] : p.querySelectorAll(item.el);\n targets.forEach(node => Object.assign(node.style, item.style));\n }\n // A generic keyboard focus target avoids button roles around interactive children.\n if (s.Tilt !== 'only' && !p.hasAttribute('tabindex')) p.tabIndex = 0;\n }\n events() {\n this.listen('click', event => {\n if (this.settings.Tilt === 'only') return;\n const trigger = this.settings.Click;\n if (trigger === true || (trigger && [].concat(trigger).some(selector => event.target.closest?.(selector) && this.hoverPanel.contains(event.target.closest(selector))))) this.toggle();\n });\n this.listen('keydown', event => {\n if (event.target !== this.hoverPanel || this.settings.Tilt === 'only') return;\n if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); this.toggle(); }\n if (event.key === 'Escape') this.flip(false);\n });\n this.listen('pointerenter', event => { if (!this.settings.Click && this.settings.Tilt !== 'only' && event.pointerType !== 'touch') this.flip(true); });\n this.listen('pointerleave', event => {\n // Touch release also emits pointerleave. The tap must survive it.\n if (event.pointerType === 'touch') return;\n this.resetTilt();\n if (!this.settings.Click && this.settings.Tilt !== 'only') this.flip(false);\n });\n this.listen('pointerdown', event => {\n if (event.pointerType !== 'touch' || event.isPrimary === false || this.touch) return;\n this.resetTilt();\n this.touch = { id: event.pointerId, x: event.clientX, y: event.clientY, moved: false };\n this.queueTilt(event, this.touch);\n }, { passive: true });\n this.listen('pointermove', event => {\n if (event.pointerType !== 'touch') {\n if (!this.touch) this.queueTilt(event);\n return;\n }\n const touch = this.touch;\n if (!touch || touch.id !== event.pointerId) return;\n touch.moved ||= this.touchMoved(event, touch);\n this.queueTilt(event, touch);\n }, { passive: true });\n this.listen('pointerup', event => {\n const touch = this.finishTouch(event);\n if (!touch || touch.moved || this.touchMoved(event, touch)) return;\n // Explicit click triggers continue to use the browser's click event.\n if (!this.settings.Click && this.settings.Tilt !== 'only') this.toggle();\n });\n this.listen('pointercancel', event => {\n if (event.pointerType === 'touch') this.finishTouch(event);\n else this.resetTilt();\n });\n this.listen('lostpointercapture', event => this.finishTouch(event));\n this.baseTransform = this.hoverPanel.style.transform;\n }\n touchMoved(event, touch) {\n return Math.hypot(event.clientX - touch.x, event.clientY - touch.y) > 10;\n }\n finishTouch(event) {\n const touch = this.touch;\n if (event.pointerType !== 'touch' || !touch || touch.id !== event.pointerId) return;\n this.touch = null;\n this.resetTilt();\n return touch;\n }\n queueTilt(event, touch) {\n if (!this.settings.Tilt || this.reduced) return;\n this.point = [event.clientX, event.clientY];\n if (this.frame) return;\n this.frame = this.win.requestAnimationFrame(() => {\n this.frame = 0;\n // Keep the touch reference box stable as the panel rotates.\n const rect = touch\n ? (touch.rect ??= this.hoverPanel.getBoundingClientRect())\n : this.hoverPanel.getBoundingClientRect();\n if (!rect.width || !rect.height) return;\n const { max = 10, perspective = 1000, scale = 1.03 } = this.settings.Tilt;\n const x = Math.max(-1, Math.min(1, (this.point[0] - rect.left) / rect.width * 2 - 1));\n const y = Math.max(-1, Math.min(1, (this.point[1] - rect.top) / rect.height * 2 - 1));\n this.hoverPanel.style.transform = `perspective(${perspective}px) rotateX(${-y * max}deg) rotateY(${x * max}deg) scale(${scale})`;\n });\n }\n resetTilt() { if (this.frame) this.win.cancelAnimationFrame(this.frame); this.frame = 0; this.hoverPanel.style.transform = this.baseTransform || ''; }\n render() {\n this.hoverPanel.dataset.jfiFlipped = String(this.flipped); this.hoverPanel.dataset.jfiReduced = String(this.reduced);\n for (const [node, hidden] of [[this.frontWrapper, this.flipped], [this.backWrapper, !this.flipped]]) { node.setAttribute('aria-hidden', String(hidden)); node.inert = hidden; }\n }\n flip(value = true) {\n if (this.destroyed || this.flipped === !!value) return this;\n const active = this.element.ownerDocument.activeElement;\n if ((value ? this.frontWrapper : this.backWrapper).contains(active)) this.hoverPanel.focus({ preventScroll: true });\n this.flipped = !!value; this.render();\n this.hoverPanel.dispatchEvent(new this.win.CustomEvent('justflipit:change', { bubbles: true, detail: this.getState() }));\n return this;\n }\n toggle() { return this.flip(!this.flipped); }\n update(options = {}) {\n if (this.destroyed) return this;\n if ('Faces' in options) throw new TypeError('Faces cannot change after initialization');\n validate(options);\n if (this.managed && 'Template' in options) throw new TypeError('Render framework face content with the framework');\n this.settings = { ...this.settings, ...options };\n if ('Template' in options) {\n if (this.managed) throw new TypeError('Render framework face content with the framework');\n this.backWrapper.innerHTML = options.Template;\n }\n this.resetTilt(); this.configure(); this.render(); return this;\n }\n getState() { return { flipped: this.flipped, destroyed: this.destroyed, effect: this.settings.Effect }; }\n destroy() {\n if (this.destroyed) return;\n this.resetTilt(); this.cleanups.forEach(fn => fn());\n this.restores.forEach(fn => fn());\n if (!this.managed) { this.hoverPanel.replaceWith(this.element); }\n instances.delete(this.element); instances.delete(this.hoverPanel); this.destroyed = true;\n }\n}\nfunction elements(target) {\n if (typeof target === 'string') return typeof document === 'undefined' ? [] : Array.from(document.querySelectorAll(target));\n if (target?.nodeType === 1) return [target];\n return target ? Array.from(target) : [];\n}\nexport default function justFlipIt(target, options) {\n const result = elements(target).map(element => instances.get(element) || new FlipController(element, options));\n return target?.nodeType === 1 ? result[0] : result;\n}\njustFlipIt.destroy = target => elements(target).forEach(element => instances.get(element)?.destroy());\njustFlipIt.get = element => instances.get(element);\n"],
|
|
5
|
+
"mappings": ";AAAA,IAAM,YAAY,oBAAI,QAAQ;AAC9B,IAAM,WAAW,EAAE,OAAO,OAAO,OAAO,OAAO,UAAU,KAAK,QAAQ,+BAA+B,MAAM,OAAO,QAAQ,QAAQ,eAAe,MAAM,iBAAiB,MAAM,gBAAgB,MAAM,OAAO,CAAC,EAAE;AAC9M,IAAM,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBZ,SAAS,OAAO,KAAK;AACn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,SAAS,QAAQ,QAAM,GAAG,CAAC;AAClD,SAAK,SAAS,QAAQ,QAAM,GAAG,CAAC;AAChC,QAAI,CAAC,KAAK,SAAS;AAAE,WAAK,WAAW,YAAY,KAAK,OAAO;AAAA,IAAG;AAChE,cAAU,OAAO,KAAK,OAAO;AAAG,cAAU,OAAO,KAAK,UAAU;AAAG,SAAK,YAAY;AAAA,EACtF;AACF;AACA,SAAS,SAAS,QAAQ;AACxB,MAAI,OAAO,WAAW,SAAU,QAAO,OAAO,aAAa,cAAc,CAAC,IAAI,MAAM,KAAK,SAAS,iBAAiB,MAAM,CAAC;AAC1H,MAAI,QAAQ,aAAa,EAAG,QAAO,CAAC,MAAM;AAC1C,SAAO,SAAS,MAAM,KAAK,MAAM,IAAI,CAAC;AACxC;AACe,SAAR,WAA4B,QAAQ,SAAS;AAClD,QAAM,SAAS,SAAS,MAAM,EAAE,IAAI,aAAW,UAAU,IAAI,OAAO,KAAK,IAAI,eAAe,SAAS,OAAO,CAAC;AAC7G,SAAO,QAAQ,aAAa,IAAI,OAAO,CAAC,IAAI;AAC9C;AACA,WAAW,UAAU,YAAU,SAAS,MAAM,EAAE,QAAQ,aAAW,UAAU,IAAI,OAAO,GAAG,QAAQ,CAAC;AACpG,WAAW,MAAM,aAAW,UAAU,IAAI,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/adapters/react.js
|
|
30
|
+
var react_exports = {};
|
|
31
|
+
__export(react_exports, {
|
|
32
|
+
useFlip: () => useFlip
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(react_exports);
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_justflipit = __toESM(require("@simhub2/justflipit"));
|
|
37
|
+
var faces = { front: "[data-flip-front]", back: "[data-flip-back]" };
|
|
38
|
+
function useFlip(options = {}) {
|
|
39
|
+
const ref = (0, import_react.useRef)(null), controller = (0, import_react.useRef)(null);
|
|
40
|
+
(0, import_react.useEffect)(() => {
|
|
41
|
+
if (!ref.current) return;
|
|
42
|
+
const instance = (0, import_justflipit.default)(ref.current, { ...options, Faces: options.Faces || faces });
|
|
43
|
+
controller.current = instance;
|
|
44
|
+
return () => {
|
|
45
|
+
instance.destroy();
|
|
46
|
+
controller.current = null;
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
(0, import_react.useEffect)(() => {
|
|
50
|
+
const { Faces, ...settings } = options;
|
|
51
|
+
controller.current?.update(settings);
|
|
52
|
+
}, [options]);
|
|
53
|
+
return { ref, controller };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/adapters/react.js"],
|
|
4
|
+
"sourcesContent": ["import { useEffect, useRef } from 'react';\nimport justFlipIt from '@simhub2/justflipit';\nconst faces = { front: '[data-flip-front]', back: '[data-flip-back]' };\nexport function useFlip(options = {}) {\n const ref = useRef(null), controller = useRef(null);\n useEffect(() => {\n if (!ref.current) return;\n const instance = justFlipIt(ref.current, { ...options, Faces: options.Faces || faces });\n controller.current = instance;\n return () => { instance.destroy(); controller.current = null; };\n }, []);\n useEffect(() => { const { Faces, ...settings } = options; controller.current?.update(settings); }, [options]);\n return { ref, controller };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AAClC,wBAAuB;AACvB,IAAM,QAAQ,EAAE,OAAO,qBAAqB,MAAM,mBAAmB;AAC9D,SAAS,QAAQ,UAAU,CAAC,GAAG;AACpC,QAAM,UAAM,qBAAO,IAAI,GAAG,iBAAa,qBAAO,IAAI;AAClD,8BAAU,MAAM;AACd,QAAI,CAAC,IAAI,QAAS;AAClB,UAAM,eAAW,kBAAAA,SAAW,IAAI,SAAS,EAAE,GAAG,SAAS,OAAO,QAAQ,SAAS,MAAM,CAAC;AACtF,eAAW,UAAU;AACrB,WAAO,MAAM;AAAE,eAAS,QAAQ;AAAG,iBAAW,UAAU;AAAA,IAAM;AAAA,EAChE,GAAG,CAAC,CAAC;AACL,8BAAU,MAAM;AAAE,UAAM,EAAE,OAAO,GAAG,SAAS,IAAI;AAAS,eAAW,SAAS,OAAO,QAAQ;AAAA,EAAG,GAAG,CAAC,OAAO,CAAC;AAC5G,SAAO,EAAE,KAAK,WAAW;AAC3B;",
|
|
6
|
+
"names": ["justFlipIt"]
|
|
7
|
+
}
|
package/dist/react.d.cts
ADDED
package/dist/react.d.mts
ADDED
package/dist/react.d.ts
ADDED