@magicfeedback/native 1.2.8-beta.9 → 1.2.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.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(self,(()=>{return e={98:function(e,t){var i="undefined"!=typeof self?self:this,n=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,a="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,r="ArrayBuffer"in e;if(r)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],d=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function p(e){this.map={},e instanceof p?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function h(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function m(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function f(e){var t=new FileReader,i=m(t);return t.readAsArrayBuffer(e),i}function g(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:a&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&a&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r&&(ArrayBuffer.prototype.isPrototypeOf(e)||d(e))?this._bodyArrayBuffer=g(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a&&(this.blob=function(){var e=h(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?h(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var e,t,i,n=h(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,i=m(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),n=0;n<t.length;n++)i[n]=String.fromCharCode(t[n]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=c(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[c(e)]},p.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},p.prototype.set=function(e,t){this.map[c(e)]=l(t)},p.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},p.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},p.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},p.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},n&&(p.prototype[Symbol.iterator]=p.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,n,a=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new p(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,a||null==e._bodyInit||(a=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new p(t.headers)),this.method=(n=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(n)>-1?n:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&a)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(a)}function E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),n=i.shift().replace(/\+/g," "),a=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(a))}})),t}function k(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new p(t.headers),this.url=t.url||"",this._initBody(e)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},b.call(v.prototype),b.call(k.prototype),k.prototype.clone=function(){return new k(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new p(this.headers),url:this.url})},k.error=function(){var e=new k(null,{status:0,statusText:""});return e.type="error",e};var x=[301,302,303,307,308];k.redirect=function(e,t){if(-1===x.indexOf(t))throw new RangeError("Invalid status code");return new k(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function C(e,i){return new Promise((function(n,s){var r=new v(e,i);if(r.signal&&r.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function d(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new p,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),n=i.shift().trim();if(n){var a=i.join(":").trim();t.append(n,a)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var a="response"in o?o.response:o.responseText;n(new k(a,i))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(r.method,r.url,!0),"include"===r.credentials?o.withCredentials=!0:"omit"===r.credentials&&(o.withCredentials=!1),"responseType"in o&&a&&(o.responseType="blob"),r.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),r.signal&&(r.signal.addEventListener("abort",d),o.onreadystatechange=function(){4===o.readyState&&r.signal.removeEventListener("abort",d)}),o.send(void 0===r._bodyInit?null:r._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=p,e.Request=v,e.Response=k),t.Headers=p,t.Request=v,t.Response=k,t.fetch=C,Object.defineProperty(t,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var a=n;(t=a.fetch).default=a.fetch,t.fetch=a.fetch,t.Headers=a.Headers,t.Request=a.Request,t.Response=a.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(i(519));let s=null;s||(s=(0,a.default)()),t.default=s},519:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{d(n.next(e))}catch(e){s(e)}}function o(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(954),s=i(712),r=i(5),o=i(341),d=i(290);t.default=function(){const e=new s.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?d.HOST_API_URL_DEV:d.HOST_API_URL),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,r=!0,d,c){return n(this,void 0,void 0,(function*(){i||t.err("No appID provided"),a||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const n=e.get("url"),l={integration:i,publicKey:a,privateKey:c,completed:r,id:d,feedback:s};try{const e=yield(0,o.sendFeedback)(n,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,n){return i||t.err("No appID provided"),n||t.err("No publicKey provided"),new a.Form(e,i,n)}}}},314:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.History=void 0,t.History=class{constructor(){this.items=[]}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}rollback(){return this.items.pop()}front(){return this.items[0]}back(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}}},712:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{d(n.next(e))}catch(e){s(e)}}function o(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(5),s=i(341),r=i(183),o=i(24),d=i(804),c=i(116),l=i(314),u=i(457);t.Form=class{constructor(e,t,i){this.config=e,this.log=new a.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.getDataFromStorage(),this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new l.History,this.graph=new o.PageGraph([]),this.progress=0,this.total=0,this.followup=!1}getDataFromStorage(){const e=localStorage.getItem(`magicfeedback-${this.appId}`);e&&new Date(JSON.parse(e).savedAt)<new Date((new Date).getTime()+864e5)&&(this.formData=JSON.parse(e),(0,s.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,n;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),(null===(n=this.formData.style)||void 0===n?void 0:n.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm())})))}generate(e,t){var i,a,r;return n(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e,void 0!==this.formData&&this.formData||(this.formData=yield(0,s.getForm)(this.url,this.appId,this.publicKey,this.log)),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),void 0===this.formData.questions||!this.formData.questions)throw new Error(`No questions for app ${this.appId}`);0===(null===(i=this.formData.pages)||void 0===i?void 0:i.length)&&this.formatPages(),null===(a=this.formData.questions)||void 0===a||a.sort(((e,t)=>e.position-t.position)),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(r=this.formData.style)||void 0===r?void 0:r.startMessage)?yield this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}formatPages(){var e;if(this.formData)switch(this.formData.identity){case"MAGICSURVEY":this.formData.pages=[],null===(e=this.formData.questions)||void 0===e||e.forEach((e=>{var t,i;const n=new c.PageRoute(e.id,e.ref,c.OperatorType.NOEQUAL,null,c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),a=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(a)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,a;return n(this,void 0,void 0,(function*(){try{if(this.formData&&(null===(e=this.formData.pages)||void 0===e?void 0:e.length)>0){this.graph=new o.PageGraph(this.formData.pages.sort(((e,t)=>e.position-t.position)));let e=this.generateContainer();const n=document.createElement("form");n.classList.add("magicfeedback-form"),n.id="magicfeedback-"+this.appId;const s=document.createElement("div");s.classList.add("magicfeedback-questions"),s.id="magicfeedback-questions-"+this.appId;const d=this.graph.getFirstPage();if(!d)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),d.elements=(0,r.renderQuestions)(d.questions,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],(()=>this.send())),null===(i=d.elements)||void 0===i||i.forEach((e=>s.appendChild(e))),n.appendChild(s),this.history.enqueue(d),e.appendChild(n),this.formOptionsConfig.addButton){const e=(0,r.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);n.appendChild(e)}n.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData}))}}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}startForm(){this.generateForm()}generateWelcomeMessage(e){return n(this,void 0,void 0,(function*(){try{const t=this.generateContainer(),i=(0,r.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){return n(this,void 0,void 0,(function*(){const n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const a=this.history.back();if(!a)throw new Error("No page found");const s=a.getRequiredQuestions();for(const e of s)if(!this.feedback.answers.find((t=>t.key===e&&t.value.length>0)))return void this.log.err(`The question ${e} is required`);const r=yield this.pushAnswers(!1);r&&(this.id=r,yield this.processNextQuestion(n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:r,loading:!1,progress:this.progress,total:this.total,followup:this.followup,error:r?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;const n=e.querySelectorAll(".magicfeedback-input");n.forEach((e=>{const a=e.type,r=e.classList[0],o={key:e.name,value:[]},d="magicfeedback-consent"===r?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(a){case"radio":case"checkbox":if("magicfeedback-consent"===r||e.checked){if(e.id.includes("matrix")){const t=e.id.split("-")[e.id.split("-").length-1];let i="";n.forEach((e=>{e.checked&&e.id.includes(`matrix-${t}`)&&(i+=e.value+", ")})),i=i.slice(0,-2),o.value.push(`${t}: ${i}`)}else o.value.push(d);const i=t.findIndex((e=>e.key===o.key));-1!==i?t[i].value=[...t[i].value,...o.value]:t.push(o)}break;default:if(""!==d){if("email"===a){if(!(0,s.validateEmail)(d)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[d]})}if(e.id.includes("point-system")){const t=e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${d}%`)}else o.value.push(d);const n=t.findIndex((e=>e.key===o.key));-1!==n?t[n].value=[...t[n].value,...o.value]:t.push(o)}}})),this.feedback.answers=i?[]:t}finish(){if(this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer(),this.pushAnswers(!0)}pushAnswers(e=!1){return n(this,void 0,void 0,(function*(){try{const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){var t;return n(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),n={answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,s.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const a=n.getFollowupQuestions();if((null==a?void 0:a.length)>0){const s=[];for(const e of a){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&s.push(e)}}if(s.length>0){this.followup=!0;const a=new d.Page(n.id,n.position,this.appId,s,n.edges),o=new u.PageNode(n.id,n.position,n.edges,a,s);o.elements=(0,r.renderQuestions)(s,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],(()=>this.send())),this.history.enqueue(o),e.removeChild(e.childNodes[0]),null===(i=o.elements)||void 0===i||i.forEach((t=>e.appendChild(t)))}else this.renderNextQuestion(e,n)}else this.renderNextQuestion(e,n)}))}renderNextQuestion(e,t){var i,n;this.followup=!1;const a=this.graph.getNextPage(t,this.feedback.answers);a?(this.progress=this.total-this.graph.findDepth(a.id),a.elements=(0,r.renderQuestions)(a.questions,this.formOptionsConfig.questionFormat,null===(i=this.formData)||void 0===i?void 0:i.lang[0],(()=>this.send())),e.removeChild(e.childNodes[0]),null===(n=a.elements)||void 0===n||n.forEach((t=>e.appendChild(t))),this.history.enqueue(a)):this.finish()}back(){var e;if(0===this.history.size())return;console.log("Back",this.history);const t=document.getElementById("magicfeedback-questions-"+this.appId);t&&t.childNodes.length>0&&t.removeChild(t.childNodes[0]),this.history.rollback();const i=this.history.back();i&&(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e))))}}},804:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Page=void 0,t.Page=class{constructor(e,t,i,n,a){this.id=e,this.position=t,this.generatedAt=(new Date).toISOString(),this.updatedAt=(new Date).getTime(),this.status="ACTIVE",this.integrationId=i,this.integrationQuestions=n,this.integrationPageRoutes=a}}},24:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(457),a=i(116);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach((e=>{const t=new n.PageNode(e.id,e.position,e.integrationPageRoutes||[],e,e.integrationQuestions);this.nodes.set(t.id,t)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(e)for(const t of this.nodes.values())if(t.position===e.position+1)return t.id}getFirstPage(){let e,t=Number.MAX_VALUE;for(const i of this.nodes.values())i.position<t&&(t=i.position,e=i);return e}getNextPage(e,t){if(!e)return;const i=e.edges.find((e=>{const i=null==t?void 0:t.filter((t=>t.key===e.questionRef));if(!i)return!1;switch(e.typeOperator){case a.OperatorType.EQUAL:return i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case a.OperatorType.NOEQUAL:return!i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case a.OperatorType.GREATER:return i.find((t=>t.value.find((t=>Number(t)>Number(e.value)))));case a.OperatorType.LESS:return i.find((t=>t.value.find((t=>Number(t)<Number(e.value)))));case a.OperatorType.GREATEREQUAL:return console.log(i),i.find((t=>t.value.find((t=>Number(t)>=Number(e.value)))));case a.OperatorType.LESSEQUAL:return i.find((t=>t.value.find((t=>Number(t)<=Number(e.value)))));case a.OperatorType.INQ:return i.find((t=>e.value.includes(t.value)));case a.OperatorType.NINQ:return!i.find((t=>e.value.includes(t.value)));default:return!1}}));if(!i){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}return this.getNodeById(i.transitionDestiny)}findDepth(e){const t=this.getNodeById(e);if(!t)return 0;const i=new Set;return this.DFSUtil(t,i,0)}findMaxDepth(){const e=new Set;let t=0;return this.nodes.forEach((i=>{e.has(i)||(t=Math.max(t,this.DFSUtil(i,e,0)))})),t}DFSUtil(e,t,i){t.add(e);let n=i;const a=this.getNextEdgeByDefault(e);for(const s of a?[...e.edges,{transitionDestiny:a}]:e.edges){const e=this.getNodeById(s.transitionDestiny);e&&!t.has(e)&&(n=Math.max(n,this.DFSUtil(e,t,i+1)))}return n}}},457:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,a){this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=a,this.elements=[]}getFollowupQuestions(){return this.questions.filter((e=>e.followup)).map((e=>e.ref))}getRequiredQuestions(){return this.questions.filter((e=>e.require)).map((e=>e.ref))}}},116:(e,t)=>{"use strict";var i,n,a,s;Object.defineProperty(t,"__esModule",{value:!0}),t.PageRoute=t.OperatorType=t.ConditionType=t.TransitionType=void 0,(s=t.TransitionType||(t.TransitionType={})).PAGE="PAGE",s.FINISH="FINISH",function(e){e.LOGICAL="LOGICAL"}(i=t.ConditionType||(t.ConditionType={})),(a=t.OperatorType||(t.OperatorType={})).EQUAL="EQUAL",a.NOEQUAL="NOEQUAL",a.GREATER="GREATER",a.LESS="LESS",a.GREATEREQUAL="GREATEREQUAL",a.LESSEQUAL="LESSEQUAL",a.INQ="INQ",a.NINQ="NINQ",a.DEFAULT="DEFAULT",function(e){e.ACTIVE="ACTIVE",e.DEPRECATED="DEPRECATED",e.DELETE="DELETE"}(n||(n={})),t.PageRoute=class{constructor(e,t,a,s,r,o,d){this.id=e,this.questionRef=t,this.typeCondition=i.LOGICAL,this.typeOperator=a,this.value=s,this.transition=r,this.transitionDestiny=o,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=d}}},244:(e,t)=>{"use strict";var i,n;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(n=t.FEEDBACKAPPANSWERTYPE||(t.FEEDBACKAPPANSWERTYPE={})).CONTACT="CONTACT",n.MULTIPLECHOISE_IMAGE="MULTIPLECHOISE_IMAGE",n.EMAIL="EMAIL",n.RATING_STAR="RATING_STAR",n.RADIO="RADIO",n.MULTIPLECHOICE="MULTIPLECHOICE",n.SELECT="SELECT",n.TEXT="TEXT",n.LONGTEXT="LONGTEXT",n.NUMBER="NUMBER",n.RATING_EMOJI="RATING_EMOJI",n.RATING_NUMBER="RATING_NUMBER",n.DATE="DATE",n.BOOLEAN="BOOLEAN",n.PASSWORD="PASSWORD",n.CONSENT="CONSENT",n.MULTI_QUESTION_MATRIX="MULTI_QUESTION_MATRIX",n.POINT_SYSTEM="POINT_SYSTEM",n.PRIORITY_LIST="PRIORITY_LIST",t.QuestionType=class{},function(e){e.FORM="form",e.DIV="div"}(i||(i={}))},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا...";case"bn":return"এখানে আপনার"}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا...";case"bn":return"এখানে আপনার"}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا...";case"bn":return"এখানে আপনার"}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا...";case"bn":return"এখানে আপনার"}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا...";case"bn":return"এখানে আপনার"}}}},183:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const n=i(244),a=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}function r(e,t,i,n,a,s=!0){const r=document.createElement("div");r.classList.add("magicfeedback-rating-placeholder"),r.style.display="flex",r.style.justifyContent="space-between",r.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",r.style.marginRight="auto",s&&window.innerWidth<600&&(r.style.flexDirection="column");const o=document.createElement("span");o.textContent=i,o.classList.add("magicfeedback-rating-placeholder-value"),o.style.fontStyle="italic",o.style.fontSize="14px",o.style.textAlign="left",o.style.width="50%",s&&window.innerWidth<600&&(o.textContent=`${e} ➜ ${i}`,o.style.width="100%",o.style.textAlign="left",o.style.marginBottom="5px"),r.appendChild(o);const d=document.createElement("span");return d.textContent=n,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontStyle="italic",d.style.fontSize="14px",d.style.textAlign="right",d.style.width="50%",s&&window.innerWidth<600&&(d.textContent=`${t} ➜ ${n}`,d.style.width="100%",d.style.textAlign="left",d.style.marginBottom="5px"),r.appendChild(d),r}t.renderQuestions=function e(t,i="standard",o="en",d){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var l,u;if((null===(u=null===(l=null==t?void 0:t.questionType)||void 0===l?void 0:l.conf)||void 0===u?void 0:u.length)>0){let n=document.createElement("div");n.classList.add("magicfeedback-div"),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,o,d).forEach((e=>{n.appendChild(e)})),c.push(n)}else{const e=function(e,t,i,o){var d;let c,l,{id:u,title:p,type:h,ref:m,require:f,value:g,defaultValue:b,assets:y}=e,v=document.createElement("div");v.classList.add("magicfeedback-div");const E="slim"===t?s(p,i):null==y?void 0:y.placeholder,k=(C=u,new URLSearchParams(window.location.search).get(C)),x=y.maxCharacters||300;var C;switch(h){case n.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=E||a.placeholder.answer(i||"en"),l="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,x>0&&(c.maxLength=x),c.placeholder=E||a.placeholder.answer(i||"en"),l="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?s(p,i):a.placeholder.number(i||"en"),l="magicfeedback-number",g.length&&(g.sort(((e,t)=>Number(e)-Number(t))),c.max=g[g.length-1],c.min=g[0],c.value=g[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),l="magicfeedback-"+("MULTIPLECHOICE"===h?"checkbox":"radio"),y.extraOption&&g.push(y.extraOptionText),g.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===h?"checkbox":"radio"}-container`);const r=document.createElement("label"),o=document.createElement("input");if(o.id=`rating-${m}-${t}`,o.type="MULTIPLECHOICE"===h?"checkbox":"radio",o.name=m,o.value=e,o.classList.add(l),o.classList.add("magicfeedback-input"),h===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&y.maxOptions&&y.maxOptions>0&&o.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${m}"]:checked`).length>y.maxOptions&&(o.checked=!1)})),e!==b&&e!==k||(o.checked=!0),r.textContent=e,r.htmlFor=`rating-${m}-${t}`,o.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${m}`);i&&y.extraOption&&(t.target.checked&&e===y.extraOptionText?i.style.display="block":i.style.display="none")})),s.appendChild(o),s.appendChild(r),c.appendChild(s),y.extraOption&&e===y.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder=y.extraOptionPlaceholder||a.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${m}`,e.name=`extra-option-${m}`,e.style.display="none",c.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),l="magicfeedback-radio";const A=document.createElement("div");A.classList.add("magicfeedback-boolean-container"),A.style.display="flex",A.style.flexDirection="row",A.style.justifyContent="space-between",A.style.width="70%",A.style.margin="auto",(y.addIcon?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];case"bn":return["হ্যাঁ","না"];default:return["Yes","No"]}}(i)).forEach(((e,t)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${m}-${t}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const n=document.createElement("label");n.htmlFor=`rating-${m}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${m}-${t}`,a.type="radio",a.name=m,a.value=e,a.classList.add(l),a.classList.add("magicfeedback-input"),a.style.position="absolute",a.style.opacity="0",a.style.width="0",a.style.height="0",a.style.margin="0",a.addEventListener("change",(()=>{o&&o()})),i.appendChild(a),i.appendChild(n),A.appendChild(i)})),c.appendChild(A);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),l="magicfeedback-rating";const T=document.createElement("div");T.classList.add("magicfeedback-rating-container");const L=y.max?Number(y.max):5,O=y.min?Number(y.min):1,S=r(O,L,y.minPlaceholder,y.maxPlaceholder,y.extraOption);for(let ne=O;ne<=L;ne++){const ae=document.createElement("div");ae.classList.add("magicfeedback-rating-option");const se=document.createElement("label");se.htmlFor=`rating-${m}-${ne}`,se.classList.add("magicfeedback-rating-option-label-container");const re=document.createElement("label");re.htmlFor=`rating-${m}-${ne}`,re.textContent=ne.toString();const oe=document.createElement("img");if(oe.alt=`face-${m}-${ne}`,oe.className=`rating-image${ne}`,0===O&&10===L)oe.src=`https://magicfeedback-c6458-dev.web.app/assets/${ne}.svg`;else if(1===O&&5===L)switch(ne){case 1:oe.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:oe.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:oe.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:oe.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:oe.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const ce=Math.round(10/(L-O)*(ne-O));oe.src=`https://magicfeedback-c6458-dev.web.app/assets/${ce}.svg`}const de=document.createElement("input");de.id=`rating-${m}-${ne}`,de.type="radio",de.name=m,de.value=ne.toString(),de.classList.add(l),de.classList.add("magicfeedback-input"),se.appendChild(de),se.appendChild(oe),se.appendChild(re),ae.appendChild(se),T.appendChild(ae)}if(y.extraOption&&y.extraOptionText){const le=document.createElement("div");le.classList.add("magicfeedback-rating-option");const ue=document.createElement("label");ue.htmlFor=`rating-${m}-extra`,ue.classList.add("magicfeedback-rating-option-label-container");const pe=document.createElement("label");pe.htmlFor=`rating-${m}-extra`,pe.textContent=y.extraOptionText;const he=document.createElement("img");he.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",he.alt=`face-${m}-extra`,he.className="magicfeedback-rating-image-extra";const me=document.createElement("input");me.id=`rating-${m}-extra`,me.type="radio",me.name=m,me.value="-",me.classList.add(l),me.classList.add("magicfeedback-input"),ue.appendChild(me),ue.appendChild(he),ue.appendChild(pe),le.appendChild(ue),T.appendChild(le)}c.appendChild(S),c.appendChild(T);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),l="magicfeedback-rating-number";const P=document.createElement("div");P.classList.add("magicfeedback-rating-number-container");const I=y.max?Number(y.max):5,N=y.min?Number(y.min):1,D=r(N,I,y.minPlaceholder,y.maxPlaceholder,y.extraOption);for(let fe=N;fe<=I;fe++){const ge=document.createElement("div");ge.classList.add("magicfeedback-rating-number-option");const be=document.createElement("label");be.htmlFor=`rating-${m}-${fe}`,be.classList.add("magicfeedback-rating-number-option-label-container");const ye=document.createElement("label");ye.htmlFor=`rating-${m}-${fe}`,ye.textContent=fe.toString();const ve=document.createElement("input");ve.id=`rating-${m}-${fe}`,ve.type="radio",ve.name=m,ve.value=fe.toString(),ve.classList.add(l),ve.classList.add("magicfeedback-input"),be.appendChild(ve),be.appendChild(ye),ge.appendChild(be),P.appendChild(ge)}if(y.extraOption&&y.extraOptionText){const Ee=document.createElement("div");Ee.classList.add("magicfeedback-rating-number-option");const ke=document.createElement("label");ke.htmlFor=`rating-${m}-extra`,ke.classList.add("magicfeedback-rating-number-option-label-container");const xe=document.createElement("label");xe.htmlFor=`rating-${m}-extra`,xe.textContent=y.extraOptionText;const Ce=document.createElement("input");Ce.id=`rating-${m}-extra`,Ce.type="radio",Ce.name=m,Ce.value="-",Ce.classList.add(l),Ce.classList.add("magicfeedback-input"),ke.appendChild(Ce),ke.appendChild(xe),Ee.appendChild(ke),P.appendChild(Ee)}c.appendChild(D),c.appendChild(P);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),l="magicfeedback-rating-star";const _=function(e,t,i){const n="magicfeedback-rating-star-selected",a=document.createElement("div");a.classList.add("magicfeedback-rating-star-container"),a.style.maxWidth="300px",a.style.margin="auto";for(let t=1;t<=5;t++){const i=document.createElement("label");i.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${t}`,s.type="radio",s.name=e,s.value=t.toString(),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.classList.add("magicfeedback-input"),s.addEventListener("change",(()=>{const e=a.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(s.value)?e[t].classList.contains(n)||e[t].classList.add(n):e[t].classList.contains(n)&&e[t].classList.remove(n)})),i.appendChild(s);const r=document.createElement("label");r.htmlFor=`rating-${e}-${t}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",i.appendChild(r),a.appendChild(i)}return a.appendChild(r(1,5,t,i,!1,!1)),a}(m,y.minPlaceholder,y.maxPlaceholder);c.appendChild(_);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),l="magicfeedback-multiple-choice-image";const R=document.createElement("div");R.classList.add("magicfeedback-multiple-choice-image-container"),R.style.display="flex",R.style.flexDirection="row",R.style.flexWrap="wrap",R.style.justifyContent="center";const $=g.length;let M=1,F=1;switch($){case 1:case 2:case 3:M=$,F=1;break;case 4:case 5:case 6:F=2,M=Math.ceil($/F);break;case 7:case 8:case 9:F=3,M=Math.ceil($/F);break;default:F=4,M=Math.ceil($/F)}const B=void 0!==(null==y?void 0:y.addTitle)&&y.addTitle,U=void 0!==(null==y?void 0:y.multiOption)&&y.multiOption,q=void 0!==(null==y?void 0:y.randomPosition)&&y.randomPosition,j=void 0!==(null==y?void 0:y.extraOption)&&y.extraOption;function Q(e){try{const{position:t,url:i,value:n}=e,a=document.createElement("label");a.classList.add("magicfeedback-multiple-choice-image-option"),a.style.width=`calc( ${100/M}% - 10px)`,a.style.height=`calc( ${100/F}% - 10px)`,a.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${m}-${t}`,s.classList.add("magicfeedback-image-option-label-container"),s.style.display="flex",s.style.flexDirection="column",s.addEventListener("mouseover",(()=>{s.style.border="2px solid #000"})),s.addEventListener("mouseout",(()=>{s.style.border="none"})),s.addEventListener("click",(()=>{s.style.border="2px solid #000"}));const r=document.createElement("label");r.textContent=n,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${m}-${t}`,o.type=U?"checkbox":"radio",o.name=m,o.value=n,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.backgroundPosition="center",d.style.width="100%",d.style.height="100%",d.style.objectFit="cover",d.style.margin="auto",s.appendChild(o),s.appendChild(d),B&&s.appendChild(r),a.appendChild(s),R.appendChild(a)}catch(e){console.error(e)}}q&&(g=g.sort((()=>Math.random()-.5))),g.forEach((e=>Q(JSON.parse(e)))),j&&y.extraOptionValue&&y.extraOptionValue.length>0&&Q(y.extraOptionValue[0]),c.appendChild(R);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),l="magicfeedback-select";const G=document.createElement("option");G.value="",G.text="slim"===t?s(p,i):b||"Select an option",G.disabled=!0,G.selected=!0,c.appendChild(G),g.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=f,c.placeholder=E||a.placeholder.date(i||"en"),l="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),l="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${u}`,c.name=m,c.value="true",c.required=f,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input");break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=f,c.placeholder=E||"you@example.com",l="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=f,c.placeholder=E||a.placeholder.password(i||"en"),l="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),l="magicfeedback-multi-question-matrix";const K=document.createElement("div");K.classList.add("magicfeedback-multi-question-matrix-container");const W=document.createElement("table");W.classList.add("magicfeedback-multi-question-matrix-table");const H=document.createElement("thead");H.classList.add("magicfeedback-multi-question-matrix-header"),H.style.paddingBottom="15px";const Y=document.createElement("tr");["",...g].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",Y.appendChild(t)})),H.appendChild(Y);const V=document.createElement("tbody");(null===(d=null==y?void 0:y.options)||void 0===d?void 0:d.length)>0&&y.options.split("|").forEach((e=>{const t=document.createElement("tr");t.style.paddingBottom="15px";const i=document.createElement("td");i.classList.add("magicfeedback-multi-question-matrix-row-label");const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.style.paddingRight="15px",n.textContent=e,i.appendChild(n),t.appendChild(i),g.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="checkbox",a.name=m,a.value=i,a.id=`matrix-${e}`,a.classList.add("magicfeedback-input"),a.style.padding="0 10px",n.appendChild(a),t.appendChild(n)})),V.appendChild(t)})),W.appendChild(H),W.appendChild(V),K.appendChild(W),c.appendChild(K);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),l="magicfeedback-priority-list";const J=document.createElement("div");J.classList.add("magicfeedback-priority-list-container");const X=document.createElement("ul");X.classList.add("magicfeedback-priority-list-list"),g.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-priority-list-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("input");n.classList.add("magicfeedback-input-magicfeedback-priority-list"),n.classList.add("magicfeedback-input"),n.type="hidden",n.id=`priority-list-${m}`,n.name=m,n.value=`${t+1}. ${e}`,i.appendChild(n);const a=document.createElement("label");a.classList.add("magicfeedback-priority-list-item-label"),a.textContent=`${t+1}. ${e}`,i.appendChild(a);const s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between";const r=document.createElement("img");r.classList.add("magicfeedback-priority-list-arrow-up"),r.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",r.style.width="20px",r.style.height="20px",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.visibility=0===t?"hidden":"visible",r.addEventListener("click",(()=>{var t,s;const d=i.previousElementSibling;if(d){const c=Number(n.value.split(".")[0])-1;n.value=`${c}. ${e}`,a.textContent=`${c}. ${e}`,r.style.visibility=1===c?"hidden":"visible",o.style.visibility=c===g.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),h=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&h){const e=Number(l.value.split(".")[0])+1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===g.length?"hidden":"visible"}X.insertBefore(i,d)}})),s.appendChild(r);const o=document.createElement("img");o.classList.add("magicfeedback-priority-list-arrow-down"),o.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",o.style.width="20px",o.style.height="20px",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.transform="rotate(180deg)",o.style.visibility=t===g.length-1?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const d=i.nextElementSibling;if(d){const c=Number(n.value.split(".")[0])+1;n.value=c.toString(),a.textContent=`${c.toString()}. ${e}`,r.style.visibility=1===c?"hidden":"visible",o.style.visibility=c===g.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),h=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&h){const e=Number(l.value.split(".")[0])-1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===g.length?"hidden":"visible"}X.insertBefore(d,i)}})),s.appendChild(o),i.appendChild(s),X.appendChild(i)})),J.appendChild(X),c.appendChild(J);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),l="magicfeedback-point-system";const z=document.createElement("div");z.classList.add("magicfeedback-point-system-container");const Z=document.createElement("ul");Z.classList.add("magicfeedback-point-system-list"),Z.style.padding="0";const ee=100,te=ee/g.length,ie=document.createElement("div");ie.classList.add("magicfeedback-point-system-total"),ie.textContent="0 / 100 %",ie.style.textAlign="right",ie.style.fontSize="0.8em",ie.style.color="#999",ie.style.marginTop="5px",g.forEach((e=>{const t=document.createElement("li");t.classList.add("magicfeedback-point-system-item"),t.style.display="flex",t.style.justifyContent="space-between",t.style.alignItems="center",t.style.margin="5px";const i=document.createElement("label");i.textContent=e,t.appendChild(i);const n=document.createElement("span");n.classList.add("magicfeedback-point-system-input-container");const a=document.createElement("input");a.name=m,a.id=`point-system-${e}`,a.type="number",a.min="0",a.max=`${ee}`,a.value="0",a.classList.add("magicfeedback-input"),a.style.width="40px",a.style.border="0",a.style.textAlign="center",a.style.margin="0 5px";const s=document.createElement("span");s.textContent="%",s.style.color="#000",a.addEventListener("input",(()=>{const e=Z.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ee&&(a.value=`${te}%`,t-=Number(a.value)),ie.textContent=`${t} / 100 %`})),n.appendChild(a),n.appendChild(s),t.appendChild(n),Z.appendChild(t)})),z.appendChild(Z),z.appendChild(ie),c.appendChild(z);break;default:return v}c.id=`magicfeedback-${u}`,c.setAttribute("name",m),c.classList.add(l),(void 0!==b||null!==k)&&(c.value=k||b),["RADIO","MULTIPLECHOICE"].includes(h)||(c.classList.add("magicfeedback-input"),c.required=f);const w=document.createElement("label");if(w.setAttribute("for",`magicfeedback-${u}`),w.textContent=s(p,i),w.classList.add("magicfeedback-label"),["CONSENT"].includes(h))v.classList.add("magicfeedback-consent-container"),v.appendChild(c),v.appendChild(w);else{if("slim"!==t&&(v.appendChild(w),void 0!==(null==y?void 0:y.general)&&""!==(null==y?void 0:y.general))){const we=document.createElement("img");we.src=y.general,we.classList.add("magicfeedback-image"),we.style.maxWidth="auto",we.style.height="400px",we.style.margin="10px 0",v.appendChild(we)}if("LONGTEXT"===h&&x>0){const Ae=document.createElement("div");if(Ae.classList.add("magicfeedback-counter"),Ae.textContent=`${c.value.length}/${x}`,Ae.style.textAlign="right",Ae.style.fontSize="0.8em",Ae.style.color="#999",Ae.style.marginTop="5px",c.addEventListener("input",(()=>{Ae.textContent=`${c.value.length}/${x}`})),v.appendChild(c),v.appendChild(Ae),y.extraOption&&y.extraOptionText){const Te=document.createElement("div");Te.classList.add("magicfeedback-skip-container"),Te.classList.add("magicfeedback-checkbox-container"),Te.style.display="flex",Te.style.justifyContent="flex-start";const Le=document.createElement("input");Le.classList.add("magicfeedback-skip"),Le.type="checkbox",Le.id=`skip-${m}`,Le.name=m,Le.value="-",Le.style.cursor="pointer";const Oe=document.createElement("label");Oe.htmlFor=`skip-${m}`,Oe.textContent=y.extraOptionText,Oe.style.fontSize="0.8em",Oe.style.color="#999",Oe.style.cursor="pointer",Oe.style.margin="0 5px",Le.addEventListener("click",(()=>{c.value="-",o&&o()})),Te.appendChild(Le),Te.appendChild(Oe),v.appendChild(Te)}}else v.appendChild(c)}return v}(t,i,o,d);c.push(e)}})),c},t.renderActions=function(e="",t,i="Submit",n="Back",a="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=n||"Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&s.appendChild(o),s.appendChild(r),s},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,i=!1,n="Go!"){const a=document.createElement("div");a.classList.add("magicfeedback-start-message-container");const s=document.createElement("div");s.classList.add("magicfeedback-start-message"),s.innerHTML=e;const r=document.createElement("button");return r.id="magicfeedback-start-message-button",r.classList.add("magicfeedback-start-message-button"),r.textContent=n,r.addEventListener("click",(()=>t())),a.appendChild(s),i&&a.appendChild(r),a}},341:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{d(n.next(e))}catch(e){s(e)}}function o(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}d((n=n.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const s=a(i(98)),r=a(i(147)),o=i(374),d={Accept:"application/json","Magicfeedback-Sdk-Version":r.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,a){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return a.log(`Received form for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),null}}))},t.getQuestions=function(e,t,i,a){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+o.endpoints.sdk.app(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return a.log(`Received questions for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),[]}}))},t.sendFeedback=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield n.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield n.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},147:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.8-beta.9","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},function i(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,i),s.exports}(607).default;var e,t}));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(self,(()=>{return e={98:function(e,t){var i="undefined"!=typeof self?self:this,n=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,a="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,o="ArrayBuffer"in e;if(o)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],d=ArrayBuffer.isView||function(e){return e&&r.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function p(e){this.map={},e instanceof p?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function h(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function m(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function f(e){var t=new FileReader,i=m(t);return t.readAsArrayBuffer(e),i}function g(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:a&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():o&&a&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):o&&(ArrayBuffer.prototype.isPrototypeOf(e)||d(e))?this._bodyArrayBuffer=g(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a&&(this.blob=function(){var e=h(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?h(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var e,t,i,n=h(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,i=m(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),n=0;n<t.length;n++)i[n]=String.fromCharCode(t[n]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=c(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[c(e)]},p.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},p.prototype.set=function(e,t){this.map[c(e)]=l(t)},p.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},p.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},p.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},p.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},n&&(p.prototype[Symbol.iterator]=p.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,n,a=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new p(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,a||null==e._bodyInit||(a=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new p(t.headers)),this.method=(n=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(n)>-1?n:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&a)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(a)}function E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),n=i.shift().replace(/\+/g," "),a=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(a))}})),t}function k(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new p(t.headers),this.url=t.url||"",this._initBody(e)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},b.call(v.prototype),b.call(k.prototype),k.prototype.clone=function(){return new k(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new p(this.headers),url:this.url})},k.error=function(){var e=new k(null,{status:0,statusText:""});return e.type="error",e};var x=[301,302,303,307,308];k.redirect=function(e,t){if(-1===x.indexOf(t))throw new RangeError("Invalid status code");return new k(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function C(e,i){return new Promise((function(n,s){var o=new v(e,i);if(o.signal&&o.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var r=new XMLHttpRequest;function d(){r.abort()}r.onload=function(){var e,t,i={status:r.status,statusText:r.statusText,headers:(e=r.getAllResponseHeaders()||"",t=new p,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),n=i.shift().trim();if(n){var a=i.join(":").trim();t.append(n,a)}})),t)};i.url="responseURL"in r?r.responseURL:i.headers.get("X-Request-URL");var a="response"in r?r.response:r.responseText;n(new k(a,i))},r.onerror=function(){s(new TypeError("Network request failed"))},r.ontimeout=function(){s(new TypeError("Network request failed"))},r.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},r.open(o.method,o.url,!0),"include"===o.credentials?r.withCredentials=!0:"omit"===o.credentials&&(r.withCredentials=!1),"responseType"in r&&a&&(r.responseType="blob"),o.headers.forEach((function(e,t){r.setRequestHeader(t,e)})),o.signal&&(o.signal.addEventListener("abort",d),r.onreadystatechange=function(){4===r.readyState&&o.signal.removeEventListener("abort",d)}),r.send(void 0===o._bodyInit?null:o._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=p,e.Request=v,e.Response=k),t.Headers=p,t.Request=v,t.Response=k,t.fetch=C,Object.defineProperty(t,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var a=n;(t=a.fetch).default=a.fetch,t.fetch=a.fetch,t.Headers=a.Headers,t.Request=a.Request,t.Response=a.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(i(519));let s=null;s||(s=(0,a.default)()),t.default=s},519:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(954),s=i(712),o=i(5),r=i(341),d=i(290);t.default=function(){const e=new s.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?d.HOST_API_URL_DEV:d.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,o=!0,d,c){return n(this,void 0,void 0,(function*(){i||t.err("No appID provided"),a||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const n=e.get("url"),l={integration:i,publicKey:a,privateKey:c,completed:o,id:d,feedback:s};try{const e=yield(0,r.sendFeedback)(n,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,n){return i||t.err("No appID provided"),n||t.err("No publicKey provided"),new a.Form(e,i,n)}}}},314:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.History=void 0,t.History=class{constructor(){this.items=[]}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}rollback(){return this.items.pop()}front(){return this.items[0]}back(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}}},712:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(5),s=i(341),o=i(183),r=i(24),d=i(804),c=i(116),l=i(314),u=i(457);t.Form=class{constructor(e,t,i){this.config=e,this.log=new a.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.getDataFromStorage(),this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new l.History,this.graph=new r.PageGraph([]),this.progress=0,this.total=0,this.followup=!1}getDataFromStorage(){const e=localStorage.getItem(`magicfeedback-${this.appId}`);e&&new Date(JSON.parse(e).savedAt)<new Date((new Date).getTime()+864e5)&&(this.formData=JSON.parse(e),(0,s.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,n;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),(null===(n=this.formData.style)||void 0===n?void 0:n.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm())})))}generate(e,t){var i,a,o;return n(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e,void 0!==this.formData&&this.formData||(this.formData=yield(0,s.getForm)(this.url,this.appId,this.publicKey,this.log)),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),void 0===this.formData.questions||!this.formData.questions)throw new Error(`No questions for app ${this.appId}`);this.formData.pages&&0!==(null===(i=this.formData.pages)||void 0===i?void 0:i.length)||this.formatPages(),null===(a=this.formData.questions)||void 0===a||a.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(o=this.formData.style)||void 0===o?void 0:o.startMessage)?yield this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}formatPages(){var e;if(this.formData)switch(this.formData.identity){case"MAGICSURVEY":this.formData.pages=[],null===(e=this.formData.questions)||void 0===e||e.forEach((e=>{var t,i;const n=new c.PageRoute(e.id,e.ref,c.OperatorType.NOEQUAL,null,c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),a=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(a)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i;return n(this,void 0,void 0,(function*(){try{if(!this.formData||!this.formData.pages||0===this.formData.pages.length)throw new Error("No form data");this.graph=new r.PageGraph(this.formData.pages.sort(((e,t)=>e.position-t.position)));let n=this.generateContainer();const a=document.createElement("form");a.classList.add("magicfeedback-form"),a.id="magicfeedback-"+this.appId;const s=document.createElement("div");s.classList.add("magicfeedback-questions"),s.id="magicfeedback-questions-"+this.appId;const d=this.graph.getFirstPage();if(!d)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),d.elements=(0,o.renderQuestions)(d.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),null===(t=d.elements)||void 0===t||t.forEach((e=>s.appendChild(e))),a.appendChild(s),this.history.enqueue(d),n.appendChild(a),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(i=this.formData)||void 0===i?void 0:i.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);a.appendChild(e)}a.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}startForm(){this.generateForm()}generateWelcomeMessage(e){return n(this,void 0,void 0,(function*(){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){return n(this,void 0,void 0,(function*(){const n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const a=this.history.back();if(!a)throw new Error("No page found");const s=a.getRequiredQuestions();for(const e of s)if(!this.feedback.answers.find((t=>t.key===e&&t.value.length>0)))return void this.log.err(`The question ${e} is required`);const o=yield this.pushAnswers(!1);o&&(this.id=o,yield this.processNextQuestion(n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,followup:this.followup,error:o?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const n=e.type,a=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===a?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(n){case"radio":case"checkbox":if("magicfeedback-consent"===a||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===n){if(!(0,s.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}if(e.id.includes("point-system")){const t="point-system-"+e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${r}%`)}else o.value.push(r);const a=t.findIndex((e=>e.key===o.key));-1!==a?t[a].value=[...t[a].value,...o.value]:t.push(o)}}})),console.log(t);const n=t.filter((e=>e.key.includes("matrix")));null==n||n.forEach((e=>{const i=t.find((t=>t.key===e.key));i&&(i.value=[...new Set(i.value)])}));const a=t.filter((e=>e.key.includes("point-system")));null==a||a.forEach((e=>{100!==e.value.reduce(((e,t)=>{const i=t.split(": ")[1];return e+Number(i.replace("%",""))}),0)&&(this.log.err("The sum of the point system questions must be 100%"),i=!0)})),this.feedback.answers=i?[]:t}finish(){if(this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer(),this.pushAnswers(!0)}pushAnswers(e=!1){return n(this,void 0,void 0,(function*(){try{const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){var t;return n(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),n={answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,s.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const a=n.getFollowupQuestions();if((null==a?void 0:a.length)>0){const s=[];for(const e of a){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&s.push(e)}}if(s.length>0){this.followup=!0;const a=new d.Page(n.id,n.position,this.appId,s,n.edges),r=new u.PageNode(n.id,n.position,n.edges,a,s);r.elements=(0,o.renderQuestions)(s,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],(()=>this.send())),this.history.enqueue(r),e.removeChild(e.childNodes[0]),null===(i=r.elements)||void 0===i||i.forEach((t=>e.appendChild(t)))}else this.renderNextQuestion(e,n)}else this.renderNextQuestion(e,n)}))}renderNextQuestion(e,t){var i,n;this.followup=!1;const a=this.graph.getNextPage(t,this.feedback.answers);a?(this.progress=this.total-this.graph.findDepth(a.id),a.elements=(0,o.renderQuestions)(a.questions,this.formOptionsConfig.questionFormat,null===(i=this.formData)||void 0===i?void 0:i.lang[0],(()=>this.send())),e.removeChild(e.childNodes[0]),null===(n=a.elements)||void 0===n||n.forEach((t=>e.appendChild(t))),this.history.enqueue(a)):this.finish()}back(){var e;if(0===this.history.size())return;console.log("Back",this.history);const t=document.getElementById("magicfeedback-questions-"+this.appId);t&&t.childNodes.length>0&&t.removeChild(t.childNodes[0]),this.history.rollback();const i=this.history.back();i&&(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e))))}}},804:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Page=void 0,t.Page=class{constructor(e,t,i,n,a){this.id=e,this.position=t,this.generatedAt=(new Date).toISOString(),this.updatedAt=(new Date).getTime(),this.status="ACTIVE",this.integrationId=i,this.integrationQuestions=n,this.integrationPageRoutes=a}}},24:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(457),a=i(116);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach((e=>{const t=new n.PageNode(e.id,e.position,e.integrationPageRoutes||[],e,e.integrationQuestions);this.nodes.set(t.id,t)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(e)for(const t of this.nodes.values())if(t.position===e.position+1)return t.id}getFirstPage(){let e,t=Number.MAX_VALUE;for(const i of this.nodes.values())i.position<t&&(t=i.position,e=i);return e}getNextPage(e,t){if(!e)return;const i=e.edges.find((e=>{const i=null==t?void 0:t.filter((t=>t.key===e.questionRef));if(!i)return!1;switch(e.typeOperator){case a.OperatorType.EQUAL:return i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case a.OperatorType.NOEQUAL:return!i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case a.OperatorType.GREATER:return i.find((t=>t.value.find((t=>Number(t)>Number(e.value)))));case a.OperatorType.LESS:return i.find((t=>t.value.find((t=>Number(t)<Number(e.value)))));case a.OperatorType.GREATEREQUAL:return console.log(i),i.find((t=>t.value.find((t=>Number(t)>=Number(e.value)))));case a.OperatorType.LESSEQUAL:return i.find((t=>t.value.find((t=>Number(t)<=Number(e.value)))));case a.OperatorType.INQ:return i.find((t=>e.value.includes(t.value)));case a.OperatorType.NINQ:return!i.find((t=>e.value.includes(t.value)));default:return!1}}));if(!i){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}return this.getNodeById(i.transitionDestiny)}findDepth(e){const t=this.getNodeById(e);if(!t)return 0;const i=new Set;return this.DFSUtil(t,i,0)}findMaxDepth(){const e=new Set;let t=0;return this.nodes.forEach((i=>{e.has(i)||(t=Math.max(t,this.DFSUtil(i,e,0)))})),t}DFSUtil(e,t,i){t.add(e);let n=i;const a=this.getNextEdgeByDefault(e);for(const s of a?[...e.edges,{transitionDestiny:a}]:e.edges){const e=this.getNodeById(s.transitionDestiny);e&&!t.has(e)&&(n=Math.max(n,this.DFSUtil(e,t,i+1)))}return n}}},457:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,a){this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=a,this.elements=[]}getFollowupQuestions(){return this.questions.filter((e=>e.followup)).map((e=>e.ref))}getRequiredQuestions(){return this.questions.filter((e=>e.require)).map((e=>e.ref))}}},116:(e,t)=>{"use strict";var i,n,a,s;Object.defineProperty(t,"__esModule",{value:!0}),t.PageRoute=t.OperatorType=t.ConditionType=t.TransitionType=void 0,(s=t.TransitionType||(t.TransitionType={})).PAGE="PAGE",s.FINISH="FINISH",function(e){e.LOGICAL="LOGICAL"}(i=t.ConditionType||(t.ConditionType={})),(a=t.OperatorType||(t.OperatorType={})).EQUAL="EQUAL",a.NOEQUAL="NOEQUAL",a.GREATER="GREATER",a.LESS="LESS",a.GREATEREQUAL="GREATEREQUAL",a.LESSEQUAL="LESSEQUAL",a.INQ="INQ",a.NINQ="NINQ",a.DEFAULT="DEFAULT",function(e){e.ACTIVE="ACTIVE",e.DEPRECATED="DEPRECATED",e.DELETE="DELETE"}(n||(n={})),t.PageRoute=class{constructor(e,t,a,s,o,r,d){this.id=e,this.questionRef=t,this.typeCondition=i.LOGICAL,this.typeOperator=a,this.value=s,this.transition=o,this.transitionDestiny=r,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=d}}},244:(e,t)=>{"use strict";var i,n;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(n=t.FEEDBACKAPPANSWERTYPE||(t.FEEDBACKAPPANSWERTYPE={})).CONTACT="CONTACT",n.MULTIPLECHOISE_IMAGE="MULTIPLECHOISE_IMAGE",n.EMAIL="EMAIL",n.RATING_STAR="RATING_STAR",n.RADIO="RADIO",n.MULTIPLECHOICE="MULTIPLECHOICE",n.SELECT="SELECT",n.TEXT="TEXT",n.LONGTEXT="LONGTEXT",n.NUMBER="NUMBER",n.RATING_EMOJI="RATING_EMOJI",n.RATING_NUMBER="RATING_NUMBER",n.DATE="DATE",n.BOOLEAN="BOOLEAN",n.PASSWORD="PASSWORD",n.CONSENT="CONSENT",n.MULTI_QUESTION_MATRIX="MULTI_QUESTION_MATRIX",n.POINT_SYSTEM="POINT_SYSTEM",n.PRIORITY_LIST="PRIORITY_LIST",t.QuestionType=class{},function(e){e.FORM="form",e.DIV="div"}(i||(i={}))},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا...";case"bn":return"এখানে আপনার"}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا...";case"bn":return"এখানে আপনার"}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا...";case"bn":return"এখানে আপনার"}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا...";case"bn":return"এখানে আপনার"}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا...";case"bn":return"এখানে আপনার"}},pointsystemerror:e=>{switch(e){case"en":default:return"The total points must be 100 %";case"es":return"El total de puntos debe ser 100 %";case"da":return"Samlet antal point skal være 100 %";case"fi":return"Kokonaispisteiden on oltava 100 %";case"sv":return"Totala poäng måste vara 100 %";case"no":return"Totalt antall poeng må være 100 %";case"ar":return"يجب أن تكون النقاط الإجمالية 100 %";case"bn":return"মোট পয়েন্ট 100 % হতে হবে"}}}},183:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const n=i(244),a=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}function o(e,t,i,n,a,s=!0){const o=document.createElement("div");o.classList.add("magicfeedback-rating-placeholder"),o.style.display="flex",o.style.justifyContent="space-between",o.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",o.style.marginRight="auto",s&&window.innerWidth<600&&(o.style.flexDirection="column");const r=document.createElement("span");r.textContent=i,r.classList.add("magicfeedback-rating-placeholder-value"),r.style.fontSize="15px",r.style.textAlign="left",r.style.width="50%",s&&window.innerWidth<600&&(r.textContent=`${e} ➜ ${i}`,r.style.width="100%",r.style.textAlign="left",r.style.marginBottom="5px"),o.appendChild(r);const d=document.createElement("span");return d.textContent=n,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="right",d.style.width="50%",s&&window.innerWidth<600&&(d.textContent=`${t} ➜ ${n}`,d.style.width="100%",d.style.textAlign="left",d.style.marginBottom="5px"),o.appendChild(d),o}t.renderQuestions=function e(t,i="standard",r="en",d){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var l,u;if((null===(u=null===(l=null==t?void 0:t.questionType)||void 0===l?void 0:l.conf)||void 0===u?void 0:u.length)>0){let n=document.createElement("div");n.classList.add("magicfeedback-div"),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,r,d).forEach((e=>{n.appendChild(e)})),c.push(n)}else{const e=function(e,t,i,r){var d;let c,l,{id:u,title:p,type:h,ref:m,require:f,value:g,defaultValue:b,assets:y}=e,v=document.createElement("div");v.classList.add("magicfeedback-div");const E="slim"===t?s(p,i):null==y?void 0:y.placeholder,k=(C=u,new URLSearchParams(window.location.search).get(C)),x=(null==y?void 0:y.maxCharacters)||0;var C;switch(h){case n.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=E||a.placeholder.answer(i||"en"),l="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,x>0&&(c.maxLength=x),c.placeholder=E||a.placeholder.answer(i||"en"),l="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?s(p,i):a.placeholder.number(i||"en"),l="magicfeedback-number",g.length&&(g.sort(((e,t)=>Number(e)-Number(t))),c.max=g[g.length-1],c.min=g[0],c.value=g[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),l="magicfeedback-"+("MULTIPLECHOICE"===h?"checkbox":"radio"),(null==y?void 0:y.extraOption)&&g.push(null==y?void 0:y.extraOptionText),g.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===h?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${m}-${t}`,r.type="MULTIPLECHOICE"===h?"checkbox":"radio",r.name=m,r.value=e,r.classList.add(l),r.classList.add("magicfeedback-input"),h===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==y?void 0:y.maxOptions)&&(null==y?void 0:y.maxOptions)>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${m}"]:checked`).length>(null==y?void 0:y.maxOptions)&&(r.checked=!1)})),e!==b&&e!==k||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${m}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${m}`);i&&(null==y?void 0:y.extraOption)&&(t.target.checked&&e===(null==y?void 0:y.extraOptionText)?i.style.display="block":i.style.display="none")})),s.appendChild(r),s.appendChild(o),c.appendChild(s),(null==y?void 0:y.extraOption)&&e===(null==y?void 0:y.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==y?void 0:y.extraOptionPlaceholder)||a.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${m}`,e.name=`extra-option-${m}`,e.style.display="none",c.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),l="magicfeedback-radio";const A=document.createElement("div");A.classList.add("magicfeedback-boolean-container"),A.style.display="flex",A.style.flexDirection="row",A.style.justifyContent="space-between",A.style.width="70%",A.style.margin="auto",((null==y?void 0:y.addIcon)?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];case"bn":return["হ্যাঁ","না"];default:return["Yes","No"]}}(i)).forEach(((e,t)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${m}-${t}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const n=document.createElement("label");n.htmlFor=`rating-${m}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${m}-${t}`,a.type="radio",a.name=m,a.value=e,a.classList.add(l),a.classList.add("magicfeedback-input"),a.style.position="absolute",a.style.opacity="0",a.style.width="0",a.style.height="0",a.style.margin="0",a.addEventListener("change",(()=>{r&&r()})),i.appendChild(a),i.appendChild(n),A.appendChild(i)})),c.appendChild(A);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),l="magicfeedback-rating";const T=document.createElement("div");T.classList.add("magicfeedback-rating-container");const L=(null==y?void 0:y.max)?Number(null==y?void 0:y.max):5,O=(null==y?void 0:y.min)?Number(null==y?void 0:y.min):1,S=o(O,L,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder,null==y?void 0:y.extraOption);for(let ae=O;ae<=L;ae++){const se=document.createElement("div");se.classList.add("magicfeedback-rating-option");const oe=document.createElement("label");oe.htmlFor=`rating-${m}-${ae}`,oe.classList.add("magicfeedback-rating-option-label-container");const re=document.createElement("label");re.htmlFor=`rating-${m}-${ae}`,re.textContent=ae.toString();const de=document.createElement("img");if(de.alt=`face-${m}-${ae}`,de.className=`rating-image${ae}`,0===O&&10===L)de.src=`https://magicfeedback-c6458-dev.web.app/assets/${ae}.svg`;else if(1===O&&5===L)switch(ae){case 1:de.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:de.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:de.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:de.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:de.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const le=Math.round(10/(L-O)*(ae-O));de.src=`https://magicfeedback-c6458-dev.web.app/assets/${le}.svg`}const ce=document.createElement("input");ce.id=`rating-${m}-${ae}`,ce.type="radio",ce.name=m,ce.value=ae.toString(),ce.classList.add(l),ce.classList.add("magicfeedback-input"),oe.appendChild(ce),oe.appendChild(de),oe.appendChild(re),se.appendChild(oe),T.appendChild(se)}if((null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const ue=document.createElement("div");ue.classList.add("magicfeedback-rating-option");const pe=document.createElement("label");pe.htmlFor=`rating-${m}-extra`,pe.classList.add("magicfeedback-rating-option-label-container");const he=document.createElement("label");he.htmlFor=`rating-${m}-extra`,he.textContent=null==y?void 0:y.extraOptionText;const me=document.createElement("img");me.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",me.alt=`face-${m}-extra`,me.className="magicfeedback-rating-image-extra";const fe=document.createElement("input");fe.id=`rating-${m}-extra`,fe.type="radio",fe.name=m,fe.value="-",fe.classList.add(l),fe.classList.add("magicfeedback-input"),pe.appendChild(fe),pe.appendChild(me),pe.appendChild(he),ue.appendChild(pe),T.appendChild(ue)}c.appendChild(S),c.appendChild(T);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),l="magicfeedback-rating-number";const P=document.createElement("div");P.classList.add("magicfeedback-rating-number-container");const I=(null==y?void 0:y.max)?Number(null==y?void 0:y.max):5,N=(null==y?void 0:y.min)?Number(null==y?void 0:y.min):1,D=o(N,I,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder,null==y?void 0:y.extraOption);for(let ge=N;ge<=I;ge++){const be=document.createElement("div");be.classList.add("magicfeedback-rating-number-option");const ye=document.createElement("label");ye.htmlFor=`rating-${m}-${ge}`,ye.classList.add("magicfeedback-rating-number-option-label-container");const ve=document.createElement("label");ve.htmlFor=`rating-${m}-${ge}`,ve.textContent=ge.toString();const Ee=document.createElement("input");Ee.id=`rating-${m}-${ge}`,Ee.type="radio",Ee.name=m,Ee.value=ge.toString(),Ee.classList.add(l),Ee.classList.add("magicfeedback-input"),ye.appendChild(Ee),ye.appendChild(ve),be.appendChild(ye),P.appendChild(be)}if((null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const ke=document.createElement("div");ke.classList.add("magicfeedback-rating-number-option");const xe=document.createElement("label");xe.htmlFor=`rating-${m}-extra`,xe.classList.add("magicfeedback-rating-number-option-label-container");const Ce=document.createElement("label");Ce.htmlFor=`rating-${m}-extra`,Ce.textContent=null==y?void 0:y.extraOptionText;const we=document.createElement("input");we.id=`rating-${m}-extra`,we.type="radio",we.name=m,we.value="-",we.classList.add(l),we.classList.add("magicfeedback-input"),xe.appendChild(we),xe.appendChild(Ce),ke.appendChild(xe),P.appendChild(ke)}c.appendChild(D),c.appendChild(P);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),l="magicfeedback-rating-star";const _=function(e,t,i){const n="magicfeedback-rating-star-selected",a=document.createElement("div");a.classList.add("magicfeedback-rating-star-container"),a.style.maxWidth="300px",a.style.margin="auto";for(let t=1;t<=5;t++){const i=document.createElement("label");i.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${t}`,s.type="radio",s.name=e,s.value=t.toString(),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.classList.add("magicfeedback-input"),s.addEventListener("change",(()=>{const e=a.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(s.value)?e[t].classList.contains(n)||e[t].classList.add(n):e[t].classList.contains(n)&&e[t].classList.remove(n)})),i.appendChild(s);const o=document.createElement("label");o.htmlFor=`rating-${e}-${t}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",i.appendChild(o),a.appendChild(i)}return a.appendChild(o(1,5,t,i,!1,!1)),a}(m,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder);c.appendChild(_);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),l="magicfeedback-multiple-choice-image";const R=document.createElement("div");R.classList.add("magicfeedback-multiple-choice-image-container"),R.style.display="flex",R.style.flexDirection="row",R.style.flexWrap="wrap",R.style.justifyContent="center";const $=g.length;let M=1,F=1;switch($){case 1:case 2:case 3:M=$,F=1;break;case 4:case 5:case 6:F=2,M=Math.ceil($/F);break;case 7:case 8:case 9:F=3,M=Math.ceil($/F);break;default:F=4,M=Math.ceil($/F)}const B=void 0!==(null==y?void 0:y.addTitle)&&(null==y?void 0:y.addTitle),U=void 0!==(null==y?void 0:y.multiOption)&&(null==y?void 0:y.multiOption),q=void 0!==(null==y?void 0:y.randomPosition)&&(null==y?void 0:y.randomPosition),j=void 0!==(null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOption);function Q(e){try{const{position:t,url:i,value:n}=e,a=document.createElement("label");a.classList.add("magicfeedback-multiple-choice-image-option"),a.style.width=`calc( ${100/M}% - 10px)`,a.style.height=`calc( ${100/F}% - 10px)`,a.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${m}-${t}`,s.classList.add("magicfeedback-image-option-label-container"),s.style.display="flex",s.style.flexDirection="column",s.addEventListener("mouseover",(()=>{s.style.border="2px solid #000"})),s.addEventListener("mouseout",(()=>{s.style.border="none"})),s.addEventListener("click",(()=>{s.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=n,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${m}-${t}`,r.type=U?"checkbox":"radio",r.name=m,r.value=n,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.backgroundPosition="center",d.style.width="100%",d.style.height="100%",d.style.objectFit="cover",d.style.margin="auto",s.appendChild(r),s.appendChild(d),B&&s.appendChild(o),a.appendChild(s),R.appendChild(a)}catch(e){console.error(e)}}q&&(g=g.sort((()=>Math.random()-.5))),g.forEach((e=>Q(JSON.parse(e)))),j&&(null==y?void 0:y.extraOptionValue)&&(null==y?void 0:y.extraOptionValue.length)>0&&Q(null==y?void 0:y.extraOptionValue[0]),c.appendChild(R);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),l="magicfeedback-select";const G=document.createElement("option");G.value="",G.text="slim"===t?s(p,i):b||"Select an option",G.disabled=!0,G.selected=!0,c.appendChild(G),g.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=f,c.placeholder=E||a.placeholder.date(i||"en"),l="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),l="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${u}`,c.name=m,c.value="true",c.required=f,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input");break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=f,c.placeholder=E||"you@example.com",l="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=f,c.placeholder=E||a.placeholder.password(i||"en"),l="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),l="magicfeedback-multi-question-matrix";const K=document.createElement("div");K.classList.add("magicfeedback-multi-question-matrix-container");const W=document.createElement("table");W.classList.add("magicfeedback-multi-question-matrix-table");const H=document.createElement("thead");H.classList.add("magicfeedback-multi-question-matrix-header"),H.style.paddingBottom="15px";const Y=document.createElement("tr");["",...g].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",Y.appendChild(t)})),H.appendChild(Y);const V=document.createElement("tbody");(null===(d=null==y?void 0:y.options)||void 0===d?void 0:d.length)>0&&(null==y||y.options.split("|").forEach((e=>{const t=document.createElement("tr");t.style.paddingBottom="15px";const i=document.createElement("td");i.classList.add("magicfeedback-multi-question-matrix-row-label");const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.style.paddingRight="15px",n.textContent=e,i.appendChild(n),t.appendChild(i),g.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="radio",a.name=`${m}-${e}`,a.value=i,a.id=`matrix-${e}`,a.classList.add("magicfeedback-input"),a.style.padding="0 10px",n.appendChild(a),t.appendChild(n)})),V.appendChild(t)}))),W.appendChild(H),W.appendChild(V),K.appendChild(W),c.appendChild(K);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),l="magicfeedback-priority-list";const J=document.createElement("div");J.classList.add("magicfeedback-priority-list-container");const z=document.createElement("ul");z.classList.add("magicfeedback-priority-list-list"),g.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-priority-list-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("input");n.classList.add("magicfeedback-input-magicfeedback-priority-list"),n.classList.add("magicfeedback-input"),n.type="hidden",n.id=`priority-list-${m}`,n.name=m,n.value=`${t+1}. ${e}`,i.appendChild(n);const a=document.createElement("label");a.classList.add("magicfeedback-priority-list-item-label"),a.textContent=`${t+1}. ${e}`,i.appendChild(a);const s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between";const o=document.createElement("img");o.classList.add("magicfeedback-priority-list-arrow-up"),o.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",o.style.width="20px",o.style.height="20px",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.visibility=0===t?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const d=i.previousElementSibling;if(d){const c=Number(n.value.split(".")[0])-1;n.value=`${c}. ${e}`,a.textContent=`${c}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===g.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),h=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&h){const e=Number(l.value.split(".")[0])+1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===g.length?"hidden":"visible"}z.insertBefore(i,d)}})),s.appendChild(o);const r=document.createElement("img");r.classList.add("magicfeedback-priority-list-arrow-down"),r.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",r.style.width="20px",r.style.height="20px",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(180deg)",r.style.visibility=t===g.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,s;const d=i.nextElementSibling;if(d){const c=Number(n.value.split(".")[0])+1;n.value=c.toString(),a.textContent=`${c.toString()}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===g.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),h=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&h){const e=Number(l.value.split(".")[0])-1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===g.length?"hidden":"visible"}z.insertBefore(d,i)}})),s.appendChild(r),i.appendChild(s),z.appendChild(i)})),J.appendChild(z),c.appendChild(J);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),l="magicfeedback-point-system";const X=document.createElement("div");X.classList.add("magicfeedback-point-system-container");const Z=document.createElement("ul");Z.classList.add("magicfeedback-point-system-list"),Z.style.padding="0";const ee=100,te=ee/g.length,ie=document.createElement("div");ie.classList.add("magicfeedback-error"),ie.textContent=a.placeholder.pointsystemerror(i||"en"),ie.style.color="#C70039",ie.style.fontSize="14px",ie.style.textAlign="right",ie.style.width="100%",ie.style.display="none";const ne=document.createElement("div");ne.classList.add("magicfeedback-point-system-total"),ne.textContent="0 / 100 %",ne.style.textAlign="right",ne.style.fontSize="15px",ne.style.marginTop="5px",g.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-point-system-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("label");n.textContent=e,n.style.fontSize="15px",i.appendChild(n);const a=document.createElement("span");a.classList.add("magicfeedback-point-system-input-container");const s=document.createElement("input");s.name=m,s.id=`point-system-${e}`,s.type="number",s.min="0",s.max=`${ee}`,s.value="0",s.classList.add("magicfeedback-input"),s.style.width="40px",s.style.border="0",s.style.textAlign="center",s.style.margin="0 5px",s.autofocus=0===t;const o=document.createElement("span");o.textContent="%",o.style.color="#000",s.addEventListener("input",(()=>{const e=Z.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ee&&(s.value=`${te}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(ne.style.color="orange",i.setAttribute("disabled","true")):(ie.style.display="none",ne.style.color="green",i.removeAttribute("disabled"))),ne.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=Z.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(ie.style.display="block")})))})),a.appendChild(s),a.appendChild(o),i.appendChild(a),Z.appendChild(i)})),X.appendChild(Z),X.appendChild(ne),X.appendChild(ie),c.appendChild(X);break;default:return v}c.id=`magicfeedback-${u}`,c.setAttribute("name",m),c.classList.add(l),(void 0!==b||null!==k)&&(c.value=k||b),["RADIO","MULTIPLECHOICE"].includes(h)||(c.classList.add("magicfeedback-input"),c.required=f);const w=document.createElement("label");if(w.setAttribute("for",`magicfeedback-${u}`),w.textContent=s(p,i),w.classList.add("magicfeedback-label"),["CONSENT"].includes(h))v.classList.add("magicfeedback-consent-container"),v.appendChild(c),v.appendChild(w);else{if("slim"!==t&&(v.appendChild(w),void 0!==(null==y?void 0:y.general)&&""!==(null==y?void 0:y.general))){const Ae=document.createElement("img");Ae.src=null==y?void 0:y.general,Ae.classList.add("magicfeedback-image"),Ae.style.maxWidth="auto",Ae.style.height="400px",Ae.style.margin="10px 0",v.appendChild(Ae)}if("LONGTEXT"===h&&x>0){const Te=document.createElement("div");if(Te.classList.add("magicfeedback-counter"),Te.textContent=`${c.value.length}/${x}`,Te.style.textAlign="right",Te.style.fontSize="15px",Te.style.marginTop="5px",c.addEventListener("input",(()=>{Te.textContent=`${c.value.length}/${x}`})),v.appendChild(c),v.appendChild(Te),(null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const Le=document.createElement("div");Le.classList.add("magicfeedback-skip-container"),Le.classList.add("magicfeedback-checkbox-container"),Le.style.display="flex",Le.style.justifyContent="flex-start";const Oe=document.createElement("input");Oe.classList.add("magicfeedback-skip"),Oe.type="checkbox",Oe.id=`skip-${m}`,Oe.name=m,Oe.value="-",Oe.style.cursor="pointer";const Se=document.createElement("label");Se.htmlFor=`skip-${m}`,Se.textContent=null==y?void 0:y.extraOptionText,Se.style.fontSize="15px",Se.style.cursor="pointer",Se.style.margin="0 5px",Oe.addEventListener("click",(()=>{c.value="-",r&&r()})),Le.appendChild(Oe),Le.appendChild(Se),v.appendChild(Le)}}else v.appendChild(c)}return v}(t,i,r,d);c.push(e)}})),c},t.renderActions=function(e="",t,i="Submit",n="Back",a="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=n||"Back",r.addEventListener("click",t),r.addEventListener("click",(()=>{o.removeAttribute("disabled")})),"MAGICSURVEY"===e&&s.appendChild(r),s.appendChild(o),s},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,i=!1,n="Go!"){const a=document.createElement("div");a.classList.add("magicfeedback-start-message-container");const s=document.createElement("div");s.classList.add("magicfeedback-start-message"),s.innerHTML=e;const o=document.createElement("button");return o.id="magicfeedback-start-message-button",o.classList.add("magicfeedback-start-message-button"),o.textContent=n,o.addEventListener("click",(()=>t())),a.appendChild(s),i&&a.appendChild(o),a}},341:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const s=a(i(98)),o=a(i(147)),r=i(374),d={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,a){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return a.log(`Received form for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),null}}))},t.getQuestions=function(e,t,i,a){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return a.log(`Received questions for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),[]}}))},t.sendFeedback=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield n.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield n.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},147:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.8","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},function i(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,i),s.exports}(607).default;var e,t}));
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(global,(()=>(()=>{"use strict";var e={290:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=a(i(519));let s=null;s||(s=(0,n.default)()),t.default=s},519:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function o(e){try{d(a.next(e))}catch(e){s(e)}}function r(e){try{d(a.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(954),s=i(712),o=i(5),r=i(341),d=i(290);t.default=function(){const e=new s.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?d.HOST_API_URL_DEV:d.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,n,s,o=!0,d,c){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),n||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:n,privateKey:c,completed:o,id:d,feedback:s};try{const e=yield(0,r.sendFeedback)(a,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,a){return i||t.err("No appID provided"),a||t.err("No publicKey provided"),new n.Form(e,i,a)}}}},314:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.History=void 0,t.History=class{constructor(){this.items=[]}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}rollback(){return this.items.pop()}front(){return this.items[0]}back(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function o(e){try{d(a.next(e))}catch(e){s(e)}}function r(e){try{d(a.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const n=i(5),s=i(341),o=i(183),r=i(24),d=i(804),c=i(116),l=i(314),u=i(457);t.Form=class{constructor(e,t,i){this.config=e,this.log=new n.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.getDataFromStorage(),this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new l.History,this.graph=new r.PageGraph([]),this.progress=0,this.total=0,this.followup=!1}getDataFromStorage(){const e=localStorage.getItem(`magicfeedback-${this.appId}`);e&&new Date(JSON.parse(e).savedAt)<new Date((new Date).getTime()+864e5)&&(this.formData=JSON.parse(e),(0,s.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,a;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),(null===(a=this.formData.style)||void 0===a?void 0:a.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm())})))}generate(e,t){var i,n,o;return a(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e,void 0!==this.formData&&this.formData||(this.formData=yield(0,s.getForm)(this.url,this.appId,this.publicKey,this.log)),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),void 0===this.formData.questions||!this.formData.questions)throw new Error(`No questions for app ${this.appId}`);0===(null===(i=this.formData.pages)||void 0===i?void 0:i.length)&&this.formatPages(),null===(n=this.formData.questions)||void 0===n||n.sort(((e,t)=>e.position-t.position)),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(o=this.formData.style)||void 0===o?void 0:o.startMessage)?yield this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}formatPages(){var e;if(this.formData)switch(this.formData.identity){case"MAGICSURVEY":this.formData.pages=[],null===(e=this.formData.questions)||void 0===e||e.forEach((e=>{var t,i;const a=new c.PageRoute(e.id,e.ref,c.OperatorType.NOEQUAL,null,c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),n=new d.Page(e.position.toString(),e.position,this.appId,[e],[a]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(n)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,n;return a(this,void 0,void 0,(function*(){try{if(this.formData&&(null===(e=this.formData.pages)||void 0===e?void 0:e.length)>0){this.graph=new r.PageGraph(this.formData.pages.sort(((e,t)=>e.position-t.position)));let e=this.generateContainer();const a=document.createElement("form");a.classList.add("magicfeedback-form"),a.id="magicfeedback-"+this.appId;const s=document.createElement("div");s.classList.add("magicfeedback-questions"),s.id="magicfeedback-questions-"+this.appId;const d=this.graph.getFirstPage();if(!d)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),d.elements=(0,o.renderQuestions)(d.questions,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],(()=>this.send())),null===(i=d.elements)||void 0===i||i.forEach((e=>s.appendChild(e))),a.appendChild(s),this.history.enqueue(d),e.appendChild(a),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(n=this.formData)||void 0===n?void 0:n.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);a.appendChild(e)}a.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData}))}}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}startForm(){this.generateForm()}generateWelcomeMessage(e){return a(this,void 0,void 0,(function*(){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){return a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const n=this.history.back();if(!n)throw new Error("No page found");const s=n.getRequiredQuestions();for(const e of s)if(!this.feedback.answers.find((t=>t.key===e&&t.value.length>0)))return void this.log.err(`The question ${e} is required`);const o=yield this.pushAnswers(!1);o&&(this.id=o,yield this.processNextQuestion(a)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,followup:this.followup,error:o?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;const a=e.querySelectorAll(".magicfeedback-input");a.forEach((e=>{const n=e.type,o=e.classList[0],r={key:e.name,value:[]},d="magicfeedback-consent"===o?e.checked.toString():e.value;if(r.key&&""!==r.key)switch(n){case"radio":case"checkbox":if("magicfeedback-consent"===o||e.checked){if(e.id.includes("matrix")){const t=e.id.split("-")[e.id.split("-").length-1];let i="";a.forEach((e=>{e.checked&&e.id.includes(`matrix-${t}`)&&(i+=e.value+", ")})),i=i.slice(0,-2),r.value.push(`${t}: ${i}`)}else r.value.push(d);const i=t.findIndex((e=>e.key===r.key));-1!==i?t[i].value=[...t[i].value,...r.value]:t.push(r)}break;default:if(""!==d){if("email"===n){if(!(0,s.validateEmail)(d)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[d]})}if(e.id.includes("point-system")){const t=e.id.split("-")[e.id.split("-").length-1];r.value.push(`${t}: ${d}%`)}else r.value.push(d);const a=t.findIndex((e=>e.key===r.key));-1!==a?t[a].value=[...t[a].value,...r.value]:t.push(r)}}})),this.feedback.answers=i?[]:t}finish(){if(this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer(),this.pushAnswers(!0)}pushAnswers(e=!1){return a(this,void 0,void 0,(function*(){try{const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){var t;return a(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),a={answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,s.getFollowUpQuestion)(i,a,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i;return a(this,void 0,void 0,(function*(){const a=this.history.back();if(!a)throw new Error("No page found");const n=a.getFollowupQuestions();if((null==n?void 0:n.length)>0){const s=[];for(const e of n){const t=a.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&s.push(e)}}if(s.length>0){this.followup=!0;const n=new d.Page(a.id,a.position,this.appId,s,a.edges),r=new u.PageNode(a.id,a.position,a.edges,n,s);r.elements=(0,o.renderQuestions)(s,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],(()=>this.send())),this.history.enqueue(r),e.removeChild(e.childNodes[0]),null===(i=r.elements)||void 0===i||i.forEach((t=>e.appendChild(t)))}else this.renderNextQuestion(e,a)}else this.renderNextQuestion(e,a)}))}renderNextQuestion(e,t){var i,a;this.followup=!1;const n=this.graph.getNextPage(t,this.feedback.answers);n?(this.progress=this.total-this.graph.findDepth(n.id),n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(i=this.formData)||void 0===i?void 0:i.lang[0],(()=>this.send())),e.removeChild(e.childNodes[0]),null===(a=n.elements)||void 0===a||a.forEach((t=>e.appendChild(t))),this.history.enqueue(n)):this.finish()}back(){var e;if(0===this.history.size())return;console.log("Back",this.history);const t=document.getElementById("magicfeedback-questions-"+this.appId);t&&t.childNodes.length>0&&t.removeChild(t.childNodes[0]),this.history.rollback();const i=this.history.back();i&&(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e))))}}},804:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Page=void 0,t.Page=class{constructor(e,t,i,a,n){this.id=e,this.position=t,this.generatedAt=(new Date).toISOString(),this.updatedAt=(new Date).getTime(),this.status="ACTIVE",this.integrationId=i,this.integrationQuestions=a,this.integrationPageRoutes=n}}},24:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const a=i(457),n=i(116);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach((e=>{const t=new a.PageNode(e.id,e.position,e.integrationPageRoutes||[],e,e.integrationQuestions);this.nodes.set(t.id,t)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(e)for(const t of this.nodes.values())if(t.position===e.position+1)return t.id}getFirstPage(){let e,t=Number.MAX_VALUE;for(const i of this.nodes.values())i.position<t&&(t=i.position,e=i);return e}getNextPage(e,t){if(!e)return;const i=e.edges.find((e=>{const i=null==t?void 0:t.filter((t=>t.key===e.questionRef));if(!i)return!1;switch(e.typeOperator){case n.OperatorType.EQUAL:return i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case n.OperatorType.NOEQUAL:return!i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case n.OperatorType.GREATER:return i.find((t=>t.value.find((t=>Number(t)>Number(e.value)))));case n.OperatorType.LESS:return i.find((t=>t.value.find((t=>Number(t)<Number(e.value)))));case n.OperatorType.GREATEREQUAL:return console.log(i),i.find((t=>t.value.find((t=>Number(t)>=Number(e.value)))));case n.OperatorType.LESSEQUAL:return i.find((t=>t.value.find((t=>Number(t)<=Number(e.value)))));case n.OperatorType.INQ:return i.find((t=>e.value.includes(t.value)));case n.OperatorType.NINQ:return!i.find((t=>e.value.includes(t.value)));default:return!1}}));if(!i){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}return this.getNodeById(i.transitionDestiny)}findDepth(e){const t=this.getNodeById(e);if(!t)return 0;const i=new Set;return this.DFSUtil(t,i,0)}findMaxDepth(){const e=new Set;let t=0;return this.nodes.forEach((i=>{e.has(i)||(t=Math.max(t,this.DFSUtil(i,e,0)))})),t}DFSUtil(e,t,i){t.add(e);let a=i;const n=this.getNextEdgeByDefault(e);for(const s of n?[...e.edges,{transitionDestiny:n}]:e.edges){const e=this.getNodeById(s.transitionDestiny);e&&!t.has(e)&&(a=Math.max(a,this.DFSUtil(e,t,i+1)))}return a}}},457:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,a,n){this.id=e,this.position=t,this.edges=i,this.data=a,this.questions=n,this.elements=[]}getFollowupQuestions(){return this.questions.filter((e=>e.followup)).map((e=>e.ref))}getRequiredQuestions(){return this.questions.filter((e=>e.require)).map((e=>e.ref))}}},116:(e,t)=>{var i,a,n,s;Object.defineProperty(t,"__esModule",{value:!0}),t.PageRoute=t.OperatorType=t.ConditionType=t.TransitionType=void 0,(s=t.TransitionType||(t.TransitionType={})).PAGE="PAGE",s.FINISH="FINISH",function(e){e.LOGICAL="LOGICAL"}(i=t.ConditionType||(t.ConditionType={})),(n=t.OperatorType||(t.OperatorType={})).EQUAL="EQUAL",n.NOEQUAL="NOEQUAL",n.GREATER="GREATER",n.LESS="LESS",n.GREATEREQUAL="GREATEREQUAL",n.LESSEQUAL="LESSEQUAL",n.INQ="INQ",n.NINQ="NINQ",n.DEFAULT="DEFAULT",function(e){e.ACTIVE="ACTIVE",e.DEPRECATED="DEPRECATED",e.DELETE="DELETE"}(a||(a={})),t.PageRoute=class{constructor(e,t,n,s,o,r,d){this.id=e,this.questionRef=t,this.typeCondition=i.LOGICAL,this.typeOperator=n,this.value=s,this.transition=o,this.transitionDestiny=r,this.status=a.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=d}}},244:(e,t)=>{var i,a;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(a=t.FEEDBACKAPPANSWERTYPE||(t.FEEDBACKAPPANSWERTYPE={})).CONTACT="CONTACT",a.MULTIPLECHOISE_IMAGE="MULTIPLECHOISE_IMAGE",a.EMAIL="EMAIL",a.RATING_STAR="RATING_STAR",a.RADIO="RADIO",a.MULTIPLECHOICE="MULTIPLECHOICE",a.SELECT="SELECT",a.TEXT="TEXT",a.LONGTEXT="LONGTEXT",a.NUMBER="NUMBER",a.RATING_EMOJI="RATING_EMOJI",a.RATING_NUMBER="RATING_NUMBER",a.DATE="DATE",a.BOOLEAN="BOOLEAN",a.PASSWORD="PASSWORD",a.CONSENT="CONSENT",a.MULTI_QUESTION_MATRIX="MULTI_QUESTION_MATRIX",a.POINT_SYSTEM="POINT_SYSTEM",a.PRIORITY_LIST="PRIORITY_LIST",t.QuestionType=class{},function(e){e.FORM="form",e.DIV="div"}(i||(i={}))},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا...";case"bn":return"এখানে আপনার"}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا...";case"bn":return"এখানে আপনার"}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا...";case"bn":return"এখানে আপনার"}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا...";case"bn":return"এখানে আপনার"}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا...";case"bn":return"এখানে আপনার"}}}},183:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const a=i(244),n=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}function o(e,t,i,a,n,s=!0){const o=document.createElement("div");o.classList.add("magicfeedback-rating-placeholder"),o.style.display="flex",o.style.justifyContent="space-between",o.style.width=n?`calc(100% - (100% / ${t+1}))`:"100%",o.style.marginRight="auto",s&&window.innerWidth<600&&(o.style.flexDirection="column");const r=document.createElement("span");r.textContent=i,r.classList.add("magicfeedback-rating-placeholder-value"),r.style.fontStyle="italic",r.style.fontSize="14px",r.style.textAlign="left",r.style.width="50%",s&&window.innerWidth<600&&(r.textContent=`${e} ➜ ${i}`,r.style.width="100%",r.style.textAlign="left",r.style.marginBottom="5px"),o.appendChild(r);const d=document.createElement("span");return d.textContent=a,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontStyle="italic",d.style.fontSize="14px",d.style.textAlign="right",d.style.width="50%",s&&window.innerWidth<600&&(d.textContent=`${t} ➜ ${a}`,d.style.width="100%",d.style.textAlign="left",d.style.marginBottom="5px"),o.appendChild(d),o}t.renderQuestions=function e(t,i="standard",r="en",d){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var l,u;if((null===(u=null===(l=null==t?void 0:t.questionType)||void 0===l?void 0:l.conf)||void 0===u?void 0:u.length)>0){let a=document.createElement("div");a.classList.add("magicfeedback-div"),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,r,d).forEach((e=>{a.appendChild(e)})),c.push(a)}else{const e=function(e,t,i,r){var d;let c,l,{id:u,title:p,type:m,ref:h,require:f,value:g,defaultValue:b,assets:v}=e,y=document.createElement("div");y.classList.add("magicfeedback-div");const E="slim"===t?s(p,i):null==v?void 0:v.placeholder,k=(x=u,new URLSearchParams(window.location.search).get(x)),C=v.maxCharacters||300;var x;switch(m){case a.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=E||n.placeholder.answer(i||"en"),l="magicfeedback-text";break;case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,C>0&&(c.maxLength=C),c.placeholder=E||n.placeholder.answer(i||"en"),l="magicfeedback-longtext";break;case a.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?s(p,i):n.placeholder.number(i||"en"),l="magicfeedback-number",g.length&&(g.sort(((e,t)=>Number(e)-Number(t))),c.max=g[g.length-1],c.min=g[0],c.value=g[0]);break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),l="magicfeedback-"+("MULTIPLECHOICE"===m?"checkbox":"radio"),v.extraOption&&g.push(v.extraOptionText),g.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===m?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${h}-${t}`,r.type="MULTIPLECHOICE"===m?"checkbox":"radio",r.name=h,r.value=e,r.classList.add(l),r.classList.add("magicfeedback-input"),m===a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&v.maxOptions&&v.maxOptions>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${h}"]:checked`).length>v.maxOptions&&(r.checked=!1)})),e!==b&&e!==k||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${h}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${h}`);i&&v.extraOption&&(t.target.checked&&e===v.extraOptionText?i.style.display="block":i.style.display="none")})),s.appendChild(r),s.appendChild(o),c.appendChild(s),v.extraOption&&e===v.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder=v.extraOptionPlaceholder||n.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${h}`,e.name=`extra-option-${h}`,e.style.display="none",c.appendChild(e)}}));break;case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),l="magicfeedback-radio";const L=document.createElement("div");L.classList.add("magicfeedback-boolean-container"),L.style.display="flex",L.style.flexDirection="row",L.style.justifyContent="space-between",L.style.width="70%",L.style.margin="auto",(v.addIcon?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];case"bn":return["হ্যাঁ","না"];default:return["Yes","No"]}}(i)).forEach(((e,t)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${h}-${t}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const a=document.createElement("label");a.htmlFor=`rating-${h}-${t}`,a.textContent=e,a.style.margin="0",a.style.padding="0";const n=document.createElement("input");n.id=`rating-${h}-${t}`,n.type="radio",n.name=h,n.value=e,n.classList.add(l),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",n.addEventListener("change",(()=>{r&&r()})),i.appendChild(n),i.appendChild(a),L.appendChild(i)})),c.appendChild(L);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),l="magicfeedback-rating";const A=document.createElement("div");A.classList.add("magicfeedback-rating-container");const T=v.max?Number(v.max):5,S=v.min?Number(v.min):1,O=o(S,T,v.minPlaceholder,v.maxPlaceholder,v.extraOption);for(let ae=S;ae<=T;ae++){const ne=document.createElement("div");ne.classList.add("magicfeedback-rating-option");const se=document.createElement("label");se.htmlFor=`rating-${h}-${ae}`,se.classList.add("magicfeedback-rating-option-label-container");const oe=document.createElement("label");oe.htmlFor=`rating-${h}-${ae}`,oe.textContent=ae.toString();const re=document.createElement("img");if(re.alt=`face-${h}-${ae}`,re.className=`rating-image${ae}`,0===S&&10===T)re.src=`https://magicfeedback-c6458-dev.web.app/assets/${ae}.svg`;else if(1===S&&5===T)switch(ae){case 1:re.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:re.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:re.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:re.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:re.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const ce=Math.round(10/(T-S)*(ae-S));re.src=`https://magicfeedback-c6458-dev.web.app/assets/${ce}.svg`}const de=document.createElement("input");de.id=`rating-${h}-${ae}`,de.type="radio",de.name=h,de.value=ae.toString(),de.classList.add(l),de.classList.add("magicfeedback-input"),se.appendChild(de),se.appendChild(re),se.appendChild(oe),ne.appendChild(se),A.appendChild(ne)}if(v.extraOption&&v.extraOptionText){const le=document.createElement("div");le.classList.add("magicfeedback-rating-option");const ue=document.createElement("label");ue.htmlFor=`rating-${h}-extra`,ue.classList.add("magicfeedback-rating-option-label-container");const pe=document.createElement("label");pe.htmlFor=`rating-${h}-extra`,pe.textContent=v.extraOptionText;const me=document.createElement("img");me.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",me.alt=`face-${h}-extra`,me.className="magicfeedback-rating-image-extra";const he=document.createElement("input");he.id=`rating-${h}-extra`,he.type="radio",he.name=h,he.value="-",he.classList.add(l),he.classList.add("magicfeedback-input"),ue.appendChild(he),ue.appendChild(me),ue.appendChild(pe),le.appendChild(ue),A.appendChild(le)}c.appendChild(O),c.appendChild(A);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),l="magicfeedback-rating-number";const N=document.createElement("div");N.classList.add("magicfeedback-rating-number-container");const P=v.max?Number(v.max):5,I=v.min?Number(v.min):1,D=o(I,P,v.minPlaceholder,v.maxPlaceholder,v.extraOption);for(let fe=I;fe<=P;fe++){const ge=document.createElement("div");ge.classList.add("magicfeedback-rating-number-option");const be=document.createElement("label");be.htmlFor=`rating-${h}-${fe}`,be.classList.add("magicfeedback-rating-number-option-label-container");const ve=document.createElement("label");ve.htmlFor=`rating-${h}-${fe}`,ve.textContent=fe.toString();const ye=document.createElement("input");ye.id=`rating-${h}-${fe}`,ye.type="radio",ye.name=h,ye.value=fe.toString(),ye.classList.add(l),ye.classList.add("magicfeedback-input"),be.appendChild(ye),be.appendChild(ve),ge.appendChild(be),N.appendChild(ge)}if(v.extraOption&&v.extraOptionText){const Ee=document.createElement("div");Ee.classList.add("magicfeedback-rating-number-option");const ke=document.createElement("label");ke.htmlFor=`rating-${h}-extra`,ke.classList.add("magicfeedback-rating-number-option-label-container");const Ce=document.createElement("label");Ce.htmlFor=`rating-${h}-extra`,Ce.textContent=v.extraOptionText;const xe=document.createElement("input");xe.id=`rating-${h}-extra`,xe.type="radio",xe.name=h,xe.value="-",xe.classList.add(l),xe.classList.add("magicfeedback-input"),ke.appendChild(xe),ke.appendChild(Ce),Ee.appendChild(ke),N.appendChild(Ee)}c.appendChild(D),c.appendChild(N);break;case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),l="magicfeedback-rating-star";const $=function(e,t,i){const a="magicfeedback-rating-star-selected",n=document.createElement("div");n.classList.add("magicfeedback-rating-star-container"),n.style.maxWidth="300px",n.style.margin="auto";for(let t=1;t<=5;t++){const i=document.createElement("label");i.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${t}`,s.type="radio",s.name=e,s.value=t.toString(),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.classList.add("magicfeedback-input"),s.addEventListener("change",(()=>{const e=n.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(s.value)?e[t].classList.contains(a)||e[t].classList.add(a):e[t].classList.contains(a)&&e[t].classList.remove(a)})),i.appendChild(s);const o=document.createElement("label");o.htmlFor=`rating-${e}-${t}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",i.appendChild(o),n.appendChild(i)}return n.appendChild(o(1,5,t,i,!1,!1)),n}(h,v.minPlaceholder,v.maxPlaceholder);c.appendChild($);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),l="magicfeedback-multiple-choice-image";const M=document.createElement("div");M.classList.add("magicfeedback-multiple-choice-image-container"),M.style.display="flex",M.style.flexDirection="row",M.style.flexWrap="wrap",M.style.justifyContent="center";const F=g.length;let R=1,_=1;switch(F){case 1:case 2:case 3:R=F,_=1;break;case 4:case 5:case 6:_=2,R=Math.ceil(F/_);break;case 7:case 8:case 9:_=3,R=Math.ceil(F/_);break;default:_=4,R=Math.ceil(F/_)}const q=void 0!==(null==v?void 0:v.addTitle)&&v.addTitle,B=void 0!==(null==v?void 0:v.multiOption)&&v.multiOption,U=void 0!==(null==v?void 0:v.randomPosition)&&v.randomPosition,j=void 0!==(null==v?void 0:v.extraOption)&&v.extraOption;function Q(e){try{const{position:t,url:i,value:a}=e,n=document.createElement("label");n.classList.add("magicfeedback-multiple-choice-image-option"),n.style.width=`calc( ${100/R}% - 10px)`,n.style.height=`calc( ${100/_}% - 10px)`,n.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${h}-${t}`,s.classList.add("magicfeedback-image-option-label-container"),s.style.display="flex",s.style.flexDirection="column",s.addEventListener("mouseover",(()=>{s.style.border="2px solid #000"})),s.addEventListener("mouseout",(()=>{s.style.border="none"})),s.addEventListener("click",(()=>{s.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=a,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${h}-${t}`,r.type=B?"checkbox":"radio",r.name=h,r.value=a,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.backgroundPosition="center",d.style.width="100%",d.style.height="100%",d.style.objectFit="cover",d.style.margin="auto",s.appendChild(r),s.appendChild(d),q&&s.appendChild(o),n.appendChild(s),M.appendChild(n)}catch(e){console.error(e)}}U&&(g=g.sort((()=>Math.random()-.5))),g.forEach((e=>Q(JSON.parse(e)))),j&&v.extraOptionValue&&v.extraOptionValue.length>0&&Q(v.extraOptionValue[0]),c.appendChild(M);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),l="magicfeedback-select";const G=document.createElement("option");G.value="",G.text="slim"===t?s(p,i):b||"Select an option",G.disabled=!0,G.selected=!0,c.appendChild(G),g.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)}));break;case a.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=f,c.placeholder=E||n.placeholder.date(i||"en"),l="magicfeedback-date";break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),l="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${u}`,c.name=h,c.value="true",c.required=f,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input");break;case a.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=f,c.placeholder=E||"you@example.com",l="magicfeedback-email";break;case a.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=f,c.placeholder=E||n.placeholder.password(i||"en"),l="magicfeedback-password";break;case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),l="magicfeedback-multi-question-matrix";const K=document.createElement("div");K.classList.add("magicfeedback-multi-question-matrix-container");const W=document.createElement("table");W.classList.add("magicfeedback-multi-question-matrix-table");const Y=document.createElement("thead");Y.classList.add("magicfeedback-multi-question-matrix-header"),Y.style.paddingBottom="15px";const H=document.createElement("tr");["",...g].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",H.appendChild(t)})),Y.appendChild(H);const V=document.createElement("tbody");(null===(d=null==v?void 0:v.options)||void 0===d?void 0:d.length)>0&&v.options.split("|").forEach((e=>{const t=document.createElement("tr");t.style.paddingBottom="15px";const i=document.createElement("td");i.classList.add("magicfeedback-multi-question-matrix-row-label");const a=document.createElement("label");a.classList.add("magicfeedback-multi-question-matrix-label"),a.style.paddingRight="15px",a.textContent=e,i.appendChild(a),t.appendChild(i),g.forEach((i=>{const a=document.createElement("td"),n=document.createElement("input");n.type="checkbox",n.name=h,n.value=i,n.id=`matrix-${e}`,n.classList.add("magicfeedback-input"),n.style.padding="0 10px",a.appendChild(n),t.appendChild(a)})),V.appendChild(t)})),W.appendChild(Y),W.appendChild(V),K.appendChild(W),c.appendChild(K);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),l="magicfeedback-priority-list";const J=document.createElement("div");J.classList.add("magicfeedback-priority-list-container");const z=document.createElement("ul");z.classList.add("magicfeedback-priority-list-list"),g.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-priority-list-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const a=document.createElement("input");a.classList.add("magicfeedback-input-magicfeedback-priority-list"),a.classList.add("magicfeedback-input"),a.type="hidden",a.id=`priority-list-${h}`,a.name=h,a.value=`${t+1}. ${e}`,i.appendChild(a);const n=document.createElement("label");n.classList.add("magicfeedback-priority-list-item-label"),n.textContent=`${t+1}. ${e}`,i.appendChild(n);const s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between";const o=document.createElement("img");o.classList.add("magicfeedback-priority-list-arrow-up"),o.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",o.style.width="20px",o.style.height="20px",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.visibility=0===t?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const d=i.previousElementSibling;if(d){const c=Number(a.value.split(".")[0])-1;a.value=`${c}. ${e}`,n.textContent=`${c}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===g.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),m=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&m){const e=Number(l.value.split(".")[0])+1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===g.length?"hidden":"visible"}z.insertBefore(i,d)}})),s.appendChild(o);const r=document.createElement("img");r.classList.add("magicfeedback-priority-list-arrow-down"),r.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",r.style.width="20px",r.style.height="20px",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(180deg)",r.style.visibility=t===g.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,s;const d=i.nextElementSibling;if(d){const c=Number(a.value.split(".")[0])+1;a.value=c.toString(),n.textContent=`${c.toString()}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===g.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),m=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&m){const e=Number(l.value.split(".")[0])-1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===g.length?"hidden":"visible"}z.insertBefore(d,i)}})),s.appendChild(r),i.appendChild(s),z.appendChild(i)})),J.appendChild(z),c.appendChild(J);break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),l="magicfeedback-point-system";const X=document.createElement("div");X.classList.add("magicfeedback-point-system-container");const Z=document.createElement("ul");Z.classList.add("magicfeedback-point-system-list"),Z.style.padding="0";const ee=100,te=ee/g.length,ie=document.createElement("div");ie.classList.add("magicfeedback-point-system-total"),ie.textContent="0 / 100 %",ie.style.textAlign="right",ie.style.fontSize="0.8em",ie.style.color="#999",ie.style.marginTop="5px",g.forEach((e=>{const t=document.createElement("li");t.classList.add("magicfeedback-point-system-item"),t.style.display="flex",t.style.justifyContent="space-between",t.style.alignItems="center",t.style.margin="5px";const i=document.createElement("label");i.textContent=e,t.appendChild(i);const a=document.createElement("span");a.classList.add("magicfeedback-point-system-input-container");const n=document.createElement("input");n.name=h,n.id=`point-system-${e}`,n.type="number",n.min="0",n.max=`${ee}`,n.value="0",n.classList.add("magicfeedback-input"),n.style.width="40px",n.style.border="0",n.style.textAlign="center",n.style.margin="0 5px";const s=document.createElement("span");s.textContent="%",s.style.color="#000",n.addEventListener("input",(()=>{const e=Z.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ee&&(n.value=`${te}%`,t-=Number(n.value)),ie.textContent=`${t} / 100 %`})),a.appendChild(n),a.appendChild(s),t.appendChild(a),Z.appendChild(t)})),X.appendChild(Z),X.appendChild(ie),c.appendChild(X);break;default:return y}c.id=`magicfeedback-${u}`,c.setAttribute("name",h),c.classList.add(l),(void 0!==b||null!==k)&&(c.value=k||b),["RADIO","MULTIPLECHOICE"].includes(m)||(c.classList.add("magicfeedback-input"),c.required=f);const w=document.createElement("label");if(w.setAttribute("for",`magicfeedback-${u}`),w.textContent=s(p,i),w.classList.add("magicfeedback-label"),["CONSENT"].includes(m))y.classList.add("magicfeedback-consent-container"),y.appendChild(c),y.appendChild(w);else{if("slim"!==t&&(y.appendChild(w),void 0!==(null==v?void 0:v.general)&&""!==(null==v?void 0:v.general))){const we=document.createElement("img");we.src=v.general,we.classList.add("magicfeedback-image"),we.style.maxWidth="auto",we.style.height="400px",we.style.margin="10px 0",y.appendChild(we)}if("LONGTEXT"===m&&C>0){const Le=document.createElement("div");if(Le.classList.add("magicfeedback-counter"),Le.textContent=`${c.value.length}/${C}`,Le.style.textAlign="right",Le.style.fontSize="0.8em",Le.style.color="#999",Le.style.marginTop="5px",c.addEventListener("input",(()=>{Le.textContent=`${c.value.length}/${C}`})),y.appendChild(c),y.appendChild(Le),v.extraOption&&v.extraOptionText){const Ae=document.createElement("div");Ae.classList.add("magicfeedback-skip-container"),Ae.classList.add("magicfeedback-checkbox-container"),Ae.style.display="flex",Ae.style.justifyContent="flex-start";const Te=document.createElement("input");Te.classList.add("magicfeedback-skip"),Te.type="checkbox",Te.id=`skip-${h}`,Te.name=h,Te.value="-",Te.style.cursor="pointer";const Se=document.createElement("label");Se.htmlFor=`skip-${h}`,Se.textContent=v.extraOptionText,Se.style.fontSize="0.8em",Se.style.color="#999",Se.style.cursor="pointer",Se.style.margin="0 5px",Te.addEventListener("click",(()=>{c.value="-",r&&r()})),Ae.appendChild(Te),Ae.appendChild(Se),y.appendChild(Ae)}}else y.appendChild(c)}return y}(t,i,r,d);c.push(e)}})),c},t.renderActions=function(e="",t,i="Submit",a="Back",n="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?n||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=a||"Back",r.addEventListener("click",t),"MAGICSURVEY"===e&&s.appendChild(r),s.appendChild(o),s},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,i=!1,a="Go!"){const n=document.createElement("div");n.classList.add("magicfeedback-start-message-container");const s=document.createElement("div");s.classList.add("magicfeedback-start-message"),s.innerHTML=e;const o=document.createElement("button");return o.id="magicfeedback-start-message-button",o.classList.add("magicfeedback-start-message-button"),o.textContent=a,o.addEventListener("click",(()=>t())),n.appendChild(s),i&&n.appendChild(o),n}},341:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function o(e){try{d(a.next(e))}catch(e){s(e)}}function r(e){try{d(a.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const s=n(i(31)),o=n(i(147)),r=i(374),d={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,n){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:d});if(a.ok){const e=yield a.json();return n.log(`Received form for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),null}}))},t.getQuestions=function(e,t,i,n){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:d});if(a.ok){const e=yield a.json();return n.log(`Received questions for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(a.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield a.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(a.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield a.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.8-beta.9","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},i=function i(a){var n=t[a];if(void 0!==n)return n.exports;var s=t[a]={exports:{}};return e[a].call(s.exports,s,s.exports,i),s.exports}(607);return i.default})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(global,(()=>(()=>{"use strict";var e={290:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=a(i(519));let s=null;s||(s=(0,n.default)()),t.default=s},519:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function o(e){try{d(a.next(e))}catch(e){s(e)}}function r(e){try{d(a.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(954),s=i(712),o=i(5),r=i(341),d=i(290);t.default=function(){const e=new s.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?d.HOST_API_URL_DEV:d.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,n,s,o=!0,d,c){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),n||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:n,privateKey:c,completed:o,id:d,feedback:s};try{const e=yield(0,r.sendFeedback)(a,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,a){return i||t.err("No appID provided"),a||t.err("No publicKey provided"),new n.Form(e,i,a)}}}},314:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.History=void 0,t.History=class{constructor(){this.items=[]}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}rollback(){return this.items.pop()}front(){return this.items[0]}back(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function o(e){try{d(a.next(e))}catch(e){s(e)}}function r(e){try{d(a.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const n=i(5),s=i(341),o=i(183),r=i(24),d=i(804),c=i(116),l=i(314),u=i(457);t.Form=class{constructor(e,t,i){this.config=e,this.log=new n.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.getDataFromStorage(),this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new l.History,this.graph=new r.PageGraph([]),this.progress=0,this.total=0,this.followup=!1}getDataFromStorage(){const e=localStorage.getItem(`magicfeedback-${this.appId}`);e&&new Date(JSON.parse(e).savedAt)<new Date((new Date).getTime()+864e5)&&(this.formData=JSON.parse(e),(0,s.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,a;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),(null===(a=this.formData.style)||void 0===a?void 0:a.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm())})))}generate(e,t){var i,n,o;return a(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e,void 0!==this.formData&&this.formData||(this.formData=yield(0,s.getForm)(this.url,this.appId,this.publicKey,this.log)),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),void 0===this.formData.questions||!this.formData.questions)throw new Error(`No questions for app ${this.appId}`);this.formData.pages&&0!==(null===(i=this.formData.pages)||void 0===i?void 0:i.length)||this.formatPages(),null===(n=this.formData.questions)||void 0===n||n.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(o=this.formData.style)||void 0===o?void 0:o.startMessage)?yield this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}formatPages(){var e;if(this.formData)switch(this.formData.identity){case"MAGICSURVEY":this.formData.pages=[],null===(e=this.formData.questions)||void 0===e||e.forEach((e=>{var t,i;const a=new c.PageRoute(e.id,e.ref,c.OperatorType.NOEQUAL,null,c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),n=new d.Page(e.position.toString(),e.position,this.appId,[e],[a]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(n)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i;return a(this,void 0,void 0,(function*(){try{if(!this.formData||!this.formData.pages||0===this.formData.pages.length)throw new Error("No form data");this.graph=new r.PageGraph(this.formData.pages.sort(((e,t)=>e.position-t.position)));let a=this.generateContainer();const n=document.createElement("form");n.classList.add("magicfeedback-form"),n.id="magicfeedback-"+this.appId;const s=document.createElement("div");s.classList.add("magicfeedback-questions"),s.id="magicfeedback-questions-"+this.appId;const d=this.graph.getFirstPage();if(!d)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),d.elements=(0,o.renderQuestions)(d.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),null===(t=d.elements)||void 0===t||t.forEach((e=>s.appendChild(e))),n.appendChild(s),this.history.enqueue(d),a.appendChild(n),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(i=this.formData)||void 0===i?void 0:i.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);n.appendChild(e)}n.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}startForm(){this.generateForm()}generateWelcomeMessage(e){return a(this,void 0,void 0,(function*(){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){return a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const n=this.history.back();if(!n)throw new Error("No page found");const s=n.getRequiredQuestions();for(const e of s)if(!this.feedback.answers.find((t=>t.key===e&&t.value.length>0)))return void this.log.err(`The question ${e} is required`);const o=yield this.pushAnswers(!1);o&&(this.id=o,yield this.processNextQuestion(a)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,followup:this.followup,error:o?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const a=e.type,n=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===n?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(a){case"radio":case"checkbox":if("magicfeedback-consent"===n||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===a){if(!(0,s.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}if(e.id.includes("point-system")){const t="point-system-"+e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${r}%`)}else o.value.push(r);const n=t.findIndex((e=>e.key===o.key));-1!==n?t[n].value=[...t[n].value,...o.value]:t.push(o)}}})),console.log(t);const a=t.filter((e=>e.key.includes("matrix")));null==a||a.forEach((e=>{const i=t.find((t=>t.key===e.key));i&&(i.value=[...new Set(i.value)])}));const n=t.filter((e=>e.key.includes("point-system")));null==n||n.forEach((e=>{100!==e.value.reduce(((e,t)=>{const i=t.split(": ")[1];return e+Number(i.replace("%",""))}),0)&&(this.log.err("The sum of the point system questions must be 100%"),i=!0)})),this.feedback.answers=i?[]:t}finish(){if(this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer(),this.pushAnswers(!0)}pushAnswers(e=!1){return a(this,void 0,void 0,(function*(){try{const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){var t;return a(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),a={answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,s.getFollowUpQuestion)(i,a,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i;return a(this,void 0,void 0,(function*(){const a=this.history.back();if(!a)throw new Error("No page found");const n=a.getFollowupQuestions();if((null==n?void 0:n.length)>0){const s=[];for(const e of n){const t=a.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&s.push(e)}}if(s.length>0){this.followup=!0;const n=new d.Page(a.id,a.position,this.appId,s,a.edges),r=new u.PageNode(a.id,a.position,a.edges,n,s);r.elements=(0,o.renderQuestions)(s,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],(()=>this.send())),this.history.enqueue(r),e.removeChild(e.childNodes[0]),null===(i=r.elements)||void 0===i||i.forEach((t=>e.appendChild(t)))}else this.renderNextQuestion(e,a)}else this.renderNextQuestion(e,a)}))}renderNextQuestion(e,t){var i,a;this.followup=!1;const n=this.graph.getNextPage(t,this.feedback.answers);n?(this.progress=this.total-this.graph.findDepth(n.id),n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(i=this.formData)||void 0===i?void 0:i.lang[0],(()=>this.send())),e.removeChild(e.childNodes[0]),null===(a=n.elements)||void 0===a||a.forEach((t=>e.appendChild(t))),this.history.enqueue(n)):this.finish()}back(){var e;if(0===this.history.size())return;console.log("Back",this.history);const t=document.getElementById("magicfeedback-questions-"+this.appId);t&&t.childNodes.length>0&&t.removeChild(t.childNodes[0]),this.history.rollback();const i=this.history.back();i&&(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e))))}}},804:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Page=void 0,t.Page=class{constructor(e,t,i,a,n){this.id=e,this.position=t,this.generatedAt=(new Date).toISOString(),this.updatedAt=(new Date).getTime(),this.status="ACTIVE",this.integrationId=i,this.integrationQuestions=a,this.integrationPageRoutes=n}}},24:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const a=i(457),n=i(116);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach((e=>{const t=new a.PageNode(e.id,e.position,e.integrationPageRoutes||[],e,e.integrationQuestions);this.nodes.set(t.id,t)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(e)for(const t of this.nodes.values())if(t.position===e.position+1)return t.id}getFirstPage(){let e,t=Number.MAX_VALUE;for(const i of this.nodes.values())i.position<t&&(t=i.position,e=i);return e}getNextPage(e,t){if(!e)return;const i=e.edges.find((e=>{const i=null==t?void 0:t.filter((t=>t.key===e.questionRef));if(!i)return!1;switch(e.typeOperator){case n.OperatorType.EQUAL:return i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case n.OperatorType.NOEQUAL:return!i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case n.OperatorType.GREATER:return i.find((t=>t.value.find((t=>Number(t)>Number(e.value)))));case n.OperatorType.LESS:return i.find((t=>t.value.find((t=>Number(t)<Number(e.value)))));case n.OperatorType.GREATEREQUAL:return console.log(i),i.find((t=>t.value.find((t=>Number(t)>=Number(e.value)))));case n.OperatorType.LESSEQUAL:return i.find((t=>t.value.find((t=>Number(t)<=Number(e.value)))));case n.OperatorType.INQ:return i.find((t=>e.value.includes(t.value)));case n.OperatorType.NINQ:return!i.find((t=>e.value.includes(t.value)));default:return!1}}));if(!i){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}return this.getNodeById(i.transitionDestiny)}findDepth(e){const t=this.getNodeById(e);if(!t)return 0;const i=new Set;return this.DFSUtil(t,i,0)}findMaxDepth(){const e=new Set;let t=0;return this.nodes.forEach((i=>{e.has(i)||(t=Math.max(t,this.DFSUtil(i,e,0)))})),t}DFSUtil(e,t,i){t.add(e);let a=i;const n=this.getNextEdgeByDefault(e);for(const s of n?[...e.edges,{transitionDestiny:n}]:e.edges){const e=this.getNodeById(s.transitionDestiny);e&&!t.has(e)&&(a=Math.max(a,this.DFSUtil(e,t,i+1)))}return a}}},457:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,a,n){this.id=e,this.position=t,this.edges=i,this.data=a,this.questions=n,this.elements=[]}getFollowupQuestions(){return this.questions.filter((e=>e.followup)).map((e=>e.ref))}getRequiredQuestions(){return this.questions.filter((e=>e.require)).map((e=>e.ref))}}},116:(e,t)=>{var i,a,n,s;Object.defineProperty(t,"__esModule",{value:!0}),t.PageRoute=t.OperatorType=t.ConditionType=t.TransitionType=void 0,(s=t.TransitionType||(t.TransitionType={})).PAGE="PAGE",s.FINISH="FINISH",function(e){e.LOGICAL="LOGICAL"}(i=t.ConditionType||(t.ConditionType={})),(n=t.OperatorType||(t.OperatorType={})).EQUAL="EQUAL",n.NOEQUAL="NOEQUAL",n.GREATER="GREATER",n.LESS="LESS",n.GREATEREQUAL="GREATEREQUAL",n.LESSEQUAL="LESSEQUAL",n.INQ="INQ",n.NINQ="NINQ",n.DEFAULT="DEFAULT",function(e){e.ACTIVE="ACTIVE",e.DEPRECATED="DEPRECATED",e.DELETE="DELETE"}(a||(a={})),t.PageRoute=class{constructor(e,t,n,s,o,r,d){this.id=e,this.questionRef=t,this.typeCondition=i.LOGICAL,this.typeOperator=n,this.value=s,this.transition=o,this.transitionDestiny=r,this.status=a.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=d}}},244:(e,t)=>{var i,a;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(a=t.FEEDBACKAPPANSWERTYPE||(t.FEEDBACKAPPANSWERTYPE={})).CONTACT="CONTACT",a.MULTIPLECHOISE_IMAGE="MULTIPLECHOISE_IMAGE",a.EMAIL="EMAIL",a.RATING_STAR="RATING_STAR",a.RADIO="RADIO",a.MULTIPLECHOICE="MULTIPLECHOICE",a.SELECT="SELECT",a.TEXT="TEXT",a.LONGTEXT="LONGTEXT",a.NUMBER="NUMBER",a.RATING_EMOJI="RATING_EMOJI",a.RATING_NUMBER="RATING_NUMBER",a.DATE="DATE",a.BOOLEAN="BOOLEAN",a.PASSWORD="PASSWORD",a.CONSENT="CONSENT",a.MULTI_QUESTION_MATRIX="MULTI_QUESTION_MATRIX",a.POINT_SYSTEM="POINT_SYSTEM",a.PRIORITY_LIST="PRIORITY_LIST",t.QuestionType=class{},function(e){e.FORM="form",e.DIV="div"}(i||(i={}))},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا...";case"bn":return"এখানে আপনার"}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا...";case"bn":return"এখানে আপনার"}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا...";case"bn":return"এখানে আপনার"}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا...";case"bn":return"এখানে আপনার"}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا...";case"bn":return"এখানে আপনার"}},pointsystemerror:e=>{switch(e){case"en":default:return"The total points must be 100 %";case"es":return"El total de puntos debe ser 100 %";case"da":return"Samlet antal point skal være 100 %";case"fi":return"Kokonaispisteiden on oltava 100 %";case"sv":return"Totala poäng måste vara 100 %";case"no":return"Totalt antall poeng må være 100 %";case"ar":return"يجب أن تكون النقاط الإجمالية 100 %";case"bn":return"মোট পয়েন্ট 100 % হতে হবে"}}}},183:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const a=i(244),n=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}function o(e,t,i,a,n,s=!0){const o=document.createElement("div");o.classList.add("magicfeedback-rating-placeholder"),o.style.display="flex",o.style.justifyContent="space-between",o.style.width=n?`calc(100% - (100% / ${t+1}))`:"100%",o.style.marginRight="auto",s&&window.innerWidth<600&&(o.style.flexDirection="column");const r=document.createElement("span");r.textContent=i,r.classList.add("magicfeedback-rating-placeholder-value"),r.style.fontSize="15px",r.style.textAlign="left",r.style.width="50%",s&&window.innerWidth<600&&(r.textContent=`${e} ➜ ${i}`,r.style.width="100%",r.style.textAlign="left",r.style.marginBottom="5px"),o.appendChild(r);const d=document.createElement("span");return d.textContent=a,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="right",d.style.width="50%",s&&window.innerWidth<600&&(d.textContent=`${t} ➜ ${a}`,d.style.width="100%",d.style.textAlign="left",d.style.marginBottom="5px"),o.appendChild(d),o}t.renderQuestions=function e(t,i="standard",r="en",d){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var l,u;if((null===(u=null===(l=null==t?void 0:t.questionType)||void 0===l?void 0:l.conf)||void 0===u?void 0:u.length)>0){let a=document.createElement("div");a.classList.add("magicfeedback-div"),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,r,d).forEach((e=>{a.appendChild(e)})),c.push(a)}else{const e=function(e,t,i,r){var d;let c,l,{id:u,title:p,type:m,ref:h,require:f,value:g,defaultValue:v,assets:b}=e,y=document.createElement("div");y.classList.add("magicfeedback-div");const E="slim"===t?s(p,i):null==b?void 0:b.placeholder,k=(x=u,new URLSearchParams(window.location.search).get(x)),C=(null==b?void 0:b.maxCharacters)||0;var x;switch(m){case a.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=E||n.placeholder.answer(i||"en"),l="magicfeedback-text";break;case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,C>0&&(c.maxLength=C),c.placeholder=E||n.placeholder.answer(i||"en"),l="magicfeedback-longtext";break;case a.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?s(p,i):n.placeholder.number(i||"en"),l="magicfeedback-number",g.length&&(g.sort(((e,t)=>Number(e)-Number(t))),c.max=g[g.length-1],c.min=g[0],c.value=g[0]);break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),l="magicfeedback-"+("MULTIPLECHOICE"===m?"checkbox":"radio"),(null==b?void 0:b.extraOption)&&g.push(null==b?void 0:b.extraOptionText),g.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===m?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${h}-${t}`,r.type="MULTIPLECHOICE"===m?"checkbox":"radio",r.name=h,r.value=e,r.classList.add(l),r.classList.add("magicfeedback-input"),m===a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==b?void 0:b.maxOptions)&&(null==b?void 0:b.maxOptions)>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${h}"]:checked`).length>(null==b?void 0:b.maxOptions)&&(r.checked=!1)})),e!==v&&e!==k||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${h}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${h}`);i&&(null==b?void 0:b.extraOption)&&(t.target.checked&&e===(null==b?void 0:b.extraOptionText)?i.style.display="block":i.style.display="none")})),s.appendChild(r),s.appendChild(o),c.appendChild(s),(null==b?void 0:b.extraOption)&&e===(null==b?void 0:b.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==b?void 0:b.extraOptionPlaceholder)||n.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${h}`,e.name=`extra-option-${h}`,e.style.display="none",c.appendChild(e)}}));break;case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),l="magicfeedback-radio";const L=document.createElement("div");L.classList.add("magicfeedback-boolean-container"),L.style.display="flex",L.style.flexDirection="row",L.style.justifyContent="space-between",L.style.width="70%",L.style.margin="auto",((null==b?void 0:b.addIcon)?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];case"bn":return["হ্যাঁ","না"];default:return["Yes","No"]}}(i)).forEach(((e,t)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${h}-${t}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const a=document.createElement("label");a.htmlFor=`rating-${h}-${t}`,a.textContent=e,a.style.margin="0",a.style.padding="0";const n=document.createElement("input");n.id=`rating-${h}-${t}`,n.type="radio",n.name=h,n.value=e,n.classList.add(l),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",n.addEventListener("change",(()=>{r&&r()})),i.appendChild(n),i.appendChild(a),L.appendChild(i)})),c.appendChild(L);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),l="magicfeedback-rating";const A=document.createElement("div");A.classList.add("magicfeedback-rating-container");const T=(null==b?void 0:b.max)?Number(null==b?void 0:b.max):5,S=(null==b?void 0:b.min)?Number(null==b?void 0:b.min):1,O=o(S,T,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder,null==b?void 0:b.extraOption);for(let ne=S;ne<=T;ne++){const se=document.createElement("div");se.classList.add("magicfeedback-rating-option");const oe=document.createElement("label");oe.htmlFor=`rating-${h}-${ne}`,oe.classList.add("magicfeedback-rating-option-label-container");const re=document.createElement("label");re.htmlFor=`rating-${h}-${ne}`,re.textContent=ne.toString();const de=document.createElement("img");if(de.alt=`face-${h}-${ne}`,de.className=`rating-image${ne}`,0===S&&10===T)de.src=`https://magicfeedback-c6458-dev.web.app/assets/${ne}.svg`;else if(1===S&&5===T)switch(ne){case 1:de.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:de.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:de.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:de.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:de.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const le=Math.round(10/(T-S)*(ne-S));de.src=`https://magicfeedback-c6458-dev.web.app/assets/${le}.svg`}const ce=document.createElement("input");ce.id=`rating-${h}-${ne}`,ce.type="radio",ce.name=h,ce.value=ne.toString(),ce.classList.add(l),ce.classList.add("magicfeedback-input"),oe.appendChild(ce),oe.appendChild(de),oe.appendChild(re),se.appendChild(oe),A.appendChild(se)}if((null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const ue=document.createElement("div");ue.classList.add("magicfeedback-rating-option");const pe=document.createElement("label");pe.htmlFor=`rating-${h}-extra`,pe.classList.add("magicfeedback-rating-option-label-container");const me=document.createElement("label");me.htmlFor=`rating-${h}-extra`,me.textContent=null==b?void 0:b.extraOptionText;const he=document.createElement("img");he.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",he.alt=`face-${h}-extra`,he.className="magicfeedback-rating-image-extra";const fe=document.createElement("input");fe.id=`rating-${h}-extra`,fe.type="radio",fe.name=h,fe.value="-",fe.classList.add(l),fe.classList.add("magicfeedback-input"),pe.appendChild(fe),pe.appendChild(he),pe.appendChild(me),ue.appendChild(pe),A.appendChild(ue)}c.appendChild(O),c.appendChild(A);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),l="magicfeedback-rating-number";const N=document.createElement("div");N.classList.add("magicfeedback-rating-number-container");const P=(null==b?void 0:b.max)?Number(null==b?void 0:b.max):5,I=(null==b?void 0:b.min)?Number(null==b?void 0:b.min):1,D=o(I,P,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder,null==b?void 0:b.extraOption);for(let ge=I;ge<=P;ge++){const ve=document.createElement("div");ve.classList.add("magicfeedback-rating-number-option");const be=document.createElement("label");be.htmlFor=`rating-${h}-${ge}`,be.classList.add("magicfeedback-rating-number-option-label-container");const ye=document.createElement("label");ye.htmlFor=`rating-${h}-${ge}`,ye.textContent=ge.toString();const Ee=document.createElement("input");Ee.id=`rating-${h}-${ge}`,Ee.type="radio",Ee.name=h,Ee.value=ge.toString(),Ee.classList.add(l),Ee.classList.add("magicfeedback-input"),be.appendChild(Ee),be.appendChild(ye),ve.appendChild(be),N.appendChild(ve)}if((null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const ke=document.createElement("div");ke.classList.add("magicfeedback-rating-number-option");const Ce=document.createElement("label");Ce.htmlFor=`rating-${h}-extra`,Ce.classList.add("magicfeedback-rating-number-option-label-container");const xe=document.createElement("label");xe.htmlFor=`rating-${h}-extra`,xe.textContent=null==b?void 0:b.extraOptionText;const we=document.createElement("input");we.id=`rating-${h}-extra`,we.type="radio",we.name=h,we.value="-",we.classList.add(l),we.classList.add("magicfeedback-input"),Ce.appendChild(we),Ce.appendChild(xe),ke.appendChild(Ce),N.appendChild(ke)}c.appendChild(D),c.appendChild(N);break;case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),l="magicfeedback-rating-star";const $=function(e,t,i){const a="magicfeedback-rating-star-selected",n=document.createElement("div");n.classList.add("magicfeedback-rating-star-container"),n.style.maxWidth="300px",n.style.margin="auto";for(let t=1;t<=5;t++){const i=document.createElement("label");i.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${t}`,s.type="radio",s.name=e,s.value=t.toString(),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.classList.add("magicfeedback-input"),s.addEventListener("change",(()=>{const e=n.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(s.value)?e[t].classList.contains(a)||e[t].classList.add(a):e[t].classList.contains(a)&&e[t].classList.remove(a)})),i.appendChild(s);const o=document.createElement("label");o.htmlFor=`rating-${e}-${t}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",i.appendChild(o),n.appendChild(i)}return n.appendChild(o(1,5,t,i,!1,!1)),n}(h,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder);c.appendChild($);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),l="magicfeedback-multiple-choice-image";const M=document.createElement("div");M.classList.add("magicfeedback-multiple-choice-image-container"),M.style.display="flex",M.style.flexDirection="row",M.style.flexWrap="wrap",M.style.justifyContent="center";const F=g.length;let R=1,_=1;switch(F){case 1:case 2:case 3:R=F,_=1;break;case 4:case 5:case 6:_=2,R=Math.ceil(F/_);break;case 7:case 8:case 9:_=3,R=Math.ceil(F/_);break;default:_=4,R=Math.ceil(F/_)}const q=void 0!==(null==b?void 0:b.addTitle)&&(null==b?void 0:b.addTitle),B=void 0!==(null==b?void 0:b.multiOption)&&(null==b?void 0:b.multiOption),U=void 0!==(null==b?void 0:b.randomPosition)&&(null==b?void 0:b.randomPosition),j=void 0!==(null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOption);function Q(e){try{const{position:t,url:i,value:a}=e,n=document.createElement("label");n.classList.add("magicfeedback-multiple-choice-image-option"),n.style.width=`calc( ${100/R}% - 10px)`,n.style.height=`calc( ${100/_}% - 10px)`,n.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${h}-${t}`,s.classList.add("magicfeedback-image-option-label-container"),s.style.display="flex",s.style.flexDirection="column",s.addEventListener("mouseover",(()=>{s.style.border="2px solid #000"})),s.addEventListener("mouseout",(()=>{s.style.border="none"})),s.addEventListener("click",(()=>{s.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=a,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${h}-${t}`,r.type=B?"checkbox":"radio",r.name=h,r.value=a,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.backgroundPosition="center",d.style.width="100%",d.style.height="100%",d.style.objectFit="cover",d.style.margin="auto",s.appendChild(r),s.appendChild(d),q&&s.appendChild(o),n.appendChild(s),M.appendChild(n)}catch(e){console.error(e)}}U&&(g=g.sort((()=>Math.random()-.5))),g.forEach((e=>Q(JSON.parse(e)))),j&&(null==b?void 0:b.extraOptionValue)&&(null==b?void 0:b.extraOptionValue.length)>0&&Q(null==b?void 0:b.extraOptionValue[0]),c.appendChild(M);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),l="magicfeedback-select";const G=document.createElement("option");G.value="",G.text="slim"===t?s(p,i):v||"Select an option",G.disabled=!0,G.selected=!0,c.appendChild(G),g.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)}));break;case a.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=f,c.placeholder=E||n.placeholder.date(i||"en"),l="magicfeedback-date";break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),l="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${u}`,c.name=h,c.value="true",c.required=f,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input");break;case a.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=f,c.placeholder=E||"you@example.com",l="magicfeedback-email";break;case a.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=f,c.placeholder=E||n.placeholder.password(i||"en"),l="magicfeedback-password";break;case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),l="magicfeedback-multi-question-matrix";const K=document.createElement("div");K.classList.add("magicfeedback-multi-question-matrix-container");const W=document.createElement("table");W.classList.add("magicfeedback-multi-question-matrix-table");const Y=document.createElement("thead");Y.classList.add("magicfeedback-multi-question-matrix-header"),Y.style.paddingBottom="15px";const H=document.createElement("tr");["",...g].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",H.appendChild(t)})),Y.appendChild(H);const V=document.createElement("tbody");(null===(d=null==b?void 0:b.options)||void 0===d?void 0:d.length)>0&&(null==b||b.options.split("|").forEach((e=>{const t=document.createElement("tr");t.style.paddingBottom="15px";const i=document.createElement("td");i.classList.add("magicfeedback-multi-question-matrix-row-label");const a=document.createElement("label");a.classList.add("magicfeedback-multi-question-matrix-label"),a.style.paddingRight="15px",a.textContent=e,i.appendChild(a),t.appendChild(i),g.forEach((i=>{const a=document.createElement("td"),n=document.createElement("input");n.type="radio",n.name=`${h}-${e}`,n.value=i,n.id=`matrix-${e}`,n.classList.add("magicfeedback-input"),n.style.padding="0 10px",a.appendChild(n),t.appendChild(a)})),V.appendChild(t)}))),W.appendChild(Y),W.appendChild(V),K.appendChild(W),c.appendChild(K);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),l="magicfeedback-priority-list";const J=document.createElement("div");J.classList.add("magicfeedback-priority-list-container");const z=document.createElement("ul");z.classList.add("magicfeedback-priority-list-list"),g.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-priority-list-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const a=document.createElement("input");a.classList.add("magicfeedback-input-magicfeedback-priority-list"),a.classList.add("magicfeedback-input"),a.type="hidden",a.id=`priority-list-${h}`,a.name=h,a.value=`${t+1}. ${e}`,i.appendChild(a);const n=document.createElement("label");n.classList.add("magicfeedback-priority-list-item-label"),n.textContent=`${t+1}. ${e}`,i.appendChild(n);const s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between";const o=document.createElement("img");o.classList.add("magicfeedback-priority-list-arrow-up"),o.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",o.style.width="20px",o.style.height="20px",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.visibility=0===t?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const d=i.previousElementSibling;if(d){const c=Number(a.value.split(".")[0])-1;a.value=`${c}. ${e}`,n.textContent=`${c}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===g.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),m=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&m){const e=Number(l.value.split(".")[0])+1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===g.length?"hidden":"visible"}z.insertBefore(i,d)}})),s.appendChild(o);const r=document.createElement("img");r.classList.add("magicfeedback-priority-list-arrow-down"),r.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",r.style.width="20px",r.style.height="20px",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(180deg)",r.style.visibility=t===g.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,s;const d=i.nextElementSibling;if(d){const c=Number(a.value.split(".")[0])+1;a.value=c.toString(),n.textContent=`${c.toString()}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===g.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),m=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&m){const e=Number(l.value.split(".")[0])-1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===g.length?"hidden":"visible"}z.insertBefore(d,i)}})),s.appendChild(r),i.appendChild(s),z.appendChild(i)})),J.appendChild(z),c.appendChild(J);break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),l="magicfeedback-point-system";const X=document.createElement("div");X.classList.add("magicfeedback-point-system-container");const Z=document.createElement("ul");Z.classList.add("magicfeedback-point-system-list"),Z.style.padding="0";const ee=100,te=ee/g.length,ie=document.createElement("div");ie.classList.add("magicfeedback-error"),ie.textContent=n.placeholder.pointsystemerror(i||"en"),ie.style.color="#C70039",ie.style.fontSize="14px",ie.style.textAlign="right",ie.style.width="100%",ie.style.display="none";const ae=document.createElement("div");ae.classList.add("magicfeedback-point-system-total"),ae.textContent="0 / 100 %",ae.style.textAlign="right",ae.style.fontSize="15px",ae.style.marginTop="5px",g.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-point-system-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const a=document.createElement("label");a.textContent=e,a.style.fontSize="15px",i.appendChild(a);const n=document.createElement("span");n.classList.add("magicfeedback-point-system-input-container");const s=document.createElement("input");s.name=h,s.id=`point-system-${e}`,s.type="number",s.min="0",s.max=`${ee}`,s.value="0",s.classList.add("magicfeedback-input"),s.style.width="40px",s.style.border="0",s.style.textAlign="center",s.style.margin="0 5px",s.autofocus=0===t;const o=document.createElement("span");o.textContent="%",o.style.color="#000",s.addEventListener("input",(()=>{const e=Z.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ee&&(s.value=`${te}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(ae.style.color="orange",i.setAttribute("disabled","true")):(ie.style.display="none",ae.style.color="green",i.removeAttribute("disabled"))),ae.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=Z.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(ie.style.display="block")})))})),n.appendChild(s),n.appendChild(o),i.appendChild(n),Z.appendChild(i)})),X.appendChild(Z),X.appendChild(ae),X.appendChild(ie),c.appendChild(X);break;default:return y}c.id=`magicfeedback-${u}`,c.setAttribute("name",h),c.classList.add(l),(void 0!==v||null!==k)&&(c.value=k||v),["RADIO","MULTIPLECHOICE"].includes(m)||(c.classList.add("magicfeedback-input"),c.required=f);const w=document.createElement("label");if(w.setAttribute("for",`magicfeedback-${u}`),w.textContent=s(p,i),w.classList.add("magicfeedback-label"),["CONSENT"].includes(m))y.classList.add("magicfeedback-consent-container"),y.appendChild(c),y.appendChild(w);else{if("slim"!==t&&(y.appendChild(w),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const Le=document.createElement("img");Le.src=null==b?void 0:b.general,Le.classList.add("magicfeedback-image"),Le.style.maxWidth="auto",Le.style.height="400px",Le.style.margin="10px 0",y.appendChild(Le)}if("LONGTEXT"===m&&C>0){const Ae=document.createElement("div");if(Ae.classList.add("magicfeedback-counter"),Ae.textContent=`${c.value.length}/${C}`,Ae.style.textAlign="right",Ae.style.fontSize="15px",Ae.style.marginTop="5px",c.addEventListener("input",(()=>{Ae.textContent=`${c.value.length}/${C}`})),y.appendChild(c),y.appendChild(Ae),(null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const Te=document.createElement("div");Te.classList.add("magicfeedback-skip-container"),Te.classList.add("magicfeedback-checkbox-container"),Te.style.display="flex",Te.style.justifyContent="flex-start";const Se=document.createElement("input");Se.classList.add("magicfeedback-skip"),Se.type="checkbox",Se.id=`skip-${h}`,Se.name=h,Se.value="-",Se.style.cursor="pointer";const Oe=document.createElement("label");Oe.htmlFor=`skip-${h}`,Oe.textContent=null==b?void 0:b.extraOptionText,Oe.style.fontSize="15px",Oe.style.cursor="pointer",Oe.style.margin="0 5px",Se.addEventListener("click",(()=>{c.value="-",r&&r()})),Te.appendChild(Se),Te.appendChild(Oe),y.appendChild(Te)}}else y.appendChild(c)}return y}(t,i,r,d);c.push(e)}})),c},t.renderActions=function(e="",t,i="Submit",a="Back",n="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?n||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=a||"Back",r.addEventListener("click",t),r.addEventListener("click",(()=>{o.removeAttribute("disabled")})),"MAGICSURVEY"===e&&s.appendChild(r),s.appendChild(o),s},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,i=!1,a="Go!"){const n=document.createElement("div");n.classList.add("magicfeedback-start-message-container");const s=document.createElement("div");s.classList.add("magicfeedback-start-message"),s.innerHTML=e;const o=document.createElement("button");return o.id="magicfeedback-start-message-button",o.classList.add("magicfeedback-start-message-button"),o.textContent=a,o.addEventListener("click",(()=>t())),n.appendChild(s),i&&n.appendChild(o),n}},341:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function o(e){try{d(a.next(e))}catch(e){s(e)}}function r(e){try{d(a.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const s=n(i(31)),o=n(i(147)),r=i(374),d={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,n){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:d});if(a.ok){const e=yield a.json();return n.log(`Received form for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),null}}))},t.getQuestions=function(e,t,i,n){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:d});if(a.ok){const e=yield a.json();return n.log(`Received questions for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(a.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield a.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(a.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield a.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.8","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},i=function i(a){var n=t[a];if(void 0!==n)return n.exports;var s=t[a]={exports:{}};return e[a].call(s.exports,s,s.exports,i),s.exports}(607);return i.default})()));
@@ -4,4 +4,5 @@ export declare const placeholder: {
4
4
  email: (language: string) => "এখানে আপনার" | "Write your email here..." | "Escribe tu correo electrónico aquí..." | "Skriv din e-mail her..." | "Kirjoita sähköpostiosoitteesi tähän..." | "Skriv din e-post här..." | "Skriv e-posten din her..." | "اكتب بريدك الإلكتروني هنا...";
5
5
  date: (language: string) => "এখানে আপনার" | "Write your date here..." | "Escribe tu fecha aquí..." | "Skriv din dato her..." | "Kirjoita päivämääräsi tähän..." | "Skriv ditt datum här..." | "Skriv datoen din her..." | "اكتب تاريخك هنا...";
6
6
  password: (language: string) => "এখানে আপনার" | "Write your password here..." | "Escribe tu contraseña aquí..." | "Skriv dit kodeord her..." | "Kirjoita salasanasi tähän..." | "Skriv ditt lösenord här..." | "Skriv passordet ditt her..." | "اكتب كلمة المرور الخاصة بك هنا...";
7
+ pointsystemerror: (language: string) => "The total points must be 100 %" | "El total de puntos debe ser 100 %" | "Samlet antal point skal være 100 %" | "Kokonaispisteiden on oltava 100 %" | "Totala poäng måste vara 100 %" | "Totalt antall poeng må være 100 %" | "يجب أن تكون النقاط الإجمالية 100 %" | "মোট পয়েন্ট 100 % হতে হবে";
7
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicfeedback/native",
3
- "version": "1.2.8-beta.9",
3
+ "version": "1.2.8",
4
4
  "main": "./dist/magicfeedback-sdk.node.js",
5
5
  "browser": "./dist/magicfeedback-sdk.browser.js",
6
6
  "types": "./dist/types/src/index.d.ts",