@kvass/widgets 1.9.45 → 1.9.46

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.
@@ -1 +1 @@
1
- import{q as _,s as S,_ as k,b,e as E,o as L,w as T,a as f,v as g,t as x,m as M,p as D}from"./_plugin-vue_export-helper.js";(()=>{var v={792:(s,n,r)=>{r.d(n,{Z:()=>u});var a=r(609),d=r.n(a)()(function(l){return l[1]});d.push([s.id,':host{--divider-width: 1px;--divider-color: #fff;--divider-shadow: none;--default-handle-width: 50px;--default-handle-color: #fff;--default-handle-opacity: 1;--default-handle-shadow: none;--handle-position-start: 50%;position:relative;display:inline-block;overflow:hidden;line-height:0;direction:ltr}@media screen and (-webkit-min-device-pixel-ratio: 0)and (min-resolution: 0.001dpcm){:host{outline-offset:1px}}:host(:focus){outline:2px solid -webkit-focus-ring-color}::slotted(*){-webkit-user-drag:none;-khtml-user-drag:none;-moz-user-drag:none;-o-user-drag:none;user-drag:none;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.first{position:absolute;left:0;top:0;right:0;line-height:normal;font-size:100%;max-height:100%;height:100%;width:100%;--exposure: 50%;--keyboard-transition-time: 0ms;--default-transition-time: 0ms;--transition-time: var(--default-transition-time)}.first .first-overlay-container{position:relative;clip-path:inset(0 var(--exposure) 0 0);transition:clip-path var(--transition-time);height:100%}.first .first-overlay{overflow:hidden;height:100%}.first.focused{will-change:clip-path}.first.focused .first-overlay-container{will-change:clip-path}.second{position:relative}.handle-container{transform:translateX(50%);position:absolute;top:0;right:var(--exposure);height:100%;transition:right var(--transition-time),bottom var(--transition-time)}.focused .handle-container{will-change:right}.divider{position:absolute;height:100%;width:100%;left:0;top:0;display:flex;align-items:center;justify-content:center;flex-direction:column}.divider:after{content:" ";display:block;height:100%;border-left-width:var(--divider-width);border-left-style:solid;border-left-color:var(--divider-color);box-shadow:var(--divider-shadow)}.handle{position:absolute;top:var(--handle-position-start);pointer-events:none;box-sizing:border-box;margin-left:1px;transform:translate(calc(-50% - 0.5px), -50%);line-height:0}.default-handle{width:var(--default-handle-width);opacity:var(--default-handle-opacity);transition:all 1s;filter:drop-shadow(var(--default-handle-shadow))}.default-handle path{stroke:var(--default-handle-color)}.vertical .first-overlay-container{clip-path:inset(0 0 var(--exposure) 0)}.vertical .handle-container{transform:translateY(50%);height:auto;top:unset;bottom:var(--exposure);width:100%;left:0;flex-direction:row}.vertical .divider:after{height:1px;width:100%;border-top-width:var(--divider-width);border-top-style:solid;border-top-color:var(--divider-color);border-left:0}.vertical .handle{top:auto;left:var(--handle-position-start);transform:translate(calc(-50% - 0.5px), -50%) rotate(90deg)}',""]);const u=d},609:s=>{s.exports=function(n){var r=[];return r.toString=function(){return this.map(function(a){var d=n(a);return a[2]?"@media ".concat(a[2]," {").concat(d,"}"):d}).join("")},r.i=function(a,d,u){typeof a=="string"&&(a=[[null,a,""]]);var l={};if(u)for(var h=0;h<this.length;h++){var w=this[h][0];w!=null&&(l[w]=!0)}for(var e=0;e<a.length;e++){var t=[].concat(a[e]);u&&l[t[0]]||(d&&(t[2]?t[2]="".concat(d," and ").concat(t[2]):t[2]=d),r.push(t))}},r}}},p={};function c(s){var n=p[s];if(n!==void 0)return n.exports;var r=p[s]={id:s,exports:{}};return v[s](r,r.exports,c),r.exports}c.n=s=>{var n=s&&s.__esModule?()=>s.default:()=>s;return c.d(n,{a:n}),n},c.d=(s,n)=>{for(var r in n)c.o(n,r)&&!c.o(s,r)&&Object.defineProperty(s,r,{enumerable:!0,get:n[r]})},c.o=(s,n)=>Object.prototype.hasOwnProperty.call(s,n),(()=>{var s=c(792);const n="rendered",r=(e,t)=>{const i=e.getBoundingClientRect();let o,m;return t.type==="mousedown"?(o=t.clientX,m=t.clientY):(o=t.touches[0].clientX,m=t.touches[0].clientY),o>=i.x&&o<=i.x+i.width&&m>=i.y&&m<=i.y+i.height};let a;const d={ArrowLeft:-1,ArrowRight:1},u=["horizontal","vertical"],l=e=>({x:e.touches[0].pageX,y:e.touches[0].pageY}),h=e=>({x:e.pageX,y:e.pageY}),w=typeof window<"u"&&window?.HTMLElement;typeof window<"u"&&(window.document&&(a=document.createElement("template"),a.innerHTML='<div class="second" id="second"> <slot name="second"><slot name="before"></slot></slot> </div> <div class="first" id="first"> <div class="first-overlay"> <div class="first-overlay-container" id="firstImageContainer"> <slot name="first"><slot name="after"></slot></slot> </div> </div> <div class="handle-container"> <div class="divider"></div> <div class="handle" id="handle"> <slot name="handle"> <svg xmlns="http://www.w3.org/2000/svg" class="default-handle" viewBox="-8 -3 16 6"> <path d="M -5 -2 L -7 0 L -5 2 M 5 -2 L 7 0 L 5 2" fill="none" vector-effect="non-scaling-stroke"/> </svg> </slot> </div> </div> </div> '),window.customElements.define("img-comparison-slider",class extends w{constructor(){super(),this.exposure=this.hasAttribute("value")?parseFloat(this.getAttribute("value")):50,this.slideOnHover=!1,this.slideDirection="horizontal",this.keyboard="enabled",this.isMouseDown=!1,this.animationDirection=0,this.isFocused=!1,this.dragByHandle=!1,this.onMouseMove=i=>{if(this.isMouseDown||this.slideOnHover){const o=h(i);this.slideToPage(o)}},this.bodyUserSelectStyle="",this.bodyWebkitUserSelectStyle="",this.onMouseDown=i=>{if(this.slideOnHover||this.handle&&!r(this.handleElement,i))return;i.preventDefault(),window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("mouseup",this.onWindowMouseUp),this.isMouseDown=!0,this.enableTransition();const o=h(i);this.slideToPage(o),this.focus(),this.bodyUserSelectStyle=window.document.body.style.userSelect,this.bodyWebkitUserSelectStyle=window.document.body.style.webkitUserSelect,window.document.body.style.userSelect="none",window.document.body.style.webkitUserSelect="none"},this.onWindowMouseUp=()=>{this.isMouseDown=!1,window.document.body.style.userSelect=this.bodyUserSelectStyle,window.document.body.style.webkitUserSelect=this.bodyWebkitUserSelectStyle,window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("mouseup",this.onWindowMouseUp)},this.touchStartPoint=null,this.isTouchComparing=!1,this.hasTouchMoved=!1,this.onTouchStart=i=>{this.dragByHandle&&!r(this.handleElement,i)||(this.touchStartPoint=l(i),this.isFocused&&(this.enableTransition(),this.slideToPage(this.touchStartPoint)))},this.onTouchMove=i=>{if(this.touchStartPoint===null)return;const o=l(i);if(this.isTouchComparing)return this.slideToPage(o),i.preventDefault(),!1;if(!this.hasTouchMoved){const m=Math.abs(o.y-this.touchStartPoint.y),y=Math.abs(o.x-this.touchStartPoint.x);if(this.slideDirection==="horizontal"&&m<y||this.slideDirection==="vertical"&&m>y)return this.isTouchComparing=!0,this.focus(),this.slideToPage(o),i.preventDefault(),!1;this.hasTouchMoved=!0}},this.onTouchEnd=()=>{this.isTouchComparing=!1,this.hasTouchMoved=!1,this.touchStartPoint=null},this.onBlur=()=>{this.stopSlideAnimation(),this.isFocused=!1,this.firstElement.classList.remove("focused")},this.onFocus=()=>{this.isFocused=!0,this.firstElement.classList.add("focused")},this.onKeyDown=i=>{if(this.keyboard==="disabled")return;const o=d[i.key];this.animationDirection!==o&&o!==void 0&&(this.animationDirection=o,this.startSlideAnimation())},this.onKeyUp=i=>{if(this.keyboard==="disabled")return;const o=d[i.key];o!==void 0&&this.animationDirection===o&&this.stopSlideAnimation()},this.resetDimensions=()=>{this.imageWidth=this.offsetWidth,this.imageHeight=this.offsetHeight};const e=this.attachShadow({mode:"open"}),t=document.createElement("style");t.innerHTML=s.Z,this.getAttribute("nonce")&&t.setAttribute("nonce",this.getAttribute("nonce")),e.appendChild(t),e.appendChild(a.content.cloneNode(!0)),this.firstElement=e.getElementById("first"),this.handleElement=e.getElementById("handle")}set handle(e){this.dragByHandle=e.toString().toLowerCase()!=="false"}get handle(){return this.dragByHandle}get value(){return this.exposure}set value(e){const t=parseFloat(e);t!==this.exposure&&(this.exposure=t,this.enableTransition(),this.setExposure())}get hover(){return this.slideOnHover}set hover(e){this.slideOnHover=e.toString().toLowerCase()!=="false",this.removeEventListener("mousemove",this.onMouseMove),this.slideOnHover&&this.addEventListener("mousemove",this.onMouseMove)}get direction(){return this.slideDirection}set direction(e){this.slideDirection=e.toString().toLowerCase(),this.slide(0),this.firstElement.classList.remove(...u),u.includes(this.slideDirection)&&this.firstElement.classList.add(this.slideDirection)}static get observedAttributes(){return["hover","direction"]}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.addEventListener("dragstart",e=>(e.preventDefault(),!1)),new ResizeObserver(this.resetDimensions).observe(this),this.setExposure(0),this.keyboard=this.hasAttribute("keyboard")&&this.getAttribute("keyboard")==="disabled"?"disabled":"enabled",this.addEventListener("keydown",this.onKeyDown),this.addEventListener("keyup",this.onKeyUp),this.addEventListener("focus",this.onFocus),this.addEventListener("blur",this.onBlur),this.addEventListener("touchstart",this.onTouchStart,{passive:!0}),this.addEventListener("touchmove",this.onTouchMove,{passive:!1}),this.addEventListener("touchend",this.onTouchEnd),this.addEventListener("mousedown",this.onMouseDown),this.handle=this.hasAttribute("handle")?this.getAttribute("handle"):this.dragByHandle,this.hover=this.hasAttribute("hover")?this.getAttribute("hover"):this.slideOnHover,this.direction=this.hasAttribute("direction")?this.getAttribute("direction"):this.slideDirection,this.resetDimensions(),this.classList.contains(n)||this.classList.add(n)}disconnectedCallback(){this.transitionTimer&&window.clearTimeout(this.transitionTimer)}attributeChangedCallback(e,t,i){e==="hover"&&(this.hover=i),e==="direction"&&(this.direction=i),e==="keyboard"&&(this.keyboard=i==="disabled"?"disabled":"enabled")}setExposure(e=0){var t;this.exposure=(t=this.exposure+e)<0?0:t>100?100:t,this.firstElement.style.setProperty("--exposure",100-this.exposure+"%")}slide(e=0){this.setExposure(e);const t=new Event("slide");this.dispatchEvent(t)}slideToPage(e){this.slideDirection==="horizontal"&&this.slideToPageX(e.x),this.slideDirection==="vertical"&&this.slideToPageY(e.y)}slideToPageX(e){const t=e-this.getBoundingClientRect().left-window.scrollX;this.exposure=t/this.imageWidth*100,this.slide(0)}slideToPageY(e){const t=e-this.getBoundingClientRect().top-window.scrollY;this.exposure=t/this.imageHeight*100,this.slide(0)}enableTransition(){this.firstElement.style.setProperty("--transition-time","100ms"),this.transitionTimer=window.setTimeout(()=>{this.firstElement.style.setProperty("--transition-time","var(--default-transition-time)"),this.transitionTimer=null},100)}startSlideAnimation(){let e=null,t=this.animationDirection;this.firstElement.style.setProperty("--transition-time","var(--keyboard-transition-time)");const i=o=>{if(this.animationDirection===0||t!==this.animationDirection)return;e===null&&(e=o);const m=(o-e)/16.666666666666668*this.animationDirection;this.slide(m),setTimeout(()=>window.requestAnimationFrame(i),0),e=o};window.requestAnimationFrame(i)}stopSlideAnimation(){this.animationDirection=0,this.firstElement.style.setProperty("--transition-time","var(--default-transition-time)")}}))})()})();const C=_({name:"ImgComparisonSlider",setup(v,{slots:p}){return()=>S("img-comparison-slider",p.default())}}),A=".img-comparison-slider{width:100%;height:100%;--divider-width: 4px;--divider-color: black}.img-comparison-slider__image{width:100%;height:100%;object-fit:cover}.img-comparison-slider .handle{display:flex;flex-direction:row;justify-content:center;align-items:center;flex-wrap:nowrap;gap:1rem;min-width:800px;font-size:1rem}@media (max-width: 600px){.img-comparison-slider .handle{font-size:.75rem}}.img-comparison-slider .handle__caption{color:#fff;word-wrap:wrap;width:100%}.img-comparison-slider .handle__caption--left{text-align:right}.img-comparison-slider .handle__svg{padding:.3em;background-color:#000;border-radius:100%}.img-comparison-slider .handle__svg svg{width:2.5em;height:2.5em}",P=["src"],H=["src"],B={slot:"handle",class:"handle"},I={class:"handle__caption handle__caption--left"},O=["innerHTML"],U={class:"handle__caption handle__caption--right"},z={__name:"ImgComparisonSlider.ce",props:{firstImage:{type:String,default:"https://assets.kvass.no/641c0b087c49867b0b1065ec,Første bilde"},secondImage:{type:String,default:"https://assets.kvass.no/641c0a8c7c49867b0b106570,Andre bilde"},options:{type:String,default:""},handleSvg:{type:String,default:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="-8 -3 16 6"><path stroke="#fff" d="M -3 -2 L -5 0 L -3 2 M -3 -2 L -3 2 M 3 -2 L 5 0 L 3 2 M 3 -2 L 3 2" stroke-width="1" fill="#fff" vector-effect="non-scaling-stroke"></path></svg>'}},setup(v){const p={value:50,hover:!1,direction:"horizontal",keyboard:"enabled",handle:!1};function c(l){if(!l)return{};const h=l.split(",");return{url:h[0],description:h[1]}}const s=v,n=c(s.firstImage),r=b(()=>n.description),a=c(s.secondImage),d=b(()=>a.description),u=b(()=>{const l=s.options.split(",").map(h=>h.split(":"));return Object.fromEntries(l)});return(l,h)=>(L(),E(g(C),M({style:`--first-image-caption: ${r.value}; --second-image-caption: ${d.value}`,tabindex:"0",class:"img-comparison-slider"},{...p,...u.value}),{default:T(()=>[f("img",{slot:"first",class:"img-comparison-slider__image",src:g(n).url},null,8,P),f("img",{slot:"second",class:"img-comparison-slider__image",src:g(a).url},null,8,H),f("div",B,[f("p",I,x(g(n).description),1),f("div",{class:"handle__svg",innerHTML:v.handleSvg},null,8,O),f("p",U,x(g(a).description),1)])]),_:1},16,["style"]))}},F=k(z,[["styles",[A]]]);customElements.define("kvass-img-comparison-slider",D(F));
1
+ import{q as S,s as k,_ as E,b,e as _,o as L,w as T,a as v,v as g,t as x,m as M,p as D}from"./_plugin-vue_export-helper.js";(()=>{var p={792:(s,n,r)=>{r.d(n,{Z:()=>u});var a=r(609),l=r.n(a)()(function(d){return d[1]});l.push([s.id,':host{--divider-width: 1px;--divider-color: #fff;--divider-shadow: none;--default-handle-width: 50px;--default-handle-color: #fff;--default-handle-opacity: 1;--default-handle-shadow: none;--handle-position-start: 50%;position:relative;display:inline-block;overflow:hidden;line-height:0;direction:ltr}@media screen and (-webkit-min-device-pixel-ratio: 0)and (min-resolution: 0.001dpcm){:host{outline-offset:1px}}:host(:focus){outline:2px solid -webkit-focus-ring-color}::slotted(*){-webkit-user-drag:none;-khtml-user-drag:none;-moz-user-drag:none;-o-user-drag:none;user-drag:none;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.first{position:absolute;left:0;top:0;right:0;line-height:normal;font-size:100%;max-height:100%;height:100%;width:100%;--exposure: 50%;--keyboard-transition-time: 0ms;--default-transition-time: 0ms;--transition-time: var(--default-transition-time)}.first .first-overlay-container{position:relative;clip-path:inset(0 var(--exposure) 0 0);transition:clip-path var(--transition-time);height:100%}.first .first-overlay{overflow:hidden;height:100%}.first.focused{will-change:clip-path}.first.focused .first-overlay-container{will-change:clip-path}.second{position:relative}.handle-container{transform:translateX(50%);position:absolute;top:0;right:var(--exposure);height:100%;transition:right var(--transition-time),bottom var(--transition-time)}.focused .handle-container{will-change:right}.divider{position:absolute;height:100%;width:100%;left:0;top:0;display:flex;align-items:center;justify-content:center;flex-direction:column}.divider:after{content:" ";display:block;height:100%;border-left-width:var(--divider-width);border-left-style:solid;border-left-color:var(--divider-color);box-shadow:var(--divider-shadow)}.handle{position:absolute;top:var(--handle-position-start);pointer-events:none;box-sizing:border-box;margin-left:1px;transform:translate(calc(-50% - 0.5px), -50%);line-height:0}.default-handle{width:var(--default-handle-width);opacity:var(--default-handle-opacity);transition:all 1s;filter:drop-shadow(var(--default-handle-shadow))}.default-handle path{stroke:var(--default-handle-color)}.vertical .first-overlay-container{clip-path:inset(0 0 var(--exposure) 0)}.vertical .handle-container{transform:translateY(50%);height:auto;top:unset;bottom:var(--exposure);width:100%;left:0;flex-direction:row}.vertical .divider:after{height:1px;width:100%;border-top-width:var(--divider-width);border-top-style:solid;border-top-color:var(--divider-color);border-left:0}.vertical .handle{top:auto;left:var(--handle-position-start);transform:translate(calc(-50% - 0.5px), -50%) rotate(90deg)}',""]);const u=l},609:s=>{s.exports=function(n){var r=[];return r.toString=function(){return this.map(function(a){var l=n(a);return a[2]?"@media ".concat(a[2]," {").concat(l,"}"):l}).join("")},r.i=function(a,l,u){typeof a=="string"&&(a=[[null,a,""]]);var d={};if(u)for(var h=0;h<this.length;h++){var w=this[h][0];w!=null&&(d[w]=!0)}for(var e=0;e<a.length;e++){var t=[].concat(a[e]);u&&d[t[0]]||(l&&(t[2]?t[2]="".concat(l," and ").concat(t[2]):t[2]=l),r.push(t))}},r}}},f={};function c(s){var n=f[s];if(n!==void 0)return n.exports;var r=f[s]={id:s,exports:{}};return p[s](r,r.exports,c),r.exports}c.n=s=>{var n=s&&s.__esModule?()=>s.default:()=>s;return c.d(n,{a:n}),n},c.d=(s,n)=>{for(var r in n)c.o(n,r)&&!c.o(s,r)&&Object.defineProperty(s,r,{enumerable:!0,get:n[r]})},c.o=(s,n)=>Object.prototype.hasOwnProperty.call(s,n),(()=>{var s=c(792);const n="rendered",r=(e,t)=>{const i=e.getBoundingClientRect();let o,m;return t.type==="mousedown"?(o=t.clientX,m=t.clientY):(o=t.touches[0].clientX,m=t.touches[0].clientY),o>=i.x&&o<=i.x+i.width&&m>=i.y&&m<=i.y+i.height};let a;const l={ArrowLeft:-1,ArrowRight:1},u=["horizontal","vertical"],d=e=>({x:e.touches[0].pageX,y:e.touches[0].pageY}),h=e=>({x:e.pageX,y:e.pageY}),w=typeof window<"u"&&window?.HTMLElement;typeof window<"u"&&(window.document&&(a=document.createElement("template"),a.innerHTML='<div class="second" id="second"> <slot name="second"><slot name="before"></slot></slot> </div> <div class="first" id="first"> <div class="first-overlay"> <div class="first-overlay-container" id="firstImageContainer"> <slot name="first"><slot name="after"></slot></slot> </div> </div> <div class="handle-container"> <div class="divider"></div> <div class="handle" id="handle"> <slot name="handle"> <svg xmlns="http://www.w3.org/2000/svg" class="default-handle" viewBox="-8 -3 16 6"> <path d="M -5 -2 L -7 0 L -5 2 M 5 -2 L 7 0 L 5 2" fill="none" vector-effect="non-scaling-stroke"/> </svg> </slot> </div> </div> </div> '),window.customElements.define("img-comparison-slider",class extends w{constructor(){super(),this.exposure=this.hasAttribute("value")?parseFloat(this.getAttribute("value")):50,this.slideOnHover=!1,this.slideDirection="horizontal",this.keyboard="enabled",this.isMouseDown=!1,this.animationDirection=0,this.isFocused=!1,this.dragByHandle=!1,this.onMouseMove=i=>{if(this.isMouseDown||this.slideOnHover){const o=h(i);this.slideToPage(o)}},this.bodyUserSelectStyle="",this.bodyWebkitUserSelectStyle="",this.onMouseDown=i=>{if(this.slideOnHover||this.handle&&!r(this.handleElement,i))return;i.preventDefault(),window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("mouseup",this.onWindowMouseUp),this.isMouseDown=!0,this.enableTransition();const o=h(i);this.slideToPage(o),this.focus(),this.bodyUserSelectStyle=window.document.body.style.userSelect,this.bodyWebkitUserSelectStyle=window.document.body.style.webkitUserSelect,window.document.body.style.userSelect="none",window.document.body.style.webkitUserSelect="none"},this.onWindowMouseUp=()=>{this.isMouseDown=!1,window.document.body.style.userSelect=this.bodyUserSelectStyle,window.document.body.style.webkitUserSelect=this.bodyWebkitUserSelectStyle,window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("mouseup",this.onWindowMouseUp)},this.touchStartPoint=null,this.isTouchComparing=!1,this.hasTouchMoved=!1,this.onTouchStart=i=>{this.dragByHandle&&!r(this.handleElement,i)||(this.touchStartPoint=d(i),this.isFocused&&(this.enableTransition(),this.slideToPage(this.touchStartPoint)))},this.onTouchMove=i=>{if(this.touchStartPoint===null)return;const o=d(i);if(this.isTouchComparing)return this.slideToPage(o),i.preventDefault(),!1;if(!this.hasTouchMoved){const m=Math.abs(o.y-this.touchStartPoint.y),y=Math.abs(o.x-this.touchStartPoint.x);if(this.slideDirection==="horizontal"&&m<y||this.slideDirection==="vertical"&&m>y)return this.isTouchComparing=!0,this.focus(),this.slideToPage(o),i.preventDefault(),!1;this.hasTouchMoved=!0}},this.onTouchEnd=()=>{this.isTouchComparing=!1,this.hasTouchMoved=!1,this.touchStartPoint=null},this.onBlur=()=>{this.stopSlideAnimation(),this.isFocused=!1,this.firstElement.classList.remove("focused")},this.onFocus=()=>{this.isFocused=!0,this.firstElement.classList.add("focused")},this.onKeyDown=i=>{if(this.keyboard==="disabled")return;const o=l[i.key];this.animationDirection!==o&&o!==void 0&&(this.animationDirection=o,this.startSlideAnimation())},this.onKeyUp=i=>{if(this.keyboard==="disabled")return;const o=l[i.key];o!==void 0&&this.animationDirection===o&&this.stopSlideAnimation()},this.resetDimensions=()=>{this.imageWidth=this.offsetWidth,this.imageHeight=this.offsetHeight};const e=this.attachShadow({mode:"open"}),t=document.createElement("style");t.innerHTML=s.Z,this.getAttribute("nonce")&&t.setAttribute("nonce",this.getAttribute("nonce")),e.appendChild(t),e.appendChild(a.content.cloneNode(!0)),this.firstElement=e.getElementById("first"),this.handleElement=e.getElementById("handle")}set handle(e){this.dragByHandle=e.toString().toLowerCase()!=="false"}get handle(){return this.dragByHandle}get value(){return this.exposure}set value(e){const t=parseFloat(e);t!==this.exposure&&(this.exposure=t,this.enableTransition(),this.setExposure())}get hover(){return this.slideOnHover}set hover(e){this.slideOnHover=e.toString().toLowerCase()!=="false",this.removeEventListener("mousemove",this.onMouseMove),this.slideOnHover&&this.addEventListener("mousemove",this.onMouseMove)}get direction(){return this.slideDirection}set direction(e){this.slideDirection=e.toString().toLowerCase(),this.slide(0),this.firstElement.classList.remove(...u),u.includes(this.slideDirection)&&this.firstElement.classList.add(this.slideDirection)}static get observedAttributes(){return["hover","direction"]}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.addEventListener("dragstart",e=>(e.preventDefault(),!1)),new ResizeObserver(this.resetDimensions).observe(this),this.setExposure(0),this.keyboard=this.hasAttribute("keyboard")&&this.getAttribute("keyboard")==="disabled"?"disabled":"enabled",this.addEventListener("keydown",this.onKeyDown),this.addEventListener("keyup",this.onKeyUp),this.addEventListener("focus",this.onFocus),this.addEventListener("blur",this.onBlur),this.addEventListener("touchstart",this.onTouchStart,{passive:!0}),this.addEventListener("touchmove",this.onTouchMove,{passive:!1}),this.addEventListener("touchend",this.onTouchEnd),this.addEventListener("mousedown",this.onMouseDown),this.handle=this.hasAttribute("handle")?this.getAttribute("handle"):this.dragByHandle,this.hover=this.hasAttribute("hover")?this.getAttribute("hover"):this.slideOnHover,this.direction=this.hasAttribute("direction")?this.getAttribute("direction"):this.slideDirection,this.resetDimensions(),this.classList.contains(n)||this.classList.add(n)}disconnectedCallback(){this.transitionTimer&&window.clearTimeout(this.transitionTimer)}attributeChangedCallback(e,t,i){e==="hover"&&(this.hover=i),e==="direction"&&(this.direction=i),e==="keyboard"&&(this.keyboard=i==="disabled"?"disabled":"enabled")}setExposure(e=0){var t;this.exposure=(t=this.exposure+e)<0?0:t>100?100:t,this.firstElement.style.setProperty("--exposure",100-this.exposure+"%")}slide(e=0){this.setExposure(e);const t=new Event("slide");this.dispatchEvent(t)}slideToPage(e){this.slideDirection==="horizontal"&&this.slideToPageX(e.x),this.slideDirection==="vertical"&&this.slideToPageY(e.y)}slideToPageX(e){const t=e-this.getBoundingClientRect().left-window.scrollX;this.exposure=t/this.imageWidth*100,this.slide(0)}slideToPageY(e){const t=e-this.getBoundingClientRect().top-window.scrollY;this.exposure=t/this.imageHeight*100,this.slide(0)}enableTransition(){this.firstElement.style.setProperty("--transition-time","100ms"),this.transitionTimer=window.setTimeout(()=>{this.firstElement.style.setProperty("--transition-time","var(--default-transition-time)"),this.transitionTimer=null},100)}startSlideAnimation(){let e=null,t=this.animationDirection;this.firstElement.style.setProperty("--transition-time","var(--keyboard-transition-time)");const i=o=>{if(this.animationDirection===0||t!==this.animationDirection)return;e===null&&(e=o);const m=(o-e)/16.666666666666668*this.animationDirection;this.slide(m),setTimeout(()=>window.requestAnimationFrame(i),0),e=o};window.requestAnimationFrame(i)}stopSlideAnimation(){this.animationDirection=0,this.firstElement.style.setProperty("--transition-time","var(--default-transition-time)")}}))})()})();const A=S({name:"ImgComparisonSlider",setup(p,{slots:f}){return()=>k("img-comparison-slider",f.default())}}),C=".img-comparison-slider{width:100%;height:100%;--divider-width: 4px;--divider-color: black}.img-comparison-slider__image{width:100%;height:100%;object-fit:cover}.img-comparison-slider .handle{display:flex;flex-direction:row;justify-content:center;align-items:center;flex-wrap:nowrap;gap:1rem;min-width:800px;font-size:1rem}@media (max-width: 600px){.img-comparison-slider .handle{font-size:.75rem}}.img-comparison-slider .handle__caption{color:#fff;word-wrap:wrap;width:100%}.img-comparison-slider .handle__caption--left{text-align:right}.img-comparison-slider .handle__svg{padding:.3em;background-color:#000;border-radius:100%}.img-comparison-slider .handle__svg svg{width:2.5em;height:2.5em}",P=["src","alt"],H=["src","alt"],B={slot:"handle",class:"handle"},I={class:"handle__caption handle__caption--left"},O=["innerHTML"],U={class:"handle__caption handle__caption--right"},z={__name:"ImgComparisonSlider.ce",props:{firstImage:{type:String,default:"https://assets.kvass.no/641c0b087c49867b0b1065ec,Første bilde"},firstAlt:{type:String,default:""},secondImage:{type:String,default:"https://assets.kvass.no/641c0a8c7c49867b0b106570,Andre bilde"},secondAlt:{type:String,default:""},options:{type:String,default:""},handleSvg:{type:String,default:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="-8 -3 16 6"><path stroke="#fff" d="M -3 -2 L -5 0 L -3 2 M -3 -2 L -3 2 M 3 -2 L 5 0 L 3 2 M 3 -2 L 3 2" stroke-width="1" fill="#fff" vector-effect="non-scaling-stroke"></path></svg>'}},setup(p){const f={value:50,hover:!1,direction:"horizontal",keyboard:"enabled",handle:!1};function c(d){if(!d)return{};const h=d.split(",");return{url:h[0],description:h[1]}}const s=p,n=c(s.firstImage),r=b(()=>n.description),a=c(s.secondImage),l=b(()=>a.description),u=b(()=>{const d=s.options.split(",").map(h=>h.split(":"));return Object.fromEntries(d)});return(d,h)=>(L(),_(g(A),M({style:`--first-image-caption: ${r.value}; --second-image-caption: ${l.value}`,tabindex:"0",class:"img-comparison-slider"},{...f,...u.value}),{default:T(()=>[v("img",{slot:"first",class:"img-comparison-slider__image",src:g(n).url,alt:p.firstAlt},null,8,P),v("img",{slot:"second",class:"img-comparison-slider__image",src:g(a).url,alt:p.secondAlt},null,8,H),v("div",B,[v("p",I,x(g(n).description),1),v("div",{class:"handle__svg",innerHTML:p.handleSvg},null,8,O),v("p",U,x(g(a).description),1)])]),_:1},16,["style"]))}},F=E(z,[["styles",[C]]]);customElements.define("kvass-img-comparison-slider",D(F));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kvass/widgets",
3
- "version": "1.9.45",
3
+ "version": "1.9.46",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",