img-comparison-slider
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -16,2 +16,6 @@ 'use strict'; | ||
}; | ||
const KeySlideOffset = { | ||
'ArrowLeft': -1, | ||
'ArrowRight': 1, | ||
}; | ||
class ImgComparisonSlider { | ||
@@ -34,11 +38,20 @@ constructor(hostRef) { | ||
onKeyDown(e) { | ||
if (e.key === 'ArrowLeft') { | ||
this.slide(-1); | ||
if (this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
if (e.key === 'ArrowRight') { | ||
this.slide(1); | ||
const key = e.key; | ||
if (!Object.keys(KeySlideOffset).includes(key)) { | ||
return; | ||
} | ||
this.startSlideAnimation(KeySlideOffset[key]); | ||
} | ||
onKeyUp(e) { | ||
if (!this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
if (!Object.keys(KeySlideOffset).includes(e.key)) { | ||
return; | ||
} | ||
this.stopSlideAnimation(); | ||
} | ||
onMouseDown(e) { | ||
@@ -56,2 +69,5 @@ this.isMouseDown = true; | ||
} | ||
onBlur() { | ||
this.stopSlideAnimation(); | ||
} | ||
updateAfterWidth() { | ||
@@ -66,2 +82,22 @@ this.imageWidth = this.el.offsetWidth; | ||
} | ||
startSlideAnimation(offset) { | ||
const fps = 120; | ||
const fraction = 1 * offset; | ||
const slide = () => { | ||
this.keyboardSlideAnimationTimeoutId = window.setTimeout(() => { | ||
this.animationRequestId = window.requestAnimationFrame(slide); | ||
}, 1000 / fps); | ||
this.slide(fraction); | ||
}; | ||
slide(); | ||
} | ||
stopSlideAnimation() { | ||
if (!this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
window.clearTimeout(this.keyboardSlideAnimationTimeoutId); | ||
window.cancelAnimationFrame(this.animationRequestId); | ||
this.keyboardSlideAnimationTimeoutId = null; | ||
this.animationRequestId = null; | ||
} | ||
render() { | ||
@@ -68,0 +104,0 @@ return __chunk_1.h("div", null, __chunk_1.h("div", { ref: el => this.before = el }, __chunk_1.h("slot", { name: "before" })), __chunk_1.h("div", { class: "after", ref: el => this.after = el }, __chunk_1.h("div", { ref: el => this.afterImageContainer = el }, __chunk_1.h("slot", { name: "after" }))), __chunk_1.h("div", { class: "hint", ref: el => this.hint = el })); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
__chunk_1.patchBrowser().then(resourcesUrl => { | ||
return __chunk_1.bootstrapLazy([["img-comparison-slider.cjs",[[1,"img-comparison-slider",null,[[0,"keydown","onKeyDown"],[1,"touchstart","onMouseDown"],[1,"mousedown","onMouseDown"],[1,"touchend","onMouseUp"],[9,"mouseup","onMouseUp"],[1,"mousemove","onMouseMove"],[1,"touchmove","onMouseMove"],[9,"resize","updateAfterWidth"]]]]]], { resourcesUrl }); | ||
return __chunk_1.bootstrapLazy([["img-comparison-slider.cjs",[[1,"img-comparison-slider",null,[[0,"keydown","onKeyDown"],[0,"keyup","onKeyUp"],[1,"touchstart","onMouseDown"],[1,"mousedown","onMouseDown"],[1,"touchend","onMouseUp"],[9,"mouseup","onMouseUp"],[1,"mousemove","onMouseMove"],[1,"touchmove","onMouseMove"],[0,"blur","onBlur"],[9,"resize","updateAfterWidth"]]]]]], { resourcesUrl }); | ||
}); |
@@ -9,3 +9,3 @@ 'use strict'; | ||
return __chunk_1.patchEsm().then(() => { | ||
__chunk_1.bootstrapLazy([["img-comparison-slider.cjs",[[1,"img-comparison-slider",null,[[0,"keydown","onKeyDown"],[1,"touchstart","onMouseDown"],[1,"mousedown","onMouseDown"],[1,"touchend","onMouseUp"],[9,"mouseup","onMouseUp"],[1,"mousemove","onMouseMove"],[1,"touchmove","onMouseMove"],[9,"resize","updateAfterWidth"]]]]]], options); | ||
__chunk_1.bootstrapLazy([["img-comparison-slider.cjs",[[1,"img-comparison-slider",null,[[0,"keydown","onKeyDown"],[0,"keyup","onKeyUp"],[1,"touchstart","onMouseDown"],[1,"mousedown","onMouseDown"],[1,"touchend","onMouseUp"],[9,"mouseup","onMouseUp"],[1,"mousemove","onMouseMove"],[1,"touchmove","onMouseMove"],[0,"blur","onBlur"],[9,"resize","updateAfterWidth"]]]]]], options); | ||
}); | ||
@@ -12,0 +12,0 @@ }; |
@@ -11,2 +11,6 @@ import { h } from '@stencil/core'; | ||
}; | ||
const KeySlideOffset = { | ||
'ArrowLeft': -1, | ||
'ArrowRight': 1, | ||
}; | ||
export class ImgComparisonSlider { | ||
@@ -28,11 +32,20 @@ constructor() { | ||
onKeyDown(e) { | ||
if (e.key === 'ArrowLeft') { | ||
this.slide(-1); | ||
if (this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
if (e.key === 'ArrowRight') { | ||
this.slide(1); | ||
const key = e.key; | ||
if (!Object.keys(KeySlideOffset).includes(key)) { | ||
return; | ||
} | ||
this.startSlideAnimation(KeySlideOffset[key]); | ||
} | ||
onKeyUp(e) { | ||
if (!this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
if (!Object.keys(KeySlideOffset).includes(e.key)) { | ||
return; | ||
} | ||
this.stopSlideAnimation(); | ||
} | ||
onMouseDown(e) { | ||
@@ -50,2 +63,5 @@ this.isMouseDown = true; | ||
} | ||
onBlur() { | ||
this.stopSlideAnimation(); | ||
} | ||
updateAfterWidth() { | ||
@@ -60,2 +76,22 @@ this.imageWidth = this.el.offsetWidth; | ||
} | ||
startSlideAnimation(offset) { | ||
const fps = 120; | ||
const fraction = 1 * offset; | ||
const slide = () => { | ||
this.keyboardSlideAnimationTimeoutId = window.setTimeout(() => { | ||
this.animationRequestId = window.requestAnimationFrame(slide); | ||
}, 1000 / fps); | ||
this.slide(fraction); | ||
}; | ||
slide(); | ||
} | ||
stopSlideAnimation() { | ||
if (!this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
window.clearTimeout(this.keyboardSlideAnimationTimeoutId); | ||
window.cancelAnimationFrame(this.animationRequestId); | ||
this.keyboardSlideAnimationTimeoutId = null; | ||
this.animationRequestId = null; | ||
} | ||
render() { | ||
@@ -86,2 +122,8 @@ return h("div", null, | ||
}, { | ||
"name": "keyup", | ||
"method": "onKeyUp", | ||
"target": undefined, | ||
"capture": false, | ||
"passive": false | ||
}, { | ||
"name": "touchstart", | ||
@@ -123,2 +165,8 @@ "method": "onMouseDown", | ||
}, { | ||
"name": "blur", | ||
"method": "onBlur", | ||
"target": undefined, | ||
"capture": false, | ||
"passive": false | ||
}, { | ||
"name": "resize", | ||
@@ -125,0 +173,0 @@ "method": "updateAfterWidth", |
@@ -12,2 +12,6 @@ import { r as registerInstance, h, g as getElement } from './chunk-a29885d4.js'; | ||
}; | ||
const KeySlideOffset = { | ||
'ArrowLeft': -1, | ||
'ArrowRight': 1, | ||
}; | ||
class ImgComparisonSlider { | ||
@@ -30,11 +34,20 @@ constructor(hostRef) { | ||
onKeyDown(e) { | ||
if (e.key === 'ArrowLeft') { | ||
this.slide(-1); | ||
if (this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
if (e.key === 'ArrowRight') { | ||
this.slide(1); | ||
const key = e.key; | ||
if (!Object.keys(KeySlideOffset).includes(key)) { | ||
return; | ||
} | ||
this.startSlideAnimation(KeySlideOffset[key]); | ||
} | ||
onKeyUp(e) { | ||
if (!this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
if (!Object.keys(KeySlideOffset).includes(e.key)) { | ||
return; | ||
} | ||
this.stopSlideAnimation(); | ||
} | ||
onMouseDown(e) { | ||
@@ -52,2 +65,5 @@ this.isMouseDown = true; | ||
} | ||
onBlur() { | ||
this.stopSlideAnimation(); | ||
} | ||
updateAfterWidth() { | ||
@@ -62,2 +78,22 @@ this.imageWidth = this.el.offsetWidth; | ||
} | ||
startSlideAnimation(offset) { | ||
const fps = 120; | ||
const fraction = 1 * offset; | ||
const slide = () => { | ||
this.keyboardSlideAnimationTimeoutId = window.setTimeout(() => { | ||
this.animationRequestId = window.requestAnimationFrame(slide); | ||
}, 1000 / fps); | ||
this.slide(fraction); | ||
}; | ||
slide(); | ||
} | ||
stopSlideAnimation() { | ||
if (!this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
window.clearTimeout(this.keyboardSlideAnimationTimeoutId); | ||
window.cancelAnimationFrame(this.animationRequestId); | ||
this.keyboardSlideAnimationTimeoutId = null; | ||
this.animationRequestId = null; | ||
} | ||
render() { | ||
@@ -64,0 +100,0 @@ return h("div", null, h("div", { ref: el => this.before = el }, h("slot", { name: "before" })), h("div", { class: "after", ref: el => this.after = el }, h("div", { ref: el => this.afterImageContainer = el }, h("slot", { name: "after" }))), h("div", { class: "hint", ref: el => this.hint = el })); |
@@ -11,2 +11,6 @@ import { r as registerInstance, h, g as getElement } from './chunk-a29885d4.js'; | ||
}; | ||
var KeySlideOffset = { | ||
'ArrowLeft': -1, | ||
'ArrowRight': 1, | ||
}; | ||
var ImgComparisonSlider = /** @class */ (function () { | ||
@@ -30,11 +34,20 @@ function ImgComparisonSlider(hostRef) { | ||
ImgComparisonSlider.prototype.onKeyDown = function (e) { | ||
if (e.key === 'ArrowLeft') { | ||
this.slide(-1); | ||
if (this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
if (e.key === 'ArrowRight') { | ||
this.slide(1); | ||
var key = e.key; | ||
if (!Object.keys(KeySlideOffset).includes(key)) { | ||
return; | ||
} | ||
this.startSlideAnimation(KeySlideOffset[key]); | ||
}; | ||
ImgComparisonSlider.prototype.onKeyUp = function (e) { | ||
if (!this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
if (!Object.keys(KeySlideOffset).includes(e.key)) { | ||
return; | ||
} | ||
this.stopSlideAnimation(); | ||
}; | ||
ImgComparisonSlider.prototype.onMouseDown = function (e) { | ||
@@ -52,2 +65,5 @@ this.isMouseDown = true; | ||
}; | ||
ImgComparisonSlider.prototype.onBlur = function () { | ||
this.stopSlideAnimation(); | ||
}; | ||
ImgComparisonSlider.prototype.updateAfterWidth = function () { | ||
@@ -62,2 +78,23 @@ this.imageWidth = this.el.offsetWidth; | ||
}; | ||
ImgComparisonSlider.prototype.startSlideAnimation = function (offset) { | ||
var _this = this; | ||
var fps = 120; | ||
var fraction = 1 * offset; | ||
var slide = function () { | ||
_this.keyboardSlideAnimationTimeoutId = window.setTimeout(function () { | ||
_this.animationRequestId = window.requestAnimationFrame(slide); | ||
}, 1000 / fps); | ||
_this.slide(fraction); | ||
}; | ||
slide(); | ||
}; | ||
ImgComparisonSlider.prototype.stopSlideAnimation = function () { | ||
if (!this.keyboardSlideAnimationTimeoutId) { | ||
return; | ||
} | ||
window.clearTimeout(this.keyboardSlideAnimationTimeoutId); | ||
window.cancelAnimationFrame(this.animationRequestId); | ||
this.keyboardSlideAnimationTimeoutId = null; | ||
this.animationRequestId = null; | ||
}; | ||
ImgComparisonSlider.prototype.render = function () { | ||
@@ -64,0 +101,0 @@ var _this = this; |
@@ -1,1 +0,1 @@ | ||
import{p as o,b as e}from"./p-13b0f39b.js";o().then(o=>e([["p-sqbnw0br",[[1,"img-comparison-slider",null,[[0,"keydown","onKeyDown"],[1,"touchstart","onMouseDown"],[1,"mousedown","onMouseDown"],[1,"touchend","onMouseUp"],[9,"mouseup","onMouseUp"],[1,"mousemove","onMouseMove"],[1,"touchmove","onMouseMove"],[9,"resize","updateAfterWidth"]]]]]],{resourcesUrl:o})); | ||
import{p as o,b as e}from"./p-13b0f39b.js";o().then(o=>e([["p-pnvlrzcn",[[1,"img-comparison-slider",null,[[0,"keydown","onKeyDown"],[0,"keyup","onKeyUp"],[1,"touchstart","onMouseDown"],[1,"mousedown","onMouseDown"],[1,"touchend","onMouseUp"],[9,"mouseup","onMouseUp"],[1,"mousemove","onMouseMove"],[1,"touchmove","onMouseMove"],[0,"blur","onBlur"],[9,"resize","updateAfterWidth"]]]]]],{resourcesUrl:o})); |
@@ -1,1 +0,1 @@ | ||
System.register(["./p-334f7fd6.system.js"],function(){"use strict";var e,o;return{setters:[function(n){e=n.p;o=n.b}],execute:function(){e().then(function(e){return o([["p-0e3gxf51.system",[[1,"img-comparison-slider",null,[[0,"keydown","onKeyDown"],[1,"touchstart","onMouseDown"],[1,"mousedown","onMouseDown"],[1,"touchend","onMouseUp"],[9,"mouseup","onMouseUp"],[1,"mousemove","onMouseMove"],[1,"touchmove","onMouseMove"],[9,"resize","updateAfterWidth"]]]]]],{resourcesUrl:e})})}}}); | ||
System.register(["./p-334f7fd6.system.js"],function(){"use strict";var e,o;return{setters:[function(n){e=n.p;o=n.b}],execute:function(){e().then(function(e){return o([["p-af4blkbo.system",[[1,"img-comparison-slider",null,[[0,"keydown","onKeyDown"],[0,"keyup","onKeyUp"],[1,"touchstart","onMouseDown"],[1,"mousedown","onMouseDown"],[1,"touchend","onMouseUp"],[9,"mouseup","onMouseUp"],[1,"mousemove","onMouseMove"],[1,"touchmove","onMouseMove"],[0,"blur","onBlur"],[9,"resize","updateAfterWidth"]]]]]],{resourcesUrl:e})})}}}); |
@@ -10,11 +10,17 @@ export declare class ImgComparisonSlider { | ||
private isMouseDown; | ||
private keyboardSlideAnimationTimeoutId; | ||
private animationRequestId; | ||
componentDidRender(): void; | ||
slide(increment?: number): void; | ||
onKeyDown(e: KeyboardEvent): void; | ||
onKeyUp(e: KeyboardEvent): void; | ||
onMouseDown(e: MouseEvent): void; | ||
onMouseUp(e: MouseEvent): void; | ||
onMouseMove(e: MouseEvent): void; | ||
onBlur(): void; | ||
updateAfterWidth(): void; | ||
slideToEvent(e: MouseEvent): void; | ||
private startSlideAnimation; | ||
private stopSlideAnimation; | ||
render(): any; | ||
} |
{ | ||
"name": "img-comparison-slider", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Stencil Component Starter", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# img-comparison-slider | ||
[![npm package](https://img.shields.io/npm/v/img-comparison-slider.svg)](https://www.npmjs.com/package/img-comparison-slider) | ||
[![Built With Stencil](https://img.shields.io/badge/-Built%20With%20Stencil-16161d.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLT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diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
844641
11021
136