@tinydialog/sdk-js 0.0.1-rc.7 → 0.0.1-rc.8
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/README.md +1 -1
- package/dist/browser.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";(()=>{var e=(()=>{let e=0;return()=>(e+=1,`u${`0000${(Math.random()*36**4|0).toString(36)}`.slice(-4)}${e}`)})();function t(e){const t=[];for(let n=0,o=e.length;n<o;n++)t.push(e[n]);return t}var n=null;function o(e={}){return n||(n=e.includeStyleProperties?e.includeStyleProperties:t(window.getComputedStyle(document.documentElement)))}function i(e,t){const n=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return n?parseFloat(n.replace("px","")):0}function r(e,t={}){return{width:t.width||function(e){const t=i(e,"border-left-width"),n=i(e,"border-right-width");return e.clientWidth+t+n}(e),height:t.height||function(e){const t=i(e,"border-top-width"),n=i(e,"border-bottom-width");return e.clientHeight+t+n}(e)}}var a=16384;function s(e){return new Promise((t,n)=>{const o=new Image;o.onload=()=>{o.decode().then(()=>{requestAnimationFrame(()=>t(o))})},o.onerror=n,o.crossOrigin="anonymous",o.decoding="async",o.src=e})}var l=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return null!==n&&(n.constructor.name===t.name||l(n,t))};function c(t,n,i,r){const a=window.getComputedStyle(t,i),s=a.getPropertyValue("content");if(""===s||"none"===s)return;const l=e();try{n.className=`${n.className} ${l}`}catch(e){return}const c=document.createElement("style");c.appendChild(function(e,t,n,i){const r=`.${e}:${t}`,a=n.cssText?function(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}(n):function(e,t){return o(t).map(t=>`${t}: ${e.getPropertyValue(t)}${e.getPropertyPriority(t)?" !important":""};`).join(" ")}(n,i);return document.createTextNode(`${r}{${a}}`)}(l,i,a,r)),n.appendChild(c)}var d="application/font-woff",u="image/jpeg",g={woff:d,woff2:d,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:u,jpeg:u,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function h(e){const t=function(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}(e).toLowerCase();return g[t]||""}function f(e){return-1!==e.search(/^(data:)/)}function y(e,t){return`data:${t};base64,${e}`}async function m(e,t,n){const o=await fetch(e,t);if(404===o.status)throw new Error(`Resource "${o.url}" not found`);const i=await o.blob();return new Promise((e,t)=>{const r=new FileReader;r.onerror=t,r.onloadend=()=>{try{e(n({res:o,result:r.result}))}catch(e){t(e)}},r.readAsDataURL(i)})}var w={};async function p(e,t,n){const o=function(e,t,n){let o=e.replace(/\?.*/,"");return n&&(o=e),/ttf|otf|eot|woff2?/i.test(o)&&(o=o.replace(/.*\//,"")),t?`[${t}]${o}`:o}(e,t,n.includeQueryParams);if(null!=w[o])return w[o];let i;n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+(new Date).getTime());try{const o=await m(e,n.fetchRequestInit,({res:e,result:n})=>(t||(t=e.headers.get("Content-Type")||""),function(e){return e.split(/,/)[1]}(n)));i=y(o,t)}catch(t){i=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;t&&(o="string"==typeof t?t:t.message),o&&console.warn(o)}return w[o]=i,i}var v=e=>null!=e.tagName&&"SVG"===e.tagName.toUpperCase();async function b(e,n,i){return i||!n.filter||n.filter(e)?Promise.resolve(e).then(e=>async function(e,t){return l(e,HTMLCanvasElement)?async function(e){const t=e.toDataURL();return"data:,"===t?e.cloneNode(!1):s(t)}(e):l(e,HTMLVideoElement)?async function(e,t){if(e.currentSrc){const t=document.createElement("canvas"),n=t.getContext("2d");return t.width=e.clientWidth,t.height=e.clientHeight,null==n||n.drawImage(e,0,0,t.width,t.height),s(t.toDataURL())}const n=e.poster,o=h(n);return s(await p(n,o,t))}(e,t):l(e,HTMLIFrameElement)?async function(e,t){var n;try{if(null===(n=null==e?void 0:e.contentDocument)||void 0===n?void 0:n.body)return await b(e.contentDocument.body,t,!0)}catch(e){}return e.cloneNode(!1)}(e,t):e.cloneNode(v(e))}(e,n)).then(o=>async function(e,n,o){var i,r;if(v(n))return n;let a=[];return a=(e=>null!=e.tagName&&"SLOT"===e.tagName.toUpperCase())(e)&&e.assignedNodes?t(e.assignedNodes()):l(e,HTMLIFrameElement)&&(null===(i=e.contentDocument)||void 0===i?void 0:i.body)?t(e.contentDocument.body.childNodes):t((null!==(r=e.shadowRoot)&&void 0!==r?r:e).childNodes),0===a.length||l(e,HTMLVideoElement)||await a.reduce((e,t)=>e.then(()=>b(t,o)).then(e=>{e&&n.appendChild(e)}),Promise.resolve()),n}(e,o,n)).then(t=>function(e,t,n){return l(t,Element)&&(function(e,t,n){const i=t.style;if(!i)return;const r=window.getComputedStyle(e);r.cssText?(i.cssText=r.cssText,i.transformOrigin=r.transformOrigin):o(n).forEach(n=>{let o=r.getPropertyValue(n);if("font-size"===n&&o.endsWith("px")){const e=Math.floor(parseFloat(o.substring(0,o.length-2)))-.1;o=`${e}px`}l(e,HTMLIFrameElement)&&"display"===n&&"inline"===o&&(o="block"),"d"===n&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),i.setProperty(n,o,r.getPropertyPriority(n))})}(e,t,n),function(e,t,n){c(e,t,":before",n),c(e,t,":after",n)}(e,t,n),function(e,t){l(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),l(e,HTMLInputElement)&&t.setAttribute("value",e.value)}(e,t),function(e,t){if(l(e,HTMLSelectElement)){const n=t,o=Array.from(n.children).find(t=>e.value===t.getAttribute("value"));o&&o.setAttribute("selected","")}}(e,t)),t}(e,t,n)).then(e=>async function(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(0===n.length)return e;const o={};for(let i=0;i<n.length;i++){const r=n[i].getAttribute("xlink:href");if(r){const n=e.querySelector(r),i=document.querySelector(r);n||!i||o[r]||(o[r]=await b(i,t,!0))}}const i=Object.values(o);if(i.length){const t="http://www.w3.org/1999/xhtml",n=document.createElementNS(t,"svg");n.setAttribute("xmlns",t),n.style.position="absolute",n.style.width="0",n.style.height="0",n.style.overflow="hidden",n.style.display="none";const o=document.createElementNS(t,"defs");n.appendChild(o);for(let e=0;e<i.length;e++)o.appendChild(i[e]);e.appendChild(n)}return e}(e,n)):null}var E=/url\((['"]?)([^'"]+?)\1\)/g,S=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,x=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function T(e){return-1!==e.search(E)}async function $(e,t,n){if(!T(e))return e;const o=function(e,{preferredFontFormat:t}){return t?e.replace(x,e=>{for(;;){const[n,,o]=S.exec(e)||[];if(!o)return"";if(o===t)return`src: ${n};`}}):e}(e,n),i=function(e){const t=[];return e.replace(E,(e,n,o)=>(t.push(o),e)),t.filter(e=>!f(e))}(o);return i.reduce((e,o)=>e.then(e=>async function(e,t,n,o){try{const i=n?function(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),o=n.createElement("base"),i=n.createElement("a");return n.head.appendChild(o),n.body.appendChild(i),t&&(o.href=t),i.href=e,i.href}(t,n):t,r=h(t);let a;return a=await p(i,r,o),e.replace(function(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}(t),`$1${a}$3`)}catch(e){}return e}(e,o,t,n)),Promise.resolve(o))}async function C(e,t,n){var o;const i=null===(o=t.style)||void 0===o?void 0:o.getPropertyValue(e);if(i){const o=await $(i,null,n);return t.style.setProperty(e,o,t.style.getPropertyPriority(e)),!0}return!1}async function P(e,n){l(e,Element)&&(await async function(e,t){await C("background",e,t)||await C("background-image",e,t),await C("mask",e,t)||await C("-webkit-mask",e,t)||await C("mask-image",e,t)||await C("-webkit-mask-image",e,t)}(e,n),await async function(e,t){const n=l(e,HTMLImageElement);if((!n||f(e.src))&&(!l(e,SVGImageElement)||f(e.href.baseVal)))return;const o=n?e.src:e.href.baseVal,i=await p(o,h(o),t);await new Promise((o,r)=>{e.onload=o,e.onerror=t.onImageErrorHandler?(...e)=>{try{o(t.onImageErrorHandler(...e))}catch(e){r(e)}}:r;const a=e;a.decode&&(a.decode=o),"lazy"===a.loading&&(a.loading="eager"),n?(e.srcset="",e.src=i):e.href.baseVal=i})}(e,n),await async function(e,n){const o=t(e.childNodes).map(e=>P(e,n));await Promise.all(o).then(()=>e)}(e,n))}var L={};async function k(e){let t=L[e];if(null!=t)return t;const n=await fetch(e);return t={url:e,cssText:await n.text()},L[e]=t,t}async function H(e,t){let n=e.cssText;const o=/url\(["']?([^"')]+)["']?\)/g,i=(n.match(/url\([^)]+\)/g)||[]).map(async i=>{let r=i.replace(o,"$1");return r.startsWith("https://")||(r=new URL(r,e.url).href),m(r,t.fetchRequestInit,({result:e})=>(n=n.replace(i,`url(${e})`),[i,e]))});return Promise.all(i).then(()=>n)}function R(e){if(null==e)return[];const t=[];let n=e.replace(/(\/\*[\s\S]*?\*\/)/gi,"");const o=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const e=o.exec(n);if(null===e)break;t.push(e[0])}n=n.replace(o,"");const i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,r=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let e=i.exec(n);if(null===e){if(e=r.exec(n),null===e)break;i.lastIndex=r.lastIndex}else r.lastIndex=i.lastIndex;t.push(e[0])}return t}function M(e){return e.trim().replace(/["']/g,"")}async function F(e,n={}){const{width:o,height:i}=r(e,n),a=await b(e,n,!0);return await async function(e,n){const o=null!=n.fontEmbedCSS?n.fontEmbedCSS:n.skipFonts?null:await async function(e,n){const o=await async function(e,n){if(null==e.ownerDocument)throw new Error("Provided element is not within a Document");const o=t(e.ownerDocument.styleSheets),i=await async function(e,n){const o=[],i=[];return e.forEach(o=>{if("cssRules"in o)try{t(o.cssRules||[]).forEach((e,t)=>{if(e.type===CSSRule.IMPORT_RULE){let r=t+1;const a=k(e.href).then(e=>H(e,n)).then(e=>R(e).forEach(e=>{try{o.insertRule(e,e.startsWith("@import")?r+=1:o.cssRules.length)}catch(t){console.error("Error inserting rule from remote css",{rule:e,error:t})}})).catch(e=>{console.error("Error loading remote css",e.toString())});i.push(a)}})}catch(t){const r=e.find(e=>null==e.href)||document.styleSheets[0];null!=o.href&&i.push(k(o.href).then(e=>H(e,n)).then(e=>R(e).forEach(e=>{r.insertRule(e,r.cssRules.length)})).catch(e=>{console.error("Error loading remote stylesheet",e)})),console.error("Error inlining remote css file",t)}}),Promise.all(i).then(()=>(e.forEach(e=>{if("cssRules"in e)try{t(e.cssRules||[]).forEach(e=>{o.push(e)})}catch(t){console.error(`Error while reading CSS rules from ${e.href}`,t)}}),o))}(o,n);return function(e){return e.filter(e=>e.type===CSSRule.FONT_FACE_RULE).filter(e=>T(e.style.getPropertyValue("src")))}(i)}(e,n),i=function(e){const t=new Set;return function e(n){(n.style.fontFamily||getComputedStyle(n).fontFamily).split(",").forEach(e=>{t.add(M(e))}),Array.from(n.children).forEach(t=>{t instanceof HTMLElement&&e(t)})}(e),t}(e);return(await Promise.all(o.filter(e=>i.has(M(e.style.fontFamily))).map(e=>{const t=e.parentStyleSheet?e.parentStyleSheet.href:null;return $(e.cssText,t,n)}))).join("\n")}(e,n);if(o){const t=document.createElement("style"),n=document.createTextNode(o);t.appendChild(n),e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}}(a,n),await P(a,n),function(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const o=t.style;null!=o&&Object.keys(o).forEach(e=>{n[e]=o[e]})}(a,n),await async function(e,t,n){const o="http://www.w3.org/2000/svg",i=document.createElementNS(o,"svg"),r=document.createElementNS(o,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${n}`),i.setAttribute("viewBox",`0 0 ${t} ${n}`),r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.setAttribute("x","0"),r.setAttribute("y","0"),r.setAttribute("externalResourcesRequired","true"),i.appendChild(r),r.appendChild(e),async function(e){return Promise.resolve().then(()=>(new XMLSerializer).serializeToString(e)).then(encodeURIComponent).then(e=>`data:image/svg+xml;charset=utf-8,${e}`)}(i)}(a,o,i)}var A={BOTTOM_RIGHT:{right:"0",bottom:"0"},BOTTOM_LEFT:{left:"0",bottom:"0"},TOP_RIGHT:{right:"0",top:"0"},TOP_LEFT:{left:"0",top:"0"}};function I(e,t,n){if(!e||e.length<5)throw new Error(`invalid surveyId! Please copy the correct surveyId from the tinyDialog dashboard. (surveyId=${e})`);const o=(n??document).querySelector(`#tinydialog-widget__${e}_auto iframe`);if(o)return console.debug(`skipping tinyDialog survey-load for ${e}, already loaded`),o.parentElement;let i=n;if(null==i){i=document.createElement("div"),i.className="tinydialog-floating-widget",i.id=`tinydialog-widget__${e}_auto`,i.dataset.tinydialogWidget=e,i.style.position="fixed";for(const[e,n]of Object.entries(A[t?.side??"BOTTOM_RIGHT"]))i.style.setProperty(e,n);i.style.overflow="hidden",i.style.visibility="hidden",i.style.transitionProperty="opacity, transform, height",i.style.transitionDuration="200ms",i.style.transform="scale(0.75)",i.style.opacity="0",i.style.zIndex="100"}let l=t?.user?.trim();0===l?.length&&(l=void 0);let c=`https://app.tinydialog.com/widget/v1/${e}?parent=${encodeURIComponent(window.location.href)}`;l&&(c+=`&user=${l}`);for(const[e,n]of Object.entries(t?.extraData??{}))null!=e&&0!==e.trim().length&&0!==n.trim().length&&(c+=`&extra-${e}=${n}`);const d=i.querySelector("iframe")??document.createElement("iframe");d.src=c,d.style.transitionProperty="height",d.style.transitionDuration="150ms",d.style.height="100%",d.style.minWidth="350px",d.style.border="none",d.ariaLabel="tinyDialog survey widget";const u=async t=>{if(t.data.targetWidget===e)if("tinydialog--hello"===t.data.event)d.contentWindow?.postMessage({event:"tinydialog--screenSize",data:{screenSizeWidth:window.innerWidth,screenSizeHeight:window.innerHeight}},"*");else if("tinydialog--updateHeight"===t.data.event&&t.data.data)i.style.height=t.data.data+"px";else if("tinydialog--close"===t.data.event)O(t.data.targetWidget);else if("tinydialog--requestScreenshot"===t.data.event)try{const e=await async function(e,t={}){const{width:n,height:o}=r(e,t),i=await F(e,t),l=await s(i),c=document.createElement("canvas"),d=c.getContext("2d"),u=t.pixelRatio||function(){let e,t;try{t=process}catch(e){}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}(),g=t.canvasWidth||n,h=t.canvasHeight||o;return c.width=g*u,c.height=h*u,t.skipAutoScale||function(e){(e.width>a||e.height>a)&&(e.width>a&&e.height>a?e.width>e.height?(e.height*=a/e.width,e.width=a):(e.width*=a/e.height,e.height=a):e.width>a?(e.height*=a/e.width,e.width=a):(e.width*=a/e.height,e.height=a))}(c),c.style.width=`${g}`,c.style.height=`${h}`,t.backgroundColor&&(d.fillStyle=t.backgroundColor,d.fillRect(0,0,c.width,c.height)),d.drawImage(l,0,0,c.width,c.height),c}(document.body,{skipAutoScale:!0,skipFonts:navigator.userAgent?.includes("Firefox")??!0,includeQueryParams:!0,width:window.innerWidth,height:window.innerHeight,canvasWidth:window.innerWidth*Math.min(1,1080/window.innerWidth),canvasHeight:window.innerHeight*Math.min(1,1080/window.innerWidth),backgroundColor:document.body.style.backgroundColor.length>0?window.getComputedStyle(document.body,null).getPropertyValue("background-color"):"rgb(255, 255, 255, 1)",style:{transform:`translate(-${window.scrollX}px, -${window.scrollY}px)`,width:`${window.innerWidth}px`,height:`${window.innerHeight}px`}}),t=await new Promise((t,n)=>{try{e.toBlob(e=>t(e),"image/jpeg",.35)}catch(e){n(e)}});if(!t)return void console.error("could not take screenshot, img null");if(!d.contentWindow)return void console.error("no iframe.contentWindow");d.contentWindow.postMessage({event:"tinydialog--screenshot",data:t},"*")}catch(e){console.error("failed taking screenshot of webpage",e)}};window.removeEventListener("message",u),window.addEventListener("message",u),i.appendChild(d),n||document.body.append(i);const g=B(()=>{d.contentWindow?.postMessage({event:"tinydialog--screenSize",data:{screenSizeWidth:window.innerWidth,screenSizeHeight:window.innerHeight}},"*")},150);return window.removeEventListener("resize",g),window.addEventListener("resize",g),i}function W(e,t,n=0){document.querySelectorAll('[data-tinydialog-widget-visible="true"]').forEach(e=>{const t=e.dataset.tinydialogWidget;t?O(t):console.warn("visibleWidget to close had no surveyId!",e)});let o=document.querySelector(`[data-tinydialog-widget='${e}']`);if(o||(o=I(e,t)),o instanceof HTMLElement)if(!o.style.height&&n<=25)setTimeout(()=>W(e,t,n+1),30+75*n);else{for(const[e,n]of Object.entries(A[t?.side??"BOTTOM_RIGHT"]))o.style.setProperty(e,n);o.dataset.tinydialogWidgetVisible="true",o.style.visibility="visible",o.style.transform="scale(1.0)",o.style.opacity="1"}else console.warn("tried opening widget, but widgetContainer was not a HTMLElement")}function O(e){const t=document.querySelector(`[data-tinydialog-widget='${e}']`);t?t instanceof HTMLElement?(t.style.transform="scale(0.75)",t.style.opacity="0",t.style.visibility="hidden",t.removeAttribute("data-tinydialog-widget-visible")):console.warn("tried opening widget, but widgetContainer was not a HTMLElement"):console.debug(`tried closing widget with id ${e} which does not exist on page`)}function N(e){e.currentTarget instanceof HTMLElement&&W(e.currentTarget.dataset.tinydialogOpenwidget,{side:e.currentTarget.dataset.tinydialogWidgetSide?.toUpperCase()})}function D(){q?.dataset.tinydialogFloatingButton&&function(e){const t=e.tinydialogFloatingButton;if(!t||t.length<10)return void console.warn('invalid surveyId configured in "data-tinydialog-floating-button"');if(document.querySelector("#tinydialog-floating-button__auto"))return void console.debug("prevented duplicate autoCreateFloatingButton execution, button alreadx exists");const n=document.createElement("button");n.id="tinydialog-floating-button__auto",n.style.position="fixed",n.style.right="20px",n.style.bottom="20px",n.style.width="48px",n.style.height="48px",n.style.background=e.tinydialogFloatingButtonBackground??"black",n.style.color=e.tinydialogFloatingButtonForeground??"white",n.style.borderRadius="100%",n.style.padding="8px",n.style.cursor="pointer",n.style.transitionDuration="300ms",n.style.transitionProperty="all",n.dataset.tinydialogOpenwidget=t,n.addEventListener("mouseenter",()=>{n.style.background=e.tinydialogFloatingButtonBackgroundHover??"#E2187D",n.style.color=e.tinydialogFloatingButtonForegroundHover??"white"}),n.addEventListener("mouseleave",()=>{n.style.background=e.tinydialogFloatingButtonBackground??"black",n.style.color=e.tinydialogFloatingButtonForeground??"white"});const o=document.createElement("svg");n.append(o),o.outerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',document.body.append(n)}(q.dataset),document.querySelectorAll("[data-tinydialog-openwidget]").forEach(e=>{e instanceof HTMLElement&&(I(e.dataset.tinydialogOpenwidget,{side:e.dataset.tinydialogWidgetSide?.toUpperCase(),user:e.dataset.tinydialogUser??q?.dataset.tinydialogUser}),e.removeEventListener("click",N),e.addEventListener("click",N))}),document.querySelectorAll("[data-tinydialog-widgetcontainer]").forEach(e=>{e instanceof HTMLElement?I(e.dataset.tinydialogWidgetcontainer,{user:e.dataset.tinydialogUser??q?.dataset.tinydialogUser},e):console.debug("tinyDialog widgetContainer is not a HTMLElement",e)})}var B=(e,t)=>{let n;return(...o)=>{clearTimeout(n),n=setTimeout(()=>{e(...o)},t)}},q=document.currentScript;onload=()=>{q||(q=document.currentScript)},D(),function(){if("navigation"in window)window.navigation.addEventListener("navigate",()=>{requestAnimationFrame(()=>{D()})});else{let e=location.href;new MutationObserver(()=>{e!==location.href&&(e=location.href,requestAnimationFrame(()=>{D()}))}).observe(document,{subtree:!0,childList:!0})}}()})();
|
|
1
|
+
"use client";"use strict";(()=>{var e=(()=>{let e=0;return()=>(e+=1,`u${`0000${(Math.random()*36**4|0).toString(36)}`.slice(-4)}${e}`)})();function t(e){const t=[];for(let n=0,o=e.length;n<o;n++)t.push(e[n]);return t}var n=null;function o(e={}){return n||(n=e.includeStyleProperties?e.includeStyleProperties:t(window.getComputedStyle(document.documentElement)))}function i(e,t){const n=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return n?parseFloat(n.replace("px","")):0}function r(e,t={}){return{width:t.width||function(e){const t=i(e,"border-left-width"),n=i(e,"border-right-width");return e.clientWidth+t+n}(e),height:t.height||function(e){const t=i(e,"border-top-width"),n=i(e,"border-bottom-width");return e.clientHeight+t+n}(e)}}var a=16384;function s(e){return new Promise((t,n)=>{const o=new Image;o.onload=()=>{o.decode().then(()=>{requestAnimationFrame(()=>t(o))})},o.onerror=n,o.crossOrigin="anonymous",o.decoding="async",o.src=e})}var l=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return null!==n&&(n.constructor.name===t.name||l(n,t))};function c(t,n,i,r){const a=window.getComputedStyle(t,i),s=a.getPropertyValue("content");if(""===s||"none"===s)return;const l=e();try{n.className=`${n.className} ${l}`}catch(e){return}const c=document.createElement("style");c.appendChild(function(e,t,n,i){const r=`.${e}:${t}`,a=n.cssText?function(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}(n):function(e,t){return o(t).map(t=>`${t}: ${e.getPropertyValue(t)}${e.getPropertyPriority(t)?" !important":""};`).join(" ")}(n,i);return document.createTextNode(`${r}{${a}}`)}(l,i,a,r)),n.appendChild(c)}var d="application/font-woff",u="image/jpeg",g={woff:d,woff2:d,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:u,jpeg:u,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function h(e){const t=function(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}(e).toLowerCase();return g[t]||""}function f(e){return-1!==e.search(/^(data:)/)}function y(e,t){return`data:${t};base64,${e}`}async function m(e,t,n){const o=await fetch(e,t);if(404===o.status)throw new Error(`Resource "${o.url}" not found`);const i=await o.blob();return new Promise((e,t)=>{const r=new FileReader;r.onerror=t,r.onloadend=()=>{try{e(n({res:o,result:r.result}))}catch(e){t(e)}},r.readAsDataURL(i)})}var w={};async function p(e,t,n){const o=function(e,t,n){let o=e.replace(/\?.*/,"");return n&&(o=e),/ttf|otf|eot|woff2?/i.test(o)&&(o=o.replace(/.*\//,"")),t?`[${t}]${o}`:o}(e,t,n.includeQueryParams);if(null!=w[o])return w[o];let i;n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+(new Date).getTime());try{const o=await m(e,n.fetchRequestInit,({res:e,result:n})=>(t||(t=e.headers.get("Content-Type")||""),function(e){return e.split(/,/)[1]}(n)));i=y(o,t)}catch(t){i=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;t&&(o="string"==typeof t?t:t.message),o&&console.warn(o)}return w[o]=i,i}var v=e=>null!=e.tagName&&"SVG"===e.tagName.toUpperCase();async function b(e,n,i){return i||!n.filter||n.filter(e)?Promise.resolve(e).then(e=>async function(e,t){return l(e,HTMLCanvasElement)?async function(e){const t=e.toDataURL();return"data:,"===t?e.cloneNode(!1):s(t)}(e):l(e,HTMLVideoElement)?async function(e,t){if(e.currentSrc){const t=document.createElement("canvas"),n=t.getContext("2d");return t.width=e.clientWidth,t.height=e.clientHeight,null==n||n.drawImage(e,0,0,t.width,t.height),s(t.toDataURL())}const n=e.poster,o=h(n);return s(await p(n,o,t))}(e,t):l(e,HTMLIFrameElement)?async function(e,t){var n;try{if(null===(n=null==e?void 0:e.contentDocument)||void 0===n?void 0:n.body)return await b(e.contentDocument.body,t,!0)}catch(e){}return e.cloneNode(!1)}(e,t):e.cloneNode(v(e))}(e,n)).then(o=>async function(e,n,o){var i,r;if(v(n))return n;let a=[];return a=(e=>null!=e.tagName&&"SLOT"===e.tagName.toUpperCase())(e)&&e.assignedNodes?t(e.assignedNodes()):l(e,HTMLIFrameElement)&&(null===(i=e.contentDocument)||void 0===i?void 0:i.body)?t(e.contentDocument.body.childNodes):t((null!==(r=e.shadowRoot)&&void 0!==r?r:e).childNodes),0===a.length||l(e,HTMLVideoElement)||await a.reduce((e,t)=>e.then(()=>b(t,o)).then(e=>{e&&n.appendChild(e)}),Promise.resolve()),n}(e,o,n)).then(t=>function(e,t,n){return l(t,Element)&&(function(e,t,n){const i=t.style;if(!i)return;const r=window.getComputedStyle(e);r.cssText?(i.cssText=r.cssText,i.transformOrigin=r.transformOrigin):o(n).forEach(n=>{let o=r.getPropertyValue(n);if("font-size"===n&&o.endsWith("px")){const e=Math.floor(parseFloat(o.substring(0,o.length-2)))-.1;o=`${e}px`}l(e,HTMLIFrameElement)&&"display"===n&&"inline"===o&&(o="block"),"d"===n&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),i.setProperty(n,o,r.getPropertyPriority(n))})}(e,t,n),function(e,t,n){c(e,t,":before",n),c(e,t,":after",n)}(e,t,n),function(e,t){l(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),l(e,HTMLInputElement)&&t.setAttribute("value",e.value)}(e,t),function(e,t){if(l(e,HTMLSelectElement)){const n=t,o=Array.from(n.children).find(t=>e.value===t.getAttribute("value"));o&&o.setAttribute("selected","")}}(e,t)),t}(e,t,n)).then(e=>async function(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(0===n.length)return e;const o={};for(let i=0;i<n.length;i++){const r=n[i].getAttribute("xlink:href");if(r){const n=e.querySelector(r),i=document.querySelector(r);n||!i||o[r]||(o[r]=await b(i,t,!0))}}const i=Object.values(o);if(i.length){const t="http://www.w3.org/1999/xhtml",n=document.createElementNS(t,"svg");n.setAttribute("xmlns",t),n.style.position="absolute",n.style.width="0",n.style.height="0",n.style.overflow="hidden",n.style.display="none";const o=document.createElementNS(t,"defs");n.appendChild(o);for(let e=0;e<i.length;e++)o.appendChild(i[e]);e.appendChild(n)}return e}(e,n)):null}var E=/url\((['"]?)([^'"]+?)\1\)/g,S=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,x=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function T(e){return-1!==e.search(E)}async function $(e,t,n){if(!T(e))return e;const o=function(e,{preferredFontFormat:t}){return t?e.replace(x,e=>{for(;;){const[n,,o]=S.exec(e)||[];if(!o)return"";if(o===t)return`src: ${n};`}}):e}(e,n),i=function(e){const t=[];return e.replace(E,(e,n,o)=>(t.push(o),e)),t.filter(e=>!f(e))}(o);return i.reduce((e,o)=>e.then(e=>async function(e,t,n,o){try{const i=n?function(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),o=n.createElement("base"),i=n.createElement("a");return n.head.appendChild(o),n.body.appendChild(i),t&&(o.href=t),i.href=e,i.href}(t,n):t,r=h(t);let a;return a=await p(i,r,o),e.replace(function(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}(t),`$1${a}$3`)}catch(e){}return e}(e,o,t,n)),Promise.resolve(o))}async function C(e,t,n){var o;const i=null===(o=t.style)||void 0===o?void 0:o.getPropertyValue(e);if(i){const o=await $(i,null,n);return t.style.setProperty(e,o,t.style.getPropertyPriority(e)),!0}return!1}async function P(e,n){l(e,Element)&&(await async function(e,t){await C("background",e,t)||await C("background-image",e,t),await C("mask",e,t)||await C("-webkit-mask",e,t)||await C("mask-image",e,t)||await C("-webkit-mask-image",e,t)}(e,n),await async function(e,t){const n=l(e,HTMLImageElement);if((!n||f(e.src))&&(!l(e,SVGImageElement)||f(e.href.baseVal)))return;const o=n?e.src:e.href.baseVal,i=await p(o,h(o),t);await new Promise((o,r)=>{e.onload=o,e.onerror=t.onImageErrorHandler?(...e)=>{try{o(t.onImageErrorHandler(...e))}catch(e){r(e)}}:r;const a=e;a.decode&&(a.decode=o),"lazy"===a.loading&&(a.loading="eager"),n?(e.srcset="",e.src=i):e.href.baseVal=i})}(e,n),await async function(e,n){const o=t(e.childNodes).map(e=>P(e,n));await Promise.all(o).then(()=>e)}(e,n))}var k={};async function L(e){let t=k[e];if(null!=t)return t;const n=await fetch(e);return t={url:e,cssText:await n.text()},k[e]=t,t}async function H(e,t){let n=e.cssText;const o=/url\(["']?([^"')]+)["']?\)/g,i=(n.match(/url\([^)]+\)/g)||[]).map(async i=>{let r=i.replace(o,"$1");return r.startsWith("https://")||(r=new URL(r,e.url).href),m(r,t.fetchRequestInit,({result:e})=>(n=n.replace(i,`url(${e})`),[i,e]))});return Promise.all(i).then(()=>n)}function R(e){if(null==e)return[];const t=[];let n=e.replace(/(\/\*[\s\S]*?\*\/)/gi,"");const o=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const e=o.exec(n);if(null===e)break;t.push(e[0])}n=n.replace(o,"");const i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,r=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let e=i.exec(n);if(null===e){if(e=r.exec(n),null===e)break;i.lastIndex=r.lastIndex}else r.lastIndex=i.lastIndex;t.push(e[0])}return t}function M(e){return e.trim().replace(/["']/g,"")}async function F(e,n={}){const{width:o,height:i}=r(e,n),a=await b(e,n,!0);return await async function(e,n){const o=null!=n.fontEmbedCSS?n.fontEmbedCSS:n.skipFonts?null:await async function(e,n){const o=await async function(e,n){if(null==e.ownerDocument)throw new Error("Provided element is not within a Document");const o=t(e.ownerDocument.styleSheets),i=await async function(e,n){const o=[],i=[];return e.forEach(o=>{if("cssRules"in o)try{t(o.cssRules||[]).forEach((e,t)=>{if(e.type===CSSRule.IMPORT_RULE){let r=t+1;const a=L(e.href).then(e=>H(e,n)).then(e=>R(e).forEach(e=>{try{o.insertRule(e,e.startsWith("@import")?r+=1:o.cssRules.length)}catch(t){console.error("Error inserting rule from remote css",{rule:e,error:t})}})).catch(e=>{console.error("Error loading remote css",e.toString())});i.push(a)}})}catch(t){const r=e.find(e=>null==e.href)||document.styleSheets[0];null!=o.href&&i.push(L(o.href).then(e=>H(e,n)).then(e=>R(e).forEach(e=>{r.insertRule(e,r.cssRules.length)})).catch(e=>{console.error("Error loading remote stylesheet",e)})),console.error("Error inlining remote css file",t)}}),Promise.all(i).then(()=>(e.forEach(e=>{if("cssRules"in e)try{t(e.cssRules||[]).forEach(e=>{o.push(e)})}catch(t){console.error(`Error while reading CSS rules from ${e.href}`,t)}}),o))}(o,n);return function(e){return e.filter(e=>e.type===CSSRule.FONT_FACE_RULE).filter(e=>T(e.style.getPropertyValue("src")))}(i)}(e,n),i=function(e){const t=new Set;return function e(n){(n.style.fontFamily||getComputedStyle(n).fontFamily).split(",").forEach(e=>{t.add(M(e))}),Array.from(n.children).forEach(t=>{t instanceof HTMLElement&&e(t)})}(e),t}(e);return(await Promise.all(o.filter(e=>i.has(M(e.style.fontFamily))).map(e=>{const t=e.parentStyleSheet?e.parentStyleSheet.href:null;return $(e.cssText,t,n)}))).join("\n")}(e,n);if(o){const t=document.createElement("style"),n=document.createTextNode(o);t.appendChild(n),e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}}(a,n),await P(a,n),function(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const o=t.style;null!=o&&Object.keys(o).forEach(e=>{n[e]=o[e]})}(a,n),await async function(e,t,n){const o="http://www.w3.org/2000/svg",i=document.createElementNS(o,"svg"),r=document.createElementNS(o,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${n}`),i.setAttribute("viewBox",`0 0 ${t} ${n}`),r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.setAttribute("x","0"),r.setAttribute("y","0"),r.setAttribute("externalResourcesRequired","true"),i.appendChild(r),r.appendChild(e),async function(e){return Promise.resolve().then(()=>(new XMLSerializer).serializeToString(e)).then(encodeURIComponent).then(e=>`data:image/svg+xml;charset=utf-8,${e}`)}(i)}(a,o,i)}var A={BOTTOM_RIGHT:{right:"0",bottom:"0"},BOTTOM_LEFT:{left:"0",bottom:"0"},TOP_RIGHT:{right:"0",top:"0"},TOP_LEFT:{left:"0",top:"0"}};function I(e,t,n){if(!e||e.length<5)throw new Error(`invalid surveyId! Please copy the correct surveyId from the tinyDialog dashboard. (surveyId=${e})`);const o=(n??document).querySelector(`#tinydialog-widget__${e}_auto iframe`);if(o)return console.debug(`skipping tinyDialog survey-load for ${e}, already loaded`),o.parentElement;let i=n;if(null==i){i=document.createElement("div"),i.className="tinydialog-floating-widget",i.id=`tinydialog-widget__${e}_auto`,i.dataset.tinydialogWidget=e,i.style.position="fixed";for(const[e,n]of Object.entries(A[t?.side??"BOTTOM_RIGHT"]))i.style.setProperty(e,n);i.style.overflow="hidden",i.style.visibility="hidden",i.style.transitionProperty="opacity, transform, height",i.style.transitionDuration="200ms",i.style.transform="scale(0.75)",i.style.opacity="0",i.style.zIndex="100"}let l=t?.user?.trim();0===l?.length&&(l=void 0);let c=`https://app.tinydialog.com/widget/v1/${e}?parent=${encodeURIComponent(window.location.href)}&sdkVersion=${encodeURIComponent("0.0.1-rc.8")}`;l&&(c+=`&user=${l}`);for(const[e,n]of Object.entries(t?.extraData??{}))null!=e&&0!==e.trim().length&&0!==n.trim().length&&(c+=`&extra-${e}=${n}`);const d=i.querySelector("iframe")??document.createElement("iframe");d.src=c,d.style.transitionProperty="height",d.style.transitionDuration="150ms",d.style.height="100%",d.style.minWidth="350px",d.style.border="none",d.ariaLabel="tinyDialog survey widget";const u=async t=>{if(t.data.targetWidget===e)if("tinydialog--hello"===t.data.event)d.contentWindow?.postMessage({event:"tinydialog--screenSize",data:{screenSizeWidth:window.innerWidth,screenSizeHeight:window.innerHeight}},"*");else if("tinydialog--updateHeight"===t.data.event&&t.data.data)i.style.height=t.data.data+"px";else if("tinydialog--close"===t.data.event)O(t.data.targetWidget);else if("tinydialog--requestScreenshot"===t.data.event)try{const e=await async function(e,t={}){const{width:n,height:o}=r(e,t),i=await F(e,t),l=await s(i),c=document.createElement("canvas"),d=c.getContext("2d"),u=t.pixelRatio||function(){let e,t;try{t=process}catch(e){}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}(),g=t.canvasWidth||n,h=t.canvasHeight||o;return c.width=g*u,c.height=h*u,t.skipAutoScale||function(e){(e.width>a||e.height>a)&&(e.width>a&&e.height>a?e.width>e.height?(e.height*=a/e.width,e.width=a):(e.width*=a/e.height,e.height=a):e.width>a?(e.height*=a/e.width,e.width=a):(e.width*=a/e.height,e.height=a))}(c),c.style.width=`${g}`,c.style.height=`${h}`,t.backgroundColor&&(d.fillStyle=t.backgroundColor,d.fillRect(0,0,c.width,c.height)),d.drawImage(l,0,0,c.width,c.height),c}(document.body,{skipAutoScale:!0,skipFonts:navigator.userAgent?.includes("Firefox")??!0,includeQueryParams:!0,width:window.innerWidth,height:window.innerHeight,canvasWidth:window.innerWidth*Math.min(1,1080/window.innerWidth),canvasHeight:window.innerHeight*Math.min(1,1080/window.innerWidth),backgroundColor:document.body.style.backgroundColor.length>0?window.getComputedStyle(document.body,null).getPropertyValue("background-color"):"rgb(255, 255, 255, 1)",style:{transform:`translate(-${window.scrollX}px, -${window.scrollY}px)`,width:`${window.innerWidth}px`,height:`${window.innerHeight}px`}}),t=await new Promise((t,n)=>{try{e.toBlob(e=>t(e),"image/jpeg",.35)}catch(e){n(e)}});if(!t)return void console.error("could not take screenshot, img null");if(!d.contentWindow)return void console.error("no iframe.contentWindow");d.contentWindow.postMessage({event:"tinydialog--screenshot",data:t},"*")}catch(e){console.error("failed taking screenshot of webpage",e)}};window.removeEventListener("message",u),window.addEventListener("message",u),i.appendChild(d),n||document.body.append(i);const g=B(()=>{d.contentWindow?.postMessage({event:"tinydialog--screenSize",data:{screenSizeWidth:window.innerWidth,screenSizeHeight:window.innerHeight}},"*")},150);return window.removeEventListener("resize",g),window.addEventListener("resize",g),i}function W(e,t,n=0){document.querySelectorAll('[data-tinydialog-widget-visible="true"]').forEach(e=>{const t=e.dataset.tinydialogWidget;t?O(t):console.warn("visibleWidget to close had no surveyId!",e)});let o=document.querySelector(`[data-tinydialog-widget='${e}']`);if(o??=I(e,t),o instanceof HTMLElement)if(!o.style.height&&n<=25)setTimeout(()=>W(e,t,n+1),30+75*n);else{for(const[e,n]of Object.entries(A[t?.side??"BOTTOM_RIGHT"]))o.style.setProperty(e,n);o.dataset.tinydialogWidgetVisible="true",o.style.visibility="visible",o.style.transform="scale(1.0)",o.style.opacity="1"}else console.warn("tried opening widget, but widgetContainer was not a HTMLElement")}function O(e){const t=document.querySelector(`[data-tinydialog-widget='${e}']`);t?t instanceof HTMLElement?(t.style.transform="scale(0.75)",t.style.opacity="0",t.style.visibility="hidden",t.removeAttribute("data-tinydialog-widget-visible")):console.warn("tried opening widget, but widgetContainer was not a HTMLElement"):console.debug(`tried closing widget with id ${e} which does not exist on page`)}function N(e){e.currentTarget instanceof HTMLElement&&W(e.currentTarget.dataset.tinydialogOpenwidget,{side:e.currentTarget.dataset.tinydialogWidgetSide?.toUpperCase()})}function D(){q?.dataset.tinydialogFloatingButton&&function(e){const t=e.tinydialogFloatingButton;if(!t||t.length<10)return void console.warn('invalid surveyId configured in "data-tinydialog-floating-button"');if(document.querySelector("#tinydialog-floating-button__auto"))return void console.debug("prevented duplicate autoCreateFloatingButton execution, button alreadx exists");const n=document.createElement("button");n.id="tinydialog-floating-button__auto",n.style.position="fixed",n.style.right="20px",n.style.bottom="20px",n.style.width="48px",n.style.height="48px",n.style.background=e.tinydialogFloatingButtonBackground??"black",n.style.color=e.tinydialogFloatingButtonForeground??"white",n.style.borderRadius="100%",n.style.padding="8px",n.style.cursor="pointer",n.style.transitionDuration="300ms",n.style.transitionProperty="all",n.dataset.tinydialogOpenwidget=t,n.addEventListener("mouseenter",()=>{n.style.background=e.tinydialogFloatingButtonBackgroundHover??"#E2187D",n.style.color=e.tinydialogFloatingButtonForegroundHover??"white"}),n.addEventListener("mouseleave",()=>{n.style.background=e.tinydialogFloatingButtonBackground??"black",n.style.color=e.tinydialogFloatingButtonForeground??"white"});const o=document.createElement("svg");n.append(o),o.outerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',document.body.append(n)}(q.dataset),document.querySelectorAll("[data-tinydialog-openwidget]").forEach(e=>{e instanceof HTMLElement&&(I(e.dataset.tinydialogOpenwidget,{side:e.dataset.tinydialogWidgetSide?.toUpperCase(),user:e.dataset.tinydialogUser??q?.dataset.tinydialogUser}),e.removeEventListener("click",N),e.addEventListener("click",N))}),document.querySelectorAll("[data-tinydialog-widgetcontainer]").forEach(e=>{e instanceof HTMLElement?I(e.dataset.tinydialogWidgetcontainer,{user:e.dataset.tinydialogUser??q?.dataset.tinydialogUser},e):console.debug("tinyDialog widgetContainer is not a HTMLElement",e)})}var B=(e,t)=>{let n;return(...o)=>{clearTimeout(n),n=setTimeout(()=>{e(...o)},t)}},q=document.currentScript;onload=()=>{q??=document.currentScript},D(),function(){if("navigation"in window)window.navigation.addEventListener("navigate",()=>{requestAnimationFrame(()=>{D()})});else{let e=location.href;new MutationObserver(()=>{e!==location.href&&(e=location.href,requestAnimationFrame(()=>{D()}))}).observe(document,{subtree:!0,childList:!0})}}()})();
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";var e,t=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,a={};((e,i)=>{for(var n in i)t(e,n,{get:i[n],enumerable:!0})})(a,{bindSurveysWithDataAttributes:()=>
|
|
1
|
+
"use client";"use strict";var e,t=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,a={};((e,i)=>{for(var n in i)t(e,n,{get:i[n],enumerable:!0})})(a,{bindSurveysWithDataAttributes:()=>y,closeWidget:()=>g,loadSurvey:()=>l,showWidget:()=>c}),module.exports=(e=a,((e,a,r,d)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of n(a))o.call(e,r)||void 0===r||t(e,r,{get:()=>a[r],enumerable:!(d=i(a,r))||d.enumerable});return e})(t({},"__esModule",{value:!0}),e));var r=require("html-to-image"),d="0.0.1-rc.8",s={BOTTOM_RIGHT:{right:"0",bottom:"0"},BOTTOM_LEFT:{left:"0",bottom:"0"},TOP_RIGHT:{right:"0",top:"0"},TOP_LEFT:{left:"0",top:"0"}};function l(e,t,i){if(!e||e.length<5)throw new Error(`invalid surveyId! Please copy the correct surveyId from the tinyDialog dashboard. (surveyId=${e})`);const n=(i??document).querySelector(`#tinydialog-widget__${e}_auto iframe`);if(n)return console.debug(`skipping tinyDialog survey-load for ${e}, already loaded`),n.parentElement;let o=i;if(null==o){o=document.createElement("div"),o.className="tinydialog-floating-widget",o.id=`tinydialog-widget__${e}_auto`,o.dataset.tinydialogWidget=e,o.style.position="fixed";for(const[e,i]of Object.entries(s[t?.side??"BOTTOM_RIGHT"]))o.style.setProperty(e,i);o.style.overflow="hidden",o.style.visibility="hidden",o.style.transitionProperty="opacity, transform, height",o.style.transitionDuration="200ms",o.style.transform="scale(0.75)",o.style.opacity="0",o.style.zIndex="100"}let a=t?.user?.trim();0===a?.length&&(a=void 0);let l=`https://app.tinydialog.com/widget/v1/${e}?parent=${encodeURIComponent(window.location.href)}&sdkVersion=${encodeURIComponent(d)}`;a&&(l+=`&user=${a}`);for(const[e,i]of Object.entries(t?.extraData??{}))null!=e&&0!==e.trim().length&&0!==i.trim().length&&(l+=`&extra-${e}=${i}`);const c=o.querySelector("iframe")??document.createElement("iframe");c.src=l,c.style.transitionProperty="height",c.style.transitionDuration="150ms",c.style.height="100%",c.style.minWidth="350px",c.style.border="none",c.ariaLabel="tinyDialog survey widget";const u=async t=>{if(t.data.targetWidget===e)if("tinydialog--hello"===t.data.event)c.contentWindow?.postMessage({event:"tinydialog--screenSize",data:{screenSizeWidth:window.innerWidth,screenSizeHeight:window.innerHeight}},"*");else if("tinydialog--updateHeight"===t.data.event&&t.data.data)o.style.height=t.data.data+"px";else if("tinydialog--close"===t.data.event)g(t.data.targetWidget);else if("tinydialog--requestScreenshot"===t.data.event)try{const e=await(0,r.toCanvas)(document.body,{skipAutoScale:!0,skipFonts:navigator.userAgent?.includes("Firefox")??!0,includeQueryParams:!0,width:window.innerWidth,height:window.innerHeight,canvasWidth:window.innerWidth*Math.min(1,1080/window.innerWidth),canvasHeight:window.innerHeight*Math.min(1,1080/window.innerWidth),backgroundColor:document.body.style.backgroundColor.length>0?window.getComputedStyle(document.body,null).getPropertyValue("background-color"):"rgb(255, 255, 255, 1)",style:{transform:`translate(-${window.scrollX}px, -${window.scrollY}px)`,width:`${window.innerWidth}px`,height:`${window.innerHeight}px`}}),t=await new Promise((t,i)=>{try{e.toBlob(e=>t(e),"image/jpeg",.35)}catch(e){i(e)}});if(!t)return void console.error("could not take screenshot, img null");if(!c.contentWindow)return void console.error("no iframe.contentWindow");c.contentWindow.postMessage({event:"tinydialog--screenshot",data:t},"*")}catch(e){console.error("failed taking screenshot of webpage",e)}};window.removeEventListener("message",u),window.addEventListener("message",u),o.appendChild(c),i||document.body.append(o);const y=w(()=>{c.contentWindow?.postMessage({event:"tinydialog--screenSize",data:{screenSizeWidth:window.innerWidth,screenSizeHeight:window.innerHeight}},"*")},150);return window.removeEventListener("resize",y),window.addEventListener("resize",y),o}function c(e,t,i=0){document.querySelectorAll('[data-tinydialog-widget-visible="true"]').forEach(e=>{const t=e.dataset.tinydialogWidget;t?g(t):console.warn("visibleWidget to close had no surveyId!",e)});let n=document.querySelector(`[data-tinydialog-widget='${e}']`);if(n??=l(e,t),n instanceof HTMLElement)if(!n.style.height&&i<=25)setTimeout(()=>c(e,t,i+1),30+75*i);else{for(const[e,i]of Object.entries(s[t?.side??"BOTTOM_RIGHT"]))n.style.setProperty(e,i);n.dataset.tinydialogWidgetVisible="true",n.style.visibility="visible",n.style.transform="scale(1.0)",n.style.opacity="1"}else console.warn("tried opening widget, but widgetContainer was not a HTMLElement")}function g(e){const t=document.querySelector(`[data-tinydialog-widget='${e}']`);t?t instanceof HTMLElement?(t.style.transform="scale(0.75)",t.style.opacity="0",t.style.visibility="hidden",t.removeAttribute("data-tinydialog-widget-visible")):console.warn("tried opening widget, but widgetContainer was not a HTMLElement"):console.debug(`tried closing widget with id ${e} which does not exist on page`)}function u(e){e.currentTarget instanceof HTMLElement&&c(e.currentTarget.dataset.tinydialogOpenwidget,{side:e.currentTarget.dataset.tinydialogWidgetSide?.toUpperCase()})}function y(){h?.dataset.tinydialogFloatingButton&&function(e){const t=e.tinydialogFloatingButton;if(!t||t.length<10)return void console.warn('invalid surveyId configured in "data-tinydialog-floating-button"');if(document.querySelector("#tinydialog-floating-button__auto"))return void console.debug("prevented duplicate autoCreateFloatingButton execution, button alreadx exists");const i=document.createElement("button");i.id="tinydialog-floating-button__auto",i.style.position="fixed",i.style.right="20px",i.style.bottom="20px",i.style.width="48px",i.style.height="48px",i.style.background=e.tinydialogFloatingButtonBackground??"black",i.style.color=e.tinydialogFloatingButtonForeground??"white",i.style.borderRadius="100%",i.style.padding="8px",i.style.cursor="pointer",i.style.transitionDuration="300ms",i.style.transitionProperty="all",i.dataset.tinydialogOpenwidget=t,i.addEventListener("mouseenter",()=>{i.style.background=e.tinydialogFloatingButtonBackgroundHover??"#E2187D",i.style.color=e.tinydialogFloatingButtonForegroundHover??"white"}),i.addEventListener("mouseleave",()=>{i.style.background=e.tinydialogFloatingButtonBackground??"black",i.style.color=e.tinydialogFloatingButtonForeground??"white"});const n=document.createElement("svg");i.append(n),n.outerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',document.body.append(i)}(h.dataset),document.querySelectorAll("[data-tinydialog-openwidget]").forEach(e=>{e instanceof HTMLElement&&(l(e.dataset.tinydialogOpenwidget,{side:e.dataset.tinydialogWidgetSide?.toUpperCase(),user:e.dataset.tinydialogUser??h?.dataset.tinydialogUser}),e.removeEventListener("click",u),e.addEventListener("click",u))}),document.querySelectorAll("[data-tinydialog-widgetcontainer]").forEach(e=>{e instanceof HTMLElement?l(e.dataset.tinydialogWidgetcontainer,{user:e.dataset.tinydialogUser??h?.dataset.tinydialogUser},e):console.debug("tinyDialog widgetContainer is not a HTMLElement",e)})}var w=(e,t)=>{let i;return(...n)=>{clearTimeout(i),i=setTimeout(()=>{e(...n)},t)}},h=document.currentScript;onload=()=>{h??=document.currentScript},y(),function(){if("navigation"in window)window.navigation.addEventListener("navigate",()=>{requestAnimationFrame(()=>{y()})});else{let e=location.href;new MutationObserver(()=>{e!==location.href&&(e=location.href,requestAnimationFrame(()=>{y()}))}).observe(document,{subtree:!0,childList:!0})}}();
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{toCanvas as t}from"html-to-image";var e={BOTTOM_RIGHT:{right:"0",bottom:"0"},BOTTOM_LEFT:{left:"0",bottom:"0"},TOP_RIGHT:{right:"0",top:"0"},TOP_LEFT:{left:"0",top:"0"}};function i(i,n,a){if(!i||i.length<5)throw new Error(`invalid surveyId! Please copy the correct surveyId from the tinyDialog dashboard. (surveyId=${i})`);const r=(a??document).querySelector(`#tinydialog-widget__${i}_auto iframe`);if(r)return console.debug(`skipping tinyDialog survey-load for ${i}, already loaded`),r.parentElement;let
|
|
1
|
+
"use client";import{toCanvas as t}from"html-to-image";var e={BOTTOM_RIGHT:{right:"0",bottom:"0"},BOTTOM_LEFT:{left:"0",bottom:"0"},TOP_RIGHT:{right:"0",top:"0"},TOP_LEFT:{left:"0",top:"0"}};function i(i,n,a){if(!i||i.length<5)throw new Error(`invalid surveyId! Please copy the correct surveyId from the tinyDialog dashboard. (surveyId=${i})`);const r=(a??document).querySelector(`#tinydialog-widget__${i}_auto iframe`);if(r)return console.debug(`skipping tinyDialog survey-load for ${i}, already loaded`),r.parentElement;let s=a;if(null==s){s=document.createElement("div"),s.className="tinydialog-floating-widget",s.id=`tinydialog-widget__${i}_auto`,s.dataset.tinydialogWidget=i,s.style.position="fixed";for(const[t,i]of Object.entries(e[n?.side??"BOTTOM_RIGHT"]))s.style.setProperty(t,i);s.style.overflow="hidden",s.style.visibility="hidden",s.style.transitionProperty="opacity, transform, height",s.style.transitionDuration="200ms",s.style.transform="scale(0.75)",s.style.opacity="0",s.style.zIndex="100"}let l=n?.user?.trim();0===l?.length&&(l=void 0);let g=`https://app.tinydialog.com/widget/v1/${i}?parent=${encodeURIComponent(window.location.href)}&sdkVersion=${encodeURIComponent("0.0.1-rc.8")}`;l&&(g+=`&user=${l}`);for(const[t,e]of Object.entries(n?.extraData??{}))null!=t&&0!==t.trim().length&&0!==e.trim().length&&(g+=`&extra-${t}=${e}`);const c=s.querySelector("iframe")??document.createElement("iframe");c.src=g,c.style.transitionProperty="height",c.style.transitionDuration="150ms",c.style.height="100%",c.style.minWidth="350px",c.style.border="none",c.ariaLabel="tinyDialog survey widget";const u=async e=>{if(e.data.targetWidget===i)if("tinydialog--hello"===e.data.event)c.contentWindow?.postMessage({event:"tinydialog--screenSize",data:{screenSizeWidth:window.innerWidth,screenSizeHeight:window.innerHeight}},"*");else if("tinydialog--updateHeight"===e.data.event&&e.data.data)s.style.height=e.data.data+"px";else if("tinydialog--close"===e.data.event)o(e.data.targetWidget);else if("tinydialog--requestScreenshot"===e.data.event)try{const e=await t(document.body,{skipAutoScale:!0,skipFonts:navigator.userAgent?.includes("Firefox")??!0,includeQueryParams:!0,width:window.innerWidth,height:window.innerHeight,canvasWidth:window.innerWidth*Math.min(1,1080/window.innerWidth),canvasHeight:window.innerHeight*Math.min(1,1080/window.innerWidth),backgroundColor:document.body.style.backgroundColor.length>0?window.getComputedStyle(document.body,null).getPropertyValue("background-color"):"rgb(255, 255, 255, 1)",style:{transform:`translate(-${window.scrollX}px, -${window.scrollY}px)`,width:`${window.innerWidth}px`,height:`${window.innerHeight}px`}}),i=await new Promise((t,i)=>{try{e.toBlob(e=>t(e),"image/jpeg",.35)}catch(t){i(t)}});if(!i)return void console.error("could not take screenshot, img null");if(!c.contentWindow)return void console.error("no iframe.contentWindow");c.contentWindow.postMessage({event:"tinydialog--screenshot",data:i},"*")}catch(t){console.error("failed taking screenshot of webpage",t)}};window.removeEventListener("message",u),window.addEventListener("message",u),s.appendChild(c),a||document.body.append(s);const y=d(()=>{c.contentWindow?.postMessage({event:"tinydialog--screenSize",data:{screenSizeWidth:window.innerWidth,screenSizeHeight:window.innerHeight}},"*")},150);return window.removeEventListener("resize",y),window.addEventListener("resize",y),s}function n(t,a,r=0){document.querySelectorAll('[data-tinydialog-widget-visible="true"]').forEach(t=>{const e=t.dataset.tinydialogWidget;e?o(e):console.warn("visibleWidget to close had no surveyId!",t)});let d=document.querySelector(`[data-tinydialog-widget='${t}']`);if(d??=i(t,a),d instanceof HTMLElement)if(!d.style.height&&r<=25)setTimeout(()=>n(t,a,r+1),30+75*r);else{for(const[t,i]of Object.entries(e[a?.side??"BOTTOM_RIGHT"]))d.style.setProperty(t,i);d.dataset.tinydialogWidgetVisible="true",d.style.visibility="visible",d.style.transform="scale(1.0)",d.style.opacity="1"}else console.warn("tried opening widget, but widgetContainer was not a HTMLElement")}function o(t){const e=document.querySelector(`[data-tinydialog-widget='${t}']`);e?e instanceof HTMLElement?(e.style.transform="scale(0.75)",e.style.opacity="0",e.style.visibility="hidden",e.removeAttribute("data-tinydialog-widget-visible")):console.warn("tried opening widget, but widgetContainer was not a HTMLElement"):console.debug(`tried closing widget with id ${t} which does not exist on page`)}function a(t){t.currentTarget instanceof HTMLElement&&n(t.currentTarget.dataset.tinydialogOpenwidget,{side:t.currentTarget.dataset.tinydialogWidgetSide?.toUpperCase()})}function r(){s?.dataset.tinydialogFloatingButton&&function(t){const e=t.tinydialogFloatingButton;if(!e||e.length<10)return void console.warn('invalid surveyId configured in "data-tinydialog-floating-button"');if(document.querySelector("#tinydialog-floating-button__auto"))return void console.debug("prevented duplicate autoCreateFloatingButton execution, button alreadx exists");const i=document.createElement("button");i.id="tinydialog-floating-button__auto",i.style.position="fixed",i.style.right="20px",i.style.bottom="20px",i.style.width="48px",i.style.height="48px",i.style.background=t.tinydialogFloatingButtonBackground??"black",i.style.color=t.tinydialogFloatingButtonForeground??"white",i.style.borderRadius="100%",i.style.padding="8px",i.style.cursor="pointer",i.style.transitionDuration="300ms",i.style.transitionProperty="all",i.dataset.tinydialogOpenwidget=e,i.addEventListener("mouseenter",()=>{i.style.background=t.tinydialogFloatingButtonBackgroundHover??"#E2187D",i.style.color=t.tinydialogFloatingButtonForegroundHover??"white"}),i.addEventListener("mouseleave",()=>{i.style.background=t.tinydialogFloatingButtonBackground??"black",i.style.color=t.tinydialogFloatingButtonForeground??"white"});const n=document.createElement("svg");i.append(n),n.outerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',document.body.append(i)}(s.dataset),document.querySelectorAll("[data-tinydialog-openwidget]").forEach(t=>{t instanceof HTMLElement&&(i(t.dataset.tinydialogOpenwidget,{side:t.dataset.tinydialogWidgetSide?.toUpperCase(),user:t.dataset.tinydialogUser??s?.dataset.tinydialogUser}),t.removeEventListener("click",a),t.addEventListener("click",a))}),document.querySelectorAll("[data-tinydialog-widgetcontainer]").forEach(t=>{t instanceof HTMLElement?i(t.dataset.tinydialogWidgetcontainer,{user:t.dataset.tinydialogUser??s?.dataset.tinydialogUser},t):console.debug("tinyDialog widgetContainer is not a HTMLElement",t)})}var d=(t,e)=>{let i;return(...n)=>{clearTimeout(i),i=setTimeout(()=>{t(...n)},e)}},s=document.currentScript;onload=()=>{s??=document.currentScript},r(),function(){if("navigation"in window)window.navigation.addEventListener("navigate",()=>{requestAnimationFrame(()=>{r()})});else{let t=location.href;new MutationObserver(()=>{t!==location.href&&(t=location.href,requestAnimationFrame(()=>{r()}))}).observe(document,{subtree:!0,childList:!0})}}();export{r as bindSurveysWithDataAttributes,o as closeWidget,i as loadSurvey,n as showWidget};
|