@magicfeedback/native 1.2.8-beta.1 → 1.2.8-beta.3

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]"],c=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(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)||c(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=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[d(e)]},p.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},p.prototype.set=function(e,t){this.map[d(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 C=[301,302,303,307,308];k.redirect=function(e,t){if(-1===C.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 x(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 c(){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",c),o.onreadystatechange=function(){4===o.readyState&&r.signal.removeEventListener("abort",c)}),o.send(void 0===r._bodyInit?null:r._bodyInit)}))}x.polyfill=!0,e.fetch||(e.fetch=x,e.Headers=p,e.Request=v,e.Response=k),t.Headers=p,t.Request=v,t.Response=k,t.fetch=x,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{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((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),c=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)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,r=!0,c,d){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:d,completed:r,id:c,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)}}}},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{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((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);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.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.censorQuestions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){var i;return n(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const n=localStorage.getItem(`magicfeedback-${this.appId}`);if(n&&new Date(JSON.parse(n).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(n),(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,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),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.generateForm())}))):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))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}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;try{this.questions.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");if(s.classList.add("magicfeedback-questions"),s.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,r.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,s.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>s.appendChild(e))),a.appendChild(s),n.appendChild(a),this.formOptionsConfig.addButton){const e=(0,r.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()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}startForm(){this.generateForm()}generateWelcomeMessage(e){try{const t=this.generateContainer(),i=(0,r.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i)}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){var a;return n(this,void 0,void 0,(function*(){const n=document.getElementById("magicfeedback-container-"+this.appId),s=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,answer:this.feedback.answers,progress:this.progress,total:this.total}));const r=yield this.pushAnswers("MAGICSURVEY"!==(null===(a=this.formData)||void 0===a?void 0:a.identity));r&&(this.id=r,yield this.processNextQuestion(n,s)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:r,loading:!1,progress:this.progress,total:this.total,answer:this.feedback.answers,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+this.censorQuestions.length,total:this.total-this.censorQuestions.length,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:[]},c="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(c);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(""!==c){if("email"===a){if(!(0,s.validateEmail)(c)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[c]})}if(e.id.includes("point-system")){const t=e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${c}%`)}else o.value.push(c);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)}censureQuestions(e){this.censorQuestions=this.questions.filter((t=>e.includes(t.id))).map((e=>e.id))}pushAnswers(e=!1){var t,i;return n(this,void 0,void 0,(function*(){try{if("MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const n=this.config.get("url"),a={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(n,this.id?Object.assign(Object.assign({},a),{sessionId:this.id}):a,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){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 t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,s.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,a,s,o;return n(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(a=this.questionInProcess)||void 0===a?void 0:a.followup){const e=yield this.callFollowUpQuestion(this.questionInProcess);if(e){this.questionInProcess=e;const i=(0,r.renderQuestions)([e],null===(s=this.formOptionsConfig)||void 0===s?void 0:s.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object:e,element:i}),t.removeChild(t.childNodes[0]),t.appendChild(i)}else this.renderNextQuestion(t)}else this.renderNextQuestion(t);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){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)}}))}renderNextQuestion(e){this.progress++,this.progress<this.total?(this.questionInProcess=this.history[this.progress][0].object,this.censorQuestions.includes(this.questionInProcess.id)?this.renderNextQuestion(e):(e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element))):this.finish()}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e&&e.childNodes.length>0&&e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;let t=this.history[this.progress][this.history[this.progress].length-1];this.censorQuestions.includes(t.object.id)?this.back():(this.questionInProcess=t.object,e.appendChild(t.element))}}},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}t.renderQuestions=function e(t,i="standard",r="en",o){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var d,l;if((null===(l=null===(d=null==t?void 0:t.questionType)||void 0===d?void 0:d.conf)||void 0===l?void 0:l.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,o).forEach((e=>{n.appendChild(e)})),c.push(n)}else{const e=function(e,t,i,r){var o;let c,d,{id:l,title:u,type:p,ref:h,require:m,value:f,defaultValue:g,assets:b}=e,y=document.createElement("div");y.classList.add("magicfeedback-div");const v="slim"===t?s(u,i):null==b?void 0:b.placeholder,E=(C=l,new URLSearchParams(window.location.search).get(C)),k=b.maxCharacters||300;var C;switch(p){case n.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=v||a.placeholder.answer(i||"en"),d="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,k>0&&(c.maxLength=k),c.placeholder=v||a.placeholder.answer(i||"en"),d="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?s(u,i):a.placeholder.number(i||"en"),d="magicfeedback-number",f.length&&(f.sort(((e,t)=>Number(e)-Number(t))),c.max=f[f.length-1],c.min=f[0],c.value=f[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),d="magicfeedback-"+("MULTIPLECHOICE"===p?"checkbox":"radio"),b.extraOption&&f.push(b.extraOptionText),f.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===p?"checkbox":"radio"}-container`);const r=document.createElement("label"),o=document.createElement("input");if(o.id=`rating-${h}-${t}`,o.type="MULTIPLECHOICE"===p?"checkbox":"radio",o.name=h,o.value=e,o.classList.add(d),o.classList.add("magicfeedback-input"),p===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&b.maxOptions&&b.maxOptions>0&&o.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${h}"]:checked`).length>b.maxOptions&&(o.checked=!1)})),e!==g&&e!==E||(o.checked=!0),r.textContent=e,r.htmlFor=`rating-${h}-${t}`,o.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${h}`);i&&b.extraOption&&(t.target.checked&&e===b.extraOptionText?i.style.display="block":i.style.display="none")})),s.appendChild(o),s.appendChild(r),c.appendChild(s),b.extraOption&&e===b.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder=b.extraOptionPlaceholder||a.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 n.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),d="magicfeedback-radio";const w=document.createElement("div");w.classList.add("magicfeedback-boolean-container"),w.style.display="flex",w.style.flexDirection="row",w.style.justifyContent="space-between",w.style.width="70%",w.style.margin="auto",(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 n=document.createElement("label");n.htmlFor=`rating-${h}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${h}-${t}`,a.type="radio",a.name=h,a.value=e,a.classList.add(d),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),w.appendChild(i)})),c.appendChild(w);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),d="magicfeedback-rating";const A=document.createElement("div");A.classList.add("magicfeedback-rating-container");const L=b.max?Number(b.max):5,S=b.min?Number(b.min):1,T=document.createElement("div");if(T.classList.add("magicfeedback-rating-placeholder"),T.style.display="flex",T.style.justifyContent="space-between",T.style.width="90%",T.style.margin="auto",b.minPlaceholder){const ie=document.createElement("span");ie.textContent=b.minPlaceholder,ie.classList.add("magicfeedback-rating-placeholder-min"),ie.style.fontStyle="italic",ie.style.fontSize="0.8em",T.appendChild(ie)}if(b.maxPlaceholder){const ne=document.createElement("span");ne.textContent=b.maxPlaceholder,ne.classList.add("magicfeedback-rating-placeholder-max"),ne.style.fontStyle="italic",ne.style.fontSize="0.8em",T.appendChild(ne)}for(let ae=S;ae<=L;ae++){const se=document.createElement("div");se.classList.add("magicfeedback-rating-option");const re=document.createElement("label");re.htmlFor=`rating-${h}-${ae}`,re.classList.add("magicfeedback-rating-option-label-container");const oe=document.createElement("label");oe.htmlFor=`rating-${h}-${ae}`,oe.textContent=ae.toString();const ce=document.createElement("img");if(ce.alt=`face-${h}-${ae}`,ce.className=`rating-image${ae}`,0===S&&10===L)ce.src=`https://magicfeedback-c6458-dev.web.app/assets/${ae}.svg`;else if(1===S&&5===L)switch(ae){case 1:ce.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:ce.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:ce.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:ce.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:ce.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const le=Math.round(10/(L-S)*(ae-S));ce.src=`https://magicfeedback-c6458-dev.web.app/assets/${le}.svg`}const de=document.createElement("input");de.id=`rating-${h}-${ae}`,de.type="radio",de.name=h,de.value=ae.toString(),de.classList.add(d),de.classList.add("magicfeedback-input"),re.appendChild(de),re.appendChild(ce),re.appendChild(oe),se.appendChild(re),A.appendChild(se)}if(b.extraOption&&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 he=document.createElement("label");he.htmlFor=`rating-${h}-extra`,he.textContent=b.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 fe=document.createElement("input");fe.id=`rating-${h}-extra`,fe.type="radio",fe.name=h,fe.value="-",fe.classList.add(d),fe.classList.add("magicfeedback-input"),pe.appendChild(fe),pe.appendChild(me),pe.appendChild(he),ue.appendChild(pe),A.appendChild(ue)}c.appendChild(T),c.appendChild(A);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),d="magicfeedback-rating-number";const O=document.createElement("div");O.classList.add("magicfeedback-rating-number-container");const P=b.max?Number(b.max):5,I=b.min?Number(b.min):1,N=document.createElement("div");if(N.classList.add("magicfeedback-rating-number-placeholder"),N.style.display="flex",N.style.justifyContent="space-between",N.style.width="90%",N.style.margin="auto",b.minPlaceholder){const ge=document.createElement("span");ge.textContent=b.minPlaceholder,ge.classList.add("magicfeedback-rating-number-placeholder-min"),ge.style.fontStyle="italic",ge.style.fontSize="0.8em",N.appendChild(ge)}if(b.maxPlaceholder){const be=document.createElement("span");be.textContent=b.maxPlaceholder,be.classList.add("magicfeedback-rating-number-placeholder-max"),be.style.fontStyle="italic",be.style.fontSize="0.8em",N.appendChild(be)}for(let ye=I;ye<=P;ye++){const ve=document.createElement("div");ve.classList.add("magicfeedback-rating-number-option");const Ee=document.createElement("label");Ee.htmlFor=`rating-${h}-${ye}`,Ee.classList.add("magicfeedback-rating-number-option-label-container");const ke=document.createElement("label");ke.htmlFor=`rating-${h}-${ye}`,ke.textContent=ye.toString();const Ce=document.createElement("input");Ce.id=`rating-${h}-${ye}`,Ce.type="radio",Ce.name=h,Ce.value=ye.toString(),Ce.classList.add(d),Ce.classList.add("magicfeedback-input"),Ee.appendChild(Ce),Ee.appendChild(ke),ve.appendChild(Ee),O.appendChild(ve)}if(b.extraOption&&b.extraOptionText){const xe=document.createElement("div");xe.classList.add("magicfeedback-rating-number-option");const we=document.createElement("label");we.htmlFor=`rating-${h}-extra`,we.classList.add("magicfeedback-rating-number-option-label-container");const Ae=document.createElement("label");Ae.htmlFor=`rating-${h}-extra`,Ae.textContent=b.extraOptionText;const Le=document.createElement("input");Le.id=`rating-${h}-extra`,Le.type="radio",Le.name=h,Le.value="-",Le.classList.add(d),Le.classList.add("magicfeedback-input"),we.appendChild(Le),we.appendChild(Ae),xe.appendChild(we),O.appendChild(xe)}c.appendChild(N),c.appendChild(O);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),d="magicfeedback-rating-star";const _=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let n=1;n<=5;n++){const a=document.createElement("label");a.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${n}`,s.type="radio",s.name=e,s.value=n.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=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(s.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),a.appendChild(s);const r=document.createElement("label");r.htmlFor=`rating-${e}-${n}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",a.appendChild(r),i.appendChild(a)}return i}(h);c.appendChild(_);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),d="magicfeedback-multiple-choice-image";const $=document.createElement("div");$.classList.add("magicfeedback-multiple-choice-image-container"),$.style.display="flex",$.style.flexDirection="row",$.style.flexWrap="wrap",$.style.justifyContent="center";const D=f.length;let M=1,R=1;switch(D){case 1:case 2:case 3:M=D,R=1;break;case 4:case 5:case 6:R=2,M=Math.ceil(D/R);break;case 7:case 8:case 9:R=3,M=Math.ceil(D/R);break;default:R=4,M=Math.ceil(D/R)}const F=void 0!==(null==b?void 0:b.addTitle)&&b.addTitle,B=void 0!==(null==b?void 0:b.multiOption)&&b.multiOption,q=void 0!==(null==b?void 0:b.randomPosition)&&b.randomPosition,j=void 0!==(null==b?void 0:b.extraOption)&&b.extraOption;function U(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/R}% - 10px)`,a.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 r=document.createElement("label");r.textContent=n,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${h}-${t}`,o.type=B?"checkbox":"radio",o.name=h,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 c=document.createElement("img");c.classList.add("magicfeedback-multiple-choice-image-image"),c.src=i,c.style.cursor="pointer",c.style.backgroundSize="cover",c.style.backgroundPosition="center",c.style.width="100%",c.style.height="100%",c.style.objectFit="cover",c.style.margin="auto",s.appendChild(o),s.appendChild(c),F&&s.appendChild(r),a.appendChild(s),$.appendChild(a)}catch(e){console.error(e)}}q&&(f=f.sort((()=>Math.random()-.5))),f.forEach((e=>U(JSON.parse(e)))),j&&b.extraOptionValue&&b.extraOptionValue.length>0&&U(b.extraOptionValue[0]),c.appendChild($);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),d="magicfeedback-select";const K=document.createElement("option");K.value="",K.text="slim"===t?s(u,i):g||"Select an option",K.disabled=!0,K.selected=!0,c.appendChild(K),f.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=m,c.placeholder=v||a.placeholder.date(i||"en"),d="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),d="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${l}`,c.name=h,c.value="true",c.required=m,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input");break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=m,c.placeholder=v||"you@example.com",d="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=m,c.placeholder=v||a.placeholder.password(i||"en"),d="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),d="magicfeedback-multi-question-matrix";const Q=document.createElement("div");Q.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 G=document.createElement("tr");["",...f].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",G.appendChild(t)})),Y.appendChild(G);const H=document.createElement("tbody");(null===(o=null==b?void 0:b.options)||void 0===o?void 0:o.length)>0&&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 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),f.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="checkbox",a.name=h,a.value=i,a.id=`matrix-${e}`,a.classList.add("magicfeedback-input"),a.style.padding="0 10px",n.appendChild(a),t.appendChild(n)})),H.appendChild(t)})),W.appendChild(Y),W.appendChild(H),Q.appendChild(W),c.appendChild(Q);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),d="magicfeedback-priority-list";const V=document.createElement("div");V.classList.add("magicfeedback-priority-list-container");const J=document.createElement("ul");J.classList.add("magicfeedback-priority-list-list"),f.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-${h}`,n.name=h,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 c=i.previousElementSibling;if(c){const d=Number(n.value.split(".")[0])-1;n.value=`${d}. ${e}`,a.textContent=`${d}. ${e}`,r.style.visibility=1===d?"hidden":"visible",o.style.visibility=d===f.length?"hidden":"visible";const l=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=c.querySelector(".magicfeedback-priority-list-item-label"),p=c.querySelector(".magicfeedback-priority-list-arrow-up"),h=c.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===f.length?"hidden":"visible"}J.insertBefore(i,c)}})),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===f.length-1?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const c=i.nextElementSibling;if(c){const d=Number(n.value.split(".")[0])+1;n.value=d.toString(),a.textContent=`${d.toString()}. ${e}`,r.style.visibility=1===d?"hidden":"visible",o.style.visibility=d===f.length?"hidden":"visible";const l=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=c.querySelector(".magicfeedback-priority-list-item-label"),p=c.querySelector(".magicfeedback-priority-list-arrow-up"),h=c.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===f.length?"hidden":"visible"}J.insertBefore(c,i)}})),s.appendChild(o),i.appendChild(s),J.appendChild(i)})),V.appendChild(J),c.appendChild(V);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),d="magicfeedback-point-system";const z=document.createElement("div");z.classList.add("magicfeedback-point-system-container");const X=document.createElement("ul");X.classList.add("magicfeedback-point-system-list"),X.style.padding="0";const Z=100,ee=Z/f.length,te=document.createElement("div");te.classList.add("magicfeedback-point-system-total"),te.textContent="0 / 100 %",te.style.textAlign="right",te.style.fontSize="0.8em",te.style.color="#999",te.style.marginTop="5px",f.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=h,a.id=`point-system-${e}`,a.type="number",a.min="0",a.max=`${Z}`,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=X.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>Z&&(a.value=`${ee}%`,t-=Number(a.value)),te.textContent=`${t} / 100 %`})),n.appendChild(a),n.appendChild(s),t.appendChild(n),X.appendChild(t)})),z.appendChild(X),z.appendChild(te),c.appendChild(z);break;default:return y}c.id=`magicfeedback-${l}`,c.setAttribute("name",h),c.classList.add(d),(void 0!==g||null!==E)&&(c.value=E||g),["RADIO","MULTIPLECHOICE"].includes(p)||(c.classList.add("magicfeedback-input"),c.required=m);const x=document.createElement("label");if(x.setAttribute("for",`magicfeedback-${l}`),x.textContent=s(u,i),x.classList.add("magicfeedback-label"),["CONSENT"].includes(p))y.classList.add("magicfeedback-consent-container"),y.appendChild(c),y.appendChild(x);else{if("slim"!==t&&(y.appendChild(x),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const Se=document.createElement("img");Se.src=b.general,Se.classList.add("magicfeedback-image"),Se.style.maxWidth="auto",Se.style.height="400px",Se.style.margin="10px 0",y.appendChild(Se)}if("LONGTEXT"===p&&k>0){const Te=document.createElement("div");if(Te.classList.add("magicfeedback-counter"),Te.textContent=`${c.value.length}/${k}`,Te.style.textAlign="right",Te.style.fontSize="0.8em",Te.style.color="#999",Te.style.marginTop="5px",c.addEventListener("input",(()=>{Te.textContent=`${c.value.length}/${k}`})),y.appendChild(c),y.appendChild(Te),b.extraOption&&b.extraOptionText){const Oe=document.createElement("div");Oe.classList.add("magicfeedback-skip-container"),Oe.classList.add("magicfeedback-checkbox-container"),Oe.style.display="flex",Oe.style.justifyContent="flex-start";const Pe=document.createElement("input");Pe.classList.add("magicfeedback-skip"),Pe.type="checkbox",Pe.id=`skip-${h}`,Pe.name=h,Pe.value="-",Pe.style.cursor="pointer";const Ie=document.createElement("label");Ie.htmlFor=`skip-${h}`,Ie.textContent=b.extraOptionText,Ie.style.fontSize="0.8em",Ie.style.color="#999",Ie.style.cursor="pointer",Ie.style.margin="0 5px",Pe.addEventListener("click",(()=>{c.value="-",r&&r()})),Oe.appendChild(Pe),Oe.appendChild(Ie),y.appendChild(Oe)}}else y.appendChild(c)}return y}(t,i,r,o);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{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((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),c={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:c});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:c});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"},c),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"},c),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.1","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,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]"],c=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(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)||c(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=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[d(e)]},p.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},p.prototype.set=function(e,t){this.map[d(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 C=[301,302,303,307,308];k.redirect=function(e,t){if(-1===C.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 x(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 c(){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",c),o.onreadystatechange=function(){4===o.readyState&&r.signal.removeEventListener("abort",c)}),o.send(void 0===r._bodyInit?null:r._bodyInit)}))}x.polyfill=!0,e.fetch||(e.fetch=x,e.Headers=p,e.Request=v,e.Response=k),t.Headers=p,t.Request=v,t.Response=k,t.fetch=x,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{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((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),c=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)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,r=!0,c,d){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:d,completed:r,id:c,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)}}}},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{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((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);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.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.censorQuestions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){var i;return n(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const n=localStorage.getItem(`magicfeedback-${this.appId}`);if(n&&new Date(JSON.parse(n).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(n),(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,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),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.generateForm())}))):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))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}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;try{this.questions.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");if(s.classList.add("magicfeedback-questions"),s.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,r.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,s.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>s.appendChild(e))),a.appendChild(s),n.appendChild(a),this.formOptionsConfig.addButton){const e=(0,r.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()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}startForm(){this.generateForm()}generateWelcomeMessage(e){try{const t=this.generateContainer(),i=(0,r.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i)}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){var a;return n(this,void 0,void 0,(function*(){const n=document.getElementById("magicfeedback-container-"+this.appId),s=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,answer:this.feedback.answers,progress:this.progress,total:this.total}));const r=yield this.pushAnswers("MAGICSURVEY"!==(null===(a=this.formData)||void 0===a?void 0:a.identity));r&&(this.id=r,yield this.processNextQuestion(n,s)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:r,loading:!1,progress:this.progress,total:this.total,answer:this.feedback.answers,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+this.censorQuestions.length,total:this.total-this.censorQuestions.length,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:[]},c="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(c);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(""!==c){if("email"===a){if(!(0,s.validateEmail)(c)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[c]})}if(e.id.includes("point-system")){const t=e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${c}%`)}else o.value.push(c);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)}censureQuestions(e){this.censorQuestions=this.questions.filter((t=>e.includes(t.id))).map((e=>e.id))}pushAnswers(e=!1){var t,i;return n(this,void 0,void 0,(function*(){try{if("MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const n=this.config.get("url"),a={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(n,this.id?Object.assign(Object.assign({},a),{sessionId:this.id}):a,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){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 t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,s.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,a,s,o;return n(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(a=this.questionInProcess)||void 0===a?void 0:a.followup){const e=yield this.callFollowUpQuestion(this.questionInProcess);if(e){this.questionInProcess=e;const i=(0,r.renderQuestions)([e],null===(s=this.formOptionsConfig)||void 0===s?void 0:s.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object:e,element:i}),t.removeChild(t.childNodes[0]),t.appendChild(i)}else this.renderNextQuestion(t)}else this.renderNextQuestion(t);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){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)}}))}renderNextQuestion(e){this.progress++,this.progress<this.total?(this.questionInProcess=this.history[this.progress][0].object,this.censorQuestions.includes(this.questionInProcess.id)?this.renderNextQuestion(e):(e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element))):this.finish()}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e&&e.childNodes.length>0&&e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;let t=this.history[this.progress][this.history[this.progress].length-1];this.censorQuestions.includes(t.object.id)?this.back():(this.questionInProcess=t.object,e.appendChild(t.element))}}},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}t.renderQuestions=function e(t,i="standard",r="en",o){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var d,l;if((null===(l=null===(d=null==t?void 0:t.questionType)||void 0===d?void 0:d.conf)||void 0===l?void 0:l.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,o).forEach((e=>{n.appendChild(e)})),c.push(n)}else{const e=function(e,t,i,r){var o;let c,d,{id:l,title:u,type:p,ref:h,require:m,value:f,defaultValue:g,assets:b}=e,y=document.createElement("div");y.classList.add("magicfeedback-div");const v="slim"===t?s(u,i):null==b?void 0:b.placeholder,E=(C=l,new URLSearchParams(window.location.search).get(C)),k=b.maxCharacters||300;var C;switch(p){case n.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=v||a.placeholder.answer(i||"en"),d="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,k>0&&(c.maxLength=k),c.placeholder=v||a.placeholder.answer(i||"en"),d="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?s(u,i):a.placeholder.number(i||"en"),d="magicfeedback-number",f.length&&(f.sort(((e,t)=>Number(e)-Number(t))),c.max=f[f.length-1],c.min=f[0],c.value=f[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),d="magicfeedback-"+("MULTIPLECHOICE"===p?"checkbox":"radio"),b.extraOption&&f.push(b.extraOptionText),f.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===p?"checkbox":"radio"}-container`);const r=document.createElement("label"),o=document.createElement("input");if(o.id=`rating-${h}-${t}`,o.type="MULTIPLECHOICE"===p?"checkbox":"radio",o.name=h,o.value=e,o.classList.add(d),o.classList.add("magicfeedback-input"),p===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&b.maxOptions&&b.maxOptions>0&&o.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${h}"]:checked`).length>b.maxOptions&&(o.checked=!1)})),e!==g&&e!==E||(o.checked=!0),r.textContent=e,r.htmlFor=`rating-${h}-${t}`,o.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${h}`);i&&b.extraOption&&(t.target.checked&&e===b.extraOptionText?i.style.display="block":i.style.display="none")})),s.appendChild(o),s.appendChild(r),c.appendChild(s),b.extraOption&&e===b.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder=b.extraOptionPlaceholder||a.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 n.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),d="magicfeedback-radio";const w=document.createElement("div");w.classList.add("magicfeedback-boolean-container"),w.style.display="flex",w.style.flexDirection="row",w.style.justifyContent="space-between",w.style.width="70%",w.style.margin="auto",(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 n=document.createElement("label");n.htmlFor=`rating-${h}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${h}-${t}`,a.type="radio",a.name=h,a.value=e,a.classList.add(d),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),w.appendChild(i)})),c.appendChild(w);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),d="magicfeedback-rating";const A=document.createElement("div");A.classList.add("magicfeedback-rating-container");const L=b.max?Number(b.max):5,S=b.min?Number(b.min):1,T=document.createElement("div");if(T.classList.add("magicfeedback-rating-placeholder"),T.style.display="flex",T.style.justifyContent="space-between",T.style.width="90%",T.style.margin="auto",b.minPlaceholder){const ie=document.createElement("span");ie.textContent=b.minPlaceholder,ie.classList.add("magicfeedback-rating-placeholder-min"),ie.style.fontStyle="italic",ie.style.fontSize="0.8em",T.appendChild(ie)}if(b.maxPlaceholder){const ne=document.createElement("span");ne.textContent=b.maxPlaceholder,ne.classList.add("magicfeedback-rating-placeholder-max"),ne.style.fontStyle="italic",ne.style.fontSize="0.8em",T.appendChild(ne)}for(let ae=S;ae<=L;ae++){const se=document.createElement("div");se.classList.add("magicfeedback-rating-option");const re=document.createElement("label");re.htmlFor=`rating-${h}-${ae}`,re.classList.add("magicfeedback-rating-option-label-container");const oe=document.createElement("label");oe.htmlFor=`rating-${h}-${ae}`,oe.textContent=ae.toString();const ce=document.createElement("img");if(ce.alt=`face-${h}-${ae}`,ce.className=`rating-image${ae}`,0===S&&10===L)ce.src=`https://magicfeedback-c6458-dev.web.app/assets/${ae}.svg`;else if(1===S&&5===L)switch(ae){case 1:ce.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:ce.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:ce.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:ce.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:ce.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const le=Math.round(10/(L-S)*(ae-S));ce.src=`https://magicfeedback-c6458-dev.web.app/assets/${le}.svg`}const de=document.createElement("input");de.id=`rating-${h}-${ae}`,de.type="radio",de.name=h,de.value=ae.toString(),de.classList.add(d),de.classList.add("magicfeedback-input"),re.appendChild(de),re.appendChild(ce),re.appendChild(oe),se.appendChild(re),A.appendChild(se)}if(b.extraOption&&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 he=document.createElement("label");he.htmlFor=`rating-${h}-extra`,he.textContent=b.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 fe=document.createElement("input");fe.id=`rating-${h}-extra`,fe.type="radio",fe.name=h,fe.value="-",fe.classList.add(d),fe.classList.add("magicfeedback-input"),pe.appendChild(fe),pe.appendChild(me),pe.appendChild(he),ue.appendChild(pe),A.appendChild(ue)}c.appendChild(T),c.appendChild(A);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),d="magicfeedback-rating-number";const O=document.createElement("div");O.classList.add("magicfeedback-rating-number-container");const P=b.max?Number(b.max):5,I=b.min?Number(b.min):1,N=function(e,t,i,n,a){const s=document.createElement("div");s.classList.add("magicfeedback-rating-placeholder"),s.style.display="flex",s.style.justifyContent="space-between",s.style.width="100%",s.style.margin="auto",window.innerWidth<600&&(s.style.flexDirection="column");const r=a?t+1:t;for(let a=e;a<=r;a++)if(a===e){const t=document.createElement("span");t.textContent=i,t.classList.add("magicfeedback-rating-placeholder-value"),t.style.fontStyle="italic",t.style.fontSize="0.8em",t.style.width=`calc(100% / ${r})`,window.innerWidth<600&&(t.textContent=`${e} ➜ ${i}`,t.style.width="100%",t.style.textAlign="left"),s.appendChild(t)}else if(a===t){const e=document.createElement("span");e.textContent=n,e.classList.add("magicfeedback-rating-placeholder-value"),e.style.fontStyle="italic",e.style.fontSize="0.8em",e.style.width=`calc(100% / ${r})`,window.innerWidth<600&&(e.textContent=`${t} ➜ ${n}`,e.style.width="100%",e.style.textAlign="left"),s.appendChild(e)}else{const e=document.createElement("span");e.textContent="",e.classList.add("magicfeedback-rating-placeholder-value"),e.style.fontStyle="italic",e.style.fontSize="0.8em",e.style.width=`calc(100% / ${r})`,s.appendChild(e)}return s}(I,P,b.minPlaceholder,b.maxPlaceholder,b.extraOption);for(let ge=I;ge<=P;ge++){const be=document.createElement("div");be.classList.add("magicfeedback-rating-number-option");const ye=document.createElement("label");ye.htmlFor=`rating-${h}-${ge}`,ye.classList.add("magicfeedback-rating-number-option-label-container");const ve=document.createElement("label");ve.htmlFor=`rating-${h}-${ge}`,ve.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(d),Ee.classList.add("magicfeedback-input"),ye.appendChild(Ee),ye.appendChild(ve),be.appendChild(ye),O.appendChild(be)}if(b.extraOption&&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=b.extraOptionText;const we=document.createElement("input");we.id=`rating-${h}-extra`,we.type="radio",we.name=h,we.value="-",we.classList.add(d),we.classList.add("magicfeedback-input"),Ce.appendChild(we),Ce.appendChild(xe),ke.appendChild(Ce),O.appendChild(ke)}c.appendChild(N),c.appendChild(O);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),d="magicfeedback-rating-star";const _=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let n=1;n<=5;n++){const a=document.createElement("label");a.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${n}`,s.type="radio",s.name=e,s.value=n.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=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(s.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),a.appendChild(s);const r=document.createElement("label");r.htmlFor=`rating-${e}-${n}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",a.appendChild(r),i.appendChild(a)}return i}(h);c.appendChild(_);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),d="magicfeedback-multiple-choice-image";const $=document.createElement("div");$.classList.add("magicfeedback-multiple-choice-image-container"),$.style.display="flex",$.style.flexDirection="row",$.style.flexWrap="wrap",$.style.justifyContent="center";const D=f.length;let M=1,R=1;switch(D){case 1:case 2:case 3:M=D,R=1;break;case 4:case 5:case 6:R=2,M=Math.ceil(D/R);break;case 7:case 8:case 9:R=3,M=Math.ceil(D/R);break;default:R=4,M=Math.ceil(D/R)}const F=void 0!==(null==b?void 0:b.addTitle)&&b.addTitle,B=void 0!==(null==b?void 0:b.multiOption)&&b.multiOption,q=void 0!==(null==b?void 0:b.randomPosition)&&b.randomPosition,j=void 0!==(null==b?void 0:b.extraOption)&&b.extraOption;function U(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/R}% - 10px)`,a.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 r=document.createElement("label");r.textContent=n,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${h}-${t}`,o.type=B?"checkbox":"radio",o.name=h,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 c=document.createElement("img");c.classList.add("magicfeedback-multiple-choice-image-image"),c.src=i,c.style.cursor="pointer",c.style.backgroundSize="cover",c.style.backgroundPosition="center",c.style.width="100%",c.style.height="100%",c.style.objectFit="cover",c.style.margin="auto",s.appendChild(o),s.appendChild(c),F&&s.appendChild(r),a.appendChild(s),$.appendChild(a)}catch(e){console.error(e)}}q&&(f=f.sort((()=>Math.random()-.5))),f.forEach((e=>U(JSON.parse(e)))),j&&b.extraOptionValue&&b.extraOptionValue.length>0&&U(b.extraOptionValue[0]),c.appendChild($);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),d="magicfeedback-select";const K=document.createElement("option");K.value="",K.text="slim"===t?s(u,i):g||"Select an option",K.disabled=!0,K.selected=!0,c.appendChild(K),f.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=m,c.placeholder=v||a.placeholder.date(i||"en"),d="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),d="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${l}`,c.name=h,c.value="true",c.required=m,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input");break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=m,c.placeholder=v||"you@example.com",d="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=m,c.placeholder=v||a.placeholder.password(i||"en"),d="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),d="magicfeedback-multi-question-matrix";const W=document.createElement("div");W.classList.add("magicfeedback-multi-question-matrix-container");const Q=document.createElement("table");Q.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 G=document.createElement("tr");["",...f].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",G.appendChild(t)})),Y.appendChild(G);const H=document.createElement("tbody");(null===(o=null==b?void 0:b.options)||void 0===o?void 0:o.length)>0&&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 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),f.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="checkbox",a.name=h,a.value=i,a.id=`matrix-${e}`,a.classList.add("magicfeedback-input"),a.style.padding="0 10px",n.appendChild(a),t.appendChild(n)})),H.appendChild(t)})),Q.appendChild(Y),Q.appendChild(H),W.appendChild(Q),c.appendChild(W);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),d="magicfeedback-priority-list";const V=document.createElement("div");V.classList.add("magicfeedback-priority-list-container");const J=document.createElement("ul");J.classList.add("magicfeedback-priority-list-list"),f.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-${h}`,n.name=h,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 c=i.previousElementSibling;if(c){const d=Number(n.value.split(".")[0])-1;n.value=`${d}. ${e}`,a.textContent=`${d}. ${e}`,r.style.visibility=1===d?"hidden":"visible",o.style.visibility=d===f.length?"hidden":"visible";const l=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=c.querySelector(".magicfeedback-priority-list-item-label"),p=c.querySelector(".magicfeedback-priority-list-arrow-up"),h=c.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===f.length?"hidden":"visible"}J.insertBefore(i,c)}})),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===f.length-1?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const c=i.nextElementSibling;if(c){const d=Number(n.value.split(".")[0])+1;n.value=d.toString(),a.textContent=`${d.toString()}. ${e}`,r.style.visibility=1===d?"hidden":"visible",o.style.visibility=d===f.length?"hidden":"visible";const l=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=c.querySelector(".magicfeedback-priority-list-item-label"),p=c.querySelector(".magicfeedback-priority-list-arrow-up"),h=c.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===f.length?"hidden":"visible"}J.insertBefore(c,i)}})),s.appendChild(o),i.appendChild(s),J.appendChild(i)})),V.appendChild(J),c.appendChild(V);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),d="magicfeedback-point-system";const z=document.createElement("div");z.classList.add("magicfeedback-point-system-container");const X=document.createElement("ul");X.classList.add("magicfeedback-point-system-list"),X.style.padding="0";const Z=100,ee=Z/f.length,te=document.createElement("div");te.classList.add("magicfeedback-point-system-total"),te.textContent="0 / 100 %",te.style.textAlign="right",te.style.fontSize="0.8em",te.style.color="#999",te.style.marginTop="5px",f.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=h,a.id=`point-system-${e}`,a.type="number",a.min="0",a.max=`${Z}`,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=X.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>Z&&(a.value=`${ee}%`,t-=Number(a.value)),te.textContent=`${t} / 100 %`})),n.appendChild(a),n.appendChild(s),t.appendChild(n),X.appendChild(t)})),z.appendChild(X),z.appendChild(te),c.appendChild(z);break;default:return y}c.id=`magicfeedback-${l}`,c.setAttribute("name",h),c.classList.add(d),(void 0!==g||null!==E)&&(c.value=E||g),["RADIO","MULTIPLECHOICE"].includes(p)||(c.classList.add("magicfeedback-input"),c.required=m);const x=document.createElement("label");if(x.setAttribute("for",`magicfeedback-${l}`),x.textContent=s(u,i),x.classList.add("magicfeedback-label"),["CONSENT"].includes(p))y.classList.add("magicfeedback-consent-container"),y.appendChild(c),y.appendChild(x);else{if("slim"!==t&&(y.appendChild(x),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const Ae=document.createElement("img");Ae.src=b.general,Ae.classList.add("magicfeedback-image"),Ae.style.maxWidth="auto",Ae.style.height="400px",Ae.style.margin="10px 0",y.appendChild(Ae)}if("LONGTEXT"===p&&k>0){const Le=document.createElement("div");if(Le.classList.add("magicfeedback-counter"),Le.textContent=`${c.value.length}/${k}`,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}/${k}`})),y.appendChild(c),y.appendChild(Le),b.extraOption&&b.extraOptionText){const Se=document.createElement("div");Se.classList.add("magicfeedback-skip-container"),Se.classList.add("magicfeedback-checkbox-container"),Se.style.display="flex",Se.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 Oe=document.createElement("label");Oe.htmlFor=`skip-${h}`,Oe.textContent=b.extraOptionText,Oe.style.fontSize="0.8em",Oe.style.color="#999",Oe.style.cursor="pointer",Oe.style.margin="0 5px",Te.addEventListener("click",(()=>{c.value="-",r&&r()})),Se.appendChild(Te),Se.appendChild(Oe),y.appendChild(Se)}}else y.appendChild(c)}return y}(t,i,r,o);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{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((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),c={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:c});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:c});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"},c),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"},c),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.3","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 s=a(i(519));let n=null;n||(n=(0,s.default)()),t.default=n},519:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(954),n=i(712),o=i(5),r=i(341),c=i(290);t.default=function(){const e=new n.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)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,s,n,o=!0,c,d){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),s||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:s,privateKey:d,completed:o,id:c,feedback:n};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 s.Form(e,i,a)}}}},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(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=i(5),n=i(341),o=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new s.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.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.censorQuestions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){var i;return a(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const a=localStorage.getItem(`magicfeedback-${this.appId}`);if(a&&new Date(JSON.parse(a).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(a),(0,n.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,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),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.generateForm())}))):this.formData=yield(0,n.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))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}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;try{this.questions.sort(((e,t)=>e.position-t.position));let a=this.generateContainer();const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,o.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),s.appendChild(n),a.appendChild(s),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);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}startForm(){this.generateForm()}generateWelcomeMessage(e){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i)}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){var s;return a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-container-"+this.appId),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,answer:this.feedback.answers,progress:this.progress,total:this.total}));const o=yield this.pushAnswers("MAGICSURVEY"!==(null===(s=this.formData)||void 0===s?void 0:s.identity));o&&(this.id=o,yield this.processNextQuestion(a,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,answer:this.feedback.answers,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+this.censorQuestions.length,total:this.total-this.censorQuestions.length,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 s=e.type,o=e.classList[0],r={key:e.name,value:[]},c="magicfeedback-consent"===o?e.checked.toString():e.value;if(r.key&&""!==r.key)switch(s){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(c);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(""!==c){if("email"===s){if(!(0,n.validateEmail)(c)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[c]})}if(e.id.includes("point-system")){const t=e.id.split("-")[e.id.split("-").length-1];r.value.push(`${t}: ${c}%`)}else r.value.push(c);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)}censureQuestions(e){this.censorQuestions=this.questions.filter((t=>e.includes(t.id))).map((e=>e.id))}pushAnswers(e=!1){var t,i;return a(this,void 0,void 0,(function*(){try{if("MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const a=this.config.get("url"),s={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(a,this.id?Object.assign(Object.assign({},s),{sessionId:this.id}):s,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){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 t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,s,n,r;return a(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(s=this.questionInProcess)||void 0===s?void 0:s.followup){const e=yield this.callFollowUpQuestion(this.questionInProcess);if(e){this.questionInProcess=e;const i=(0,o.renderQuestions)([e],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0])[0];this.history[this.progress].push({object:e,element:i}),t.removeChild(t.childNodes[0]),t.appendChild(i)}else this.renderNextQuestion(t)}else this.renderNextQuestion(t);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){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)}}))}renderNextQuestion(e){this.progress++,this.progress<this.total?(this.questionInProcess=this.history[this.progress][0].object,this.censorQuestions.includes(this.questionInProcess.id)?this.renderNextQuestion(e):(e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element))):this.finish()}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e&&e.childNodes.length>0&&e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;let t=this.history[this.progress][this.history[this.progress].length-1];this.censorQuestions.includes(t.object.id)?this.back():(this.questionInProcess=t.object,e.appendChild(t.element))}}},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),s=i(528);function n(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",o="en",r){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var d,l;if((null===(l=null===(d=null==t?void 0:t.questionType)||void 0===d?void 0:d.conf)||void 0===l?void 0:l.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,o,r).forEach((e=>{a.appendChild(e)})),c.push(a)}else{const e=function(e,t,i,o){var r;let c,d,{id:l,title:u,type:p,ref:m,require:h,value:f,defaultValue:g,assets:b}=e,v=document.createElement("div");v.classList.add("magicfeedback-div");const y="slim"===t?n(u,i):null==b?void 0:b.placeholder,E=(C=l,new URLSearchParams(window.location.search).get(C)),k=b.maxCharacters||300;var C;switch(p){case a.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=y||s.placeholder.answer(i||"en"),d="magicfeedback-text";break;case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,k>0&&(c.maxLength=k),c.placeholder=y||s.placeholder.answer(i||"en"),d="magicfeedback-longtext";break;case a.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?n(u,i):s.placeholder.number(i||"en"),d="magicfeedback-number",f.length&&(f.sort(((e,t)=>Number(e)-Number(t))),c.max=f[f.length-1],c.min=f[0],c.value=f[0]);break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),d="magicfeedback-"+("MULTIPLECHOICE"===p?"checkbox":"radio"),b.extraOption&&f.push(b.extraOptionText),f.forEach(((e,t)=>{const n=document.createElement("div");n.classList.add(`magicfeedback-${"MULTIPLECHOICE"===p?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${m}-${t}`,r.type="MULTIPLECHOICE"===p?"checkbox":"radio",r.name=m,r.value=e,r.classList.add(d),r.classList.add("magicfeedback-input"),p===a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&b.maxOptions&&b.maxOptions>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${m}"]:checked`).length>b.maxOptions&&(r.checked=!1)})),e!==g&&e!==E||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${m}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${m}`);i&&b.extraOption&&(t.target.checked&&e===b.extraOptionText?i.style.display="block":i.style.display="none")})),n.appendChild(r),n.appendChild(o),c.appendChild(n),b.extraOption&&e===b.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder=b.extraOptionPlaceholder||s.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 a.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),d="magicfeedback-radio";const w=document.createElement("div");w.classList.add("magicfeedback-boolean-container"),w.style.display="flex",w.style.flexDirection="row",w.style.justifyContent="space-between",w.style.width="70%",w.style.margin="auto",(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-${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 a=document.createElement("label");a.htmlFor=`rating-${m}-${t}`,a.textContent=e,a.style.margin="0",a.style.padding="0";const s=document.createElement("input");s.id=`rating-${m}-${t}`,s.type="radio",s.name=m,s.value=e,s.classList.add(d),s.classList.add("magicfeedback-input"),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.style.margin="0",s.addEventListener("change",(()=>{o&&o()})),i.appendChild(s),i.appendChild(a),w.appendChild(i)})),c.appendChild(w);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),d="magicfeedback-rating";const L=document.createElement("div");L.classList.add("magicfeedback-rating-container");const S=b.max?Number(b.max):5,A=b.min?Number(b.min):1,T=document.createElement("div");if(T.classList.add("magicfeedback-rating-placeholder"),T.style.display="flex",T.style.justifyContent="space-between",T.style.width="90%",T.style.margin="auto",b.minPlaceholder){const ie=document.createElement("span");ie.textContent=b.minPlaceholder,ie.classList.add("magicfeedback-rating-placeholder-min"),ie.style.fontStyle="italic",ie.style.fontSize="0.8em",T.appendChild(ie)}if(b.maxPlaceholder){const ae=document.createElement("span");ae.textContent=b.maxPlaceholder,ae.classList.add("magicfeedback-rating-placeholder-max"),ae.style.fontStyle="italic",ae.style.fontSize="0.8em",T.appendChild(ae)}for(let se=A;se<=S;se++){const ne=document.createElement("div");ne.classList.add("magicfeedback-rating-option");const oe=document.createElement("label");oe.htmlFor=`rating-${m}-${se}`,oe.classList.add("magicfeedback-rating-option-label-container");const re=document.createElement("label");re.htmlFor=`rating-${m}-${se}`,re.textContent=se.toString();const ce=document.createElement("img");if(ce.alt=`face-${m}-${se}`,ce.className=`rating-image${se}`,0===A&&10===S)ce.src=`https://magicfeedback-c6458-dev.web.app/assets/${se}.svg`;else if(1===A&&5===S)switch(se){case 1:ce.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:ce.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:ce.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:ce.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:ce.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const le=Math.round(10/(S-A)*(se-A));ce.src=`https://magicfeedback-c6458-dev.web.app/assets/${le}.svg`}const de=document.createElement("input");de.id=`rating-${m}-${se}`,de.type="radio",de.name=m,de.value=se.toString(),de.classList.add(d),de.classList.add("magicfeedback-input"),oe.appendChild(de),oe.appendChild(ce),oe.appendChild(re),ne.appendChild(oe),L.appendChild(ne)}if(b.extraOption&&b.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 me=document.createElement("label");me.htmlFor=`rating-${m}-extra`,me.textContent=b.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 fe=document.createElement("input");fe.id=`rating-${m}-extra`,fe.type="radio",fe.name=m,fe.value="-",fe.classList.add(d),fe.classList.add("magicfeedback-input"),pe.appendChild(fe),pe.appendChild(he),pe.appendChild(me),ue.appendChild(pe),L.appendChild(ue)}c.appendChild(T),c.appendChild(L);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),d="magicfeedback-rating-number";const O=document.createElement("div");O.classList.add("magicfeedback-rating-number-container");const I=b.max?Number(b.max):5,P=b.min?Number(b.min):1,N=document.createElement("div");if(N.classList.add("magicfeedback-rating-number-placeholder"),N.style.display="flex",N.style.justifyContent="space-between",N.style.width="90%",N.style.margin="auto",b.minPlaceholder){const ge=document.createElement("span");ge.textContent=b.minPlaceholder,ge.classList.add("magicfeedback-rating-number-placeholder-min"),ge.style.fontStyle="italic",ge.style.fontSize="0.8em",N.appendChild(ge)}if(b.maxPlaceholder){const be=document.createElement("span");be.textContent=b.maxPlaceholder,be.classList.add("magicfeedback-rating-number-placeholder-max"),be.style.fontStyle="italic",be.style.fontSize="0.8em",N.appendChild(be)}for(let ve=P;ve<=I;ve++){const ye=document.createElement("div");ye.classList.add("magicfeedback-rating-number-option");const Ee=document.createElement("label");Ee.htmlFor=`rating-${m}-${ve}`,Ee.classList.add("magicfeedback-rating-number-option-label-container");const ke=document.createElement("label");ke.htmlFor=`rating-${m}-${ve}`,ke.textContent=ve.toString();const Ce=document.createElement("input");Ce.id=`rating-${m}-${ve}`,Ce.type="radio",Ce.name=m,Ce.value=ve.toString(),Ce.classList.add(d),Ce.classList.add("magicfeedback-input"),Ee.appendChild(Ce),Ee.appendChild(ke),ye.appendChild(Ee),O.appendChild(ye)}if(b.extraOption&&b.extraOptionText){const xe=document.createElement("div");xe.classList.add("magicfeedback-rating-number-option");const we=document.createElement("label");we.htmlFor=`rating-${m}-extra`,we.classList.add("magicfeedback-rating-number-option-label-container");const Le=document.createElement("label");Le.htmlFor=`rating-${m}-extra`,Le.textContent=b.extraOptionText;const Se=document.createElement("input");Se.id=`rating-${m}-extra`,Se.type="radio",Se.name=m,Se.value="-",Se.classList.add(d),Se.classList.add("magicfeedback-input"),we.appendChild(Se),we.appendChild(Le),xe.appendChild(we),O.appendChild(xe)}c.appendChild(N),c.appendChild(O);break;case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),d="magicfeedback-rating-star";const $=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let a=1;a<=5;a++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${a}`,n.type="radio",n.name=e,n.value=a.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(n.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),s.appendChild(n);const o=document.createElement("label");o.htmlFor=`rating-${e}-${a}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",s.appendChild(o),i.appendChild(s)}return i}(m);c.appendChild($);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),d="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 D=f.length;let F=1,_=1;switch(D){case 1:case 2:case 3:F=D,_=1;break;case 4:case 5:case 6:_=2,F=Math.ceil(D/_);break;case 7:case 8:case 9:_=3,F=Math.ceil(D/_);break;default:_=4,F=Math.ceil(D/_)}const q=void 0!==(null==b?void 0:b.addTitle)&&b.addTitle,R=void 0!==(null==b?void 0:b.multiOption)&&b.multiOption,j=void 0!==(null==b?void 0:b.randomPosition)&&b.randomPosition,B=void 0!==(null==b?void 0:b.extraOption)&&b.extraOption;function U(e){try{const{position:t,url:i,value:a}=e,s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/F}% - 10px)`,s.style.height=`calc( ${100/_}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${m}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.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-${m}-${t}`,r.type=R?"checkbox":"radio",r.name=m,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 c=document.createElement("img");c.classList.add("magicfeedback-multiple-choice-image-image"),c.src=i,c.style.cursor="pointer",c.style.backgroundSize="cover",c.style.backgroundPosition="center",c.style.width="100%",c.style.height="100%",c.style.objectFit="cover",c.style.margin="auto",n.appendChild(r),n.appendChild(c),q&&n.appendChild(o),s.appendChild(n),M.appendChild(s)}catch(e){console.error(e)}}j&&(f=f.sort((()=>Math.random()-.5))),f.forEach((e=>U(JSON.parse(e)))),B&&b.extraOptionValue&&b.extraOptionValue.length>0&&U(b.extraOptionValue[0]),c.appendChild(M);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),d="magicfeedback-select";const K=document.createElement("option");K.value="",K.text="slim"===t?n(u,i):g||"Select an option",K.disabled=!0,K.selected=!0,c.appendChild(K),f.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=h,c.placeholder=y||s.placeholder.date(i||"en"),d="magicfeedback-date";break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),d="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${l}`,c.name=m,c.value="true",c.required=h,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input");break;case a.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=h,c.placeholder=y||"you@example.com",d="magicfeedback-email";break;case a.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=h,c.placeholder=y||s.placeholder.password(i||"en"),d="magicfeedback-password";break;case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),d="magicfeedback-multi-question-matrix";const Q=document.createElement("div");Q.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 G=document.createElement("tr");["",...f].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",G.appendChild(t)})),Y.appendChild(G);const H=document.createElement("tbody");(null===(r=null==b?void 0:b.options)||void 0===r?void 0:r.length)>0&&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),f.forEach((i=>{const a=document.createElement("td"),s=document.createElement("input");s.type="checkbox",s.name=m,s.value=i,s.id=`matrix-${e}`,s.classList.add("magicfeedback-input"),s.style.padding="0 10px",a.appendChild(s),t.appendChild(a)})),H.appendChild(t)})),W.appendChild(Y),W.appendChild(H),Q.appendChild(W),c.appendChild(Q);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),d="magicfeedback-priority-list";const J=document.createElement("div");J.classList.add("magicfeedback-priority-list-container");const V=document.createElement("ul");V.classList.add("magicfeedback-priority-list-list"),f.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-${m}`,a.name=m,a.value=`${t+1}. ${e}`,i.appendChild(a);const s=document.createElement("label");s.classList.add("magicfeedback-priority-list-item-label"),s.textContent=`${t+1}. ${e}`,i.appendChild(s);const n=document.createElement("div");n.style.display="flex",n.style.alignItems="center",n.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,n;const c=i.previousElementSibling;if(c){const d=Number(a.value.split(".")[0])-1;a.value=`${d}. ${e}`,s.textContent=`${d}. ${e}`,o.style.visibility=1===d?"hidden":"visible",r.style.visibility=d===f.length?"hidden":"visible";const l=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=c.querySelector(".magicfeedback-priority-list-item-label"),p=c.querySelector(".magicfeedback-priority-list-arrow-up"),m=c.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===(n=u.textContent)||void 0===n?void 0:n.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===f.length?"hidden":"visible"}V.insertBefore(i,c)}})),n.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===f.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,n;const c=i.nextElementSibling;if(c){const d=Number(a.value.split(".")[0])+1;a.value=d.toString(),s.textContent=`${d.toString()}. ${e}`,o.style.visibility=1===d?"hidden":"visible",r.style.visibility=d===f.length?"hidden":"visible";const l=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=c.querySelector(".magicfeedback-priority-list-item-label"),p=c.querySelector(".magicfeedback-priority-list-arrow-up"),m=c.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===(n=u.textContent)||void 0===n?void 0:n.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===f.length?"hidden":"visible"}V.insertBefore(c,i)}})),n.appendChild(r),i.appendChild(n),V.appendChild(i)})),J.appendChild(V),c.appendChild(J);break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),d="magicfeedback-point-system";const z=document.createElement("div");z.classList.add("magicfeedback-point-system-container");const X=document.createElement("ul");X.classList.add("magicfeedback-point-system-list"),X.style.padding="0";const Z=100,ee=Z/f.length,te=document.createElement("div");te.classList.add("magicfeedback-point-system-total"),te.textContent="0 / 100 %",te.style.textAlign="right",te.style.fontSize="0.8em",te.style.color="#999",te.style.marginTop="5px",f.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 s=document.createElement("input");s.name=m,s.id=`point-system-${e}`,s.type="number",s.min="0",s.max=`${Z}`,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";const n=document.createElement("span");n.textContent="%",n.style.color="#000",s.addEventListener("input",(()=>{const e=X.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>Z&&(s.value=`${ee}%`,t-=Number(s.value)),te.textContent=`${t} / 100 %`})),a.appendChild(s),a.appendChild(n),t.appendChild(a),X.appendChild(t)})),z.appendChild(X),z.appendChild(te),c.appendChild(z);break;default:return v}c.id=`magicfeedback-${l}`,c.setAttribute("name",m),c.classList.add(d),(void 0!==g||null!==E)&&(c.value=E||g),["RADIO","MULTIPLECHOICE"].includes(p)||(c.classList.add("magicfeedback-input"),c.required=h);const x=document.createElement("label");if(x.setAttribute("for",`magicfeedback-${l}`),x.textContent=n(u,i),x.classList.add("magicfeedback-label"),["CONSENT"].includes(p))v.classList.add("magicfeedback-consent-container"),v.appendChild(c),v.appendChild(x);else{if("slim"!==t&&(v.appendChild(x),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const Ae=document.createElement("img");Ae.src=b.general,Ae.classList.add("magicfeedback-image"),Ae.style.maxWidth="auto",Ae.style.height="400px",Ae.style.margin="10px 0",v.appendChild(Ae)}if("LONGTEXT"===p&&k>0){const Te=document.createElement("div");if(Te.classList.add("magicfeedback-counter"),Te.textContent=`${c.value.length}/${k}`,Te.style.textAlign="right",Te.style.fontSize="0.8em",Te.style.color="#999",Te.style.marginTop="5px",c.addEventListener("input",(()=>{Te.textContent=`${c.value.length}/${k}`})),v.appendChild(c),v.appendChild(Te),b.extraOption&&b.extraOptionText){const Oe=document.createElement("div");Oe.classList.add("magicfeedback-skip-container"),Oe.classList.add("magicfeedback-checkbox-container"),Oe.style.display="flex",Oe.style.justifyContent="flex-start";const Ie=document.createElement("input");Ie.classList.add("magicfeedback-skip"),Ie.type="checkbox",Ie.id=`skip-${m}`,Ie.name=m,Ie.value="-",Ie.style.cursor="pointer";const Pe=document.createElement("label");Pe.htmlFor=`skip-${m}`,Pe.textContent=b.extraOptionText,Pe.style.fontSize="0.8em",Pe.style.color="#999",Pe.style.cursor="pointer",Pe.style.margin="0 5px",Ie.addEventListener("click",(()=>{c.value="-",o&&o()})),Oe.appendChild(Ie),Oe.appendChild(Pe),v.appendChild(Oe)}}else v.appendChild(c)}return v}(t,i,o,r);c.push(e)}})),c},t.renderActions=function(e="",t,i="Submit",a="Back",s="Next"){const n=document.createElement("div");n.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?s||"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&&n.appendChild(r),n.appendChild(o),n},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 s=document.createElement("div");s.classList.add("magicfeedback-start-message-container");const n=document.createElement("div");n.classList.add("magicfeedback-start-message"),n.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())),s.appendChild(n),i&&s.appendChild(o),s}},341:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))},s=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 n=s(i(31)),o=s(i(147)),r=i(374),c={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,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getQuestions=function(e,t,i,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),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,n.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),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.1","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 s=t[a];if(void 0!==s)return s.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,i),n.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 s=a(i(519));let n=null;n||(n=(0,s.default)()),t.default=n},519:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(954),n=i(712),o=i(5),r=i(341),c=i(290);t.default=function(){const e=new n.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)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,s,n,o=!0,c,d){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),s||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:s,privateKey:d,completed:o,id:c,feedback:n};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 s.Form(e,i,a)}}}},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(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=i(5),n=i(341),o=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new s.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.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.censorQuestions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){var i;return a(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const a=localStorage.getItem(`magicfeedback-${this.appId}`);if(a&&new Date(JSON.parse(a).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(a),(0,n.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,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),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.generateForm())}))):this.formData=yield(0,n.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))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}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;try{this.questions.sort(((e,t)=>e.position-t.position));let a=this.generateContainer();const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,o.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),s.appendChild(n),a.appendChild(s),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);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}startForm(){this.generateForm()}generateWelcomeMessage(e){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,(()=>this.startForm()),this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText);t.appendChild(i)}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){var s;return a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-container-"+this.appId),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,answer:this.feedback.answers,progress:this.progress,total:this.total}));const o=yield this.pushAnswers("MAGICSURVEY"!==(null===(s=this.formData)||void 0===s?void 0:s.identity));o&&(this.id=o,yield this.processNextQuestion(a,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,answer:this.feedback.answers,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+this.censorQuestions.length,total:this.total-this.censorQuestions.length,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 s=e.type,o=e.classList[0],r={key:e.name,value:[]},c="magicfeedback-consent"===o?e.checked.toString():e.value;if(r.key&&""!==r.key)switch(s){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(c);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(""!==c){if("email"===s){if(!(0,n.validateEmail)(c)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[c]})}if(e.id.includes("point-system")){const t=e.id.split("-")[e.id.split("-").length-1];r.value.push(`${t}: ${c}%`)}else r.value.push(c);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)}censureQuestions(e){this.censorQuestions=this.questions.filter((t=>e.includes(t.id))).map((e=>e.id))}pushAnswers(e=!1){var t,i;return a(this,void 0,void 0,(function*(){try{if("MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const a=this.config.get("url"),s={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(a,this.id?Object.assign(Object.assign({},s),{sessionId:this.id}):s,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){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 t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,s,n,r;return a(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(s=this.questionInProcess)||void 0===s?void 0:s.followup){const e=yield this.callFollowUpQuestion(this.questionInProcess);if(e){this.questionInProcess=e;const i=(0,o.renderQuestions)([e],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0])[0];this.history[this.progress].push({object:e,element:i}),t.removeChild(t.childNodes[0]),t.appendChild(i)}else this.renderNextQuestion(t)}else this.renderNextQuestion(t);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){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)}}))}renderNextQuestion(e){this.progress++,this.progress<this.total?(this.questionInProcess=this.history[this.progress][0].object,this.censorQuestions.includes(this.questionInProcess.id)?this.renderNextQuestion(e):(e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element))):this.finish()}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e&&e.childNodes.length>0&&e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;let t=this.history[this.progress][this.history[this.progress].length-1];this.censorQuestions.includes(t.object.id)?this.back():(this.questionInProcess=t.object,e.appendChild(t.element))}}},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),s=i(528);function n(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",o="en",r){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var d,l;if((null===(l=null===(d=null==t?void 0:t.questionType)||void 0===d?void 0:d.conf)||void 0===l?void 0:l.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,o,r).forEach((e=>{a.appendChild(e)})),c.push(a)}else{const e=function(e,t,i,o){var r;let c,d,{id:l,title:u,type:p,ref:m,require:h,value:f,defaultValue:g,assets:b}=e,v=document.createElement("div");v.classList.add("magicfeedback-div");const y="slim"===t?n(u,i):null==b?void 0:b.placeholder,E=(C=l,new URLSearchParams(window.location.search).get(C)),k=b.maxCharacters||300;var C;switch(p){case a.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=y||s.placeholder.answer(i||"en"),d="magicfeedback-text";break;case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,k>0&&(c.maxLength=k),c.placeholder=y||s.placeholder.answer(i||"en"),d="magicfeedback-longtext";break;case a.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?n(u,i):s.placeholder.number(i||"en"),d="magicfeedback-number",f.length&&(f.sort(((e,t)=>Number(e)-Number(t))),c.max=f[f.length-1],c.min=f[0],c.value=f[0]);break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),d="magicfeedback-"+("MULTIPLECHOICE"===p?"checkbox":"radio"),b.extraOption&&f.push(b.extraOptionText),f.forEach(((e,t)=>{const n=document.createElement("div");n.classList.add(`magicfeedback-${"MULTIPLECHOICE"===p?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${m}-${t}`,r.type="MULTIPLECHOICE"===p?"checkbox":"radio",r.name=m,r.value=e,r.classList.add(d),r.classList.add("magicfeedback-input"),p===a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&b.maxOptions&&b.maxOptions>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${m}"]:checked`).length>b.maxOptions&&(r.checked=!1)})),e!==g&&e!==E||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${m}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${m}`);i&&b.extraOption&&(t.target.checked&&e===b.extraOptionText?i.style.display="block":i.style.display="none")})),n.appendChild(r),n.appendChild(o),c.appendChild(n),b.extraOption&&e===b.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder=b.extraOptionPlaceholder||s.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 a.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),d="magicfeedback-radio";const w=document.createElement("div");w.classList.add("magicfeedback-boolean-container"),w.style.display="flex",w.style.flexDirection="row",w.style.justifyContent="space-between",w.style.width="70%",w.style.margin="auto",(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-${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 a=document.createElement("label");a.htmlFor=`rating-${m}-${t}`,a.textContent=e,a.style.margin="0",a.style.padding="0";const s=document.createElement("input");s.id=`rating-${m}-${t}`,s.type="radio",s.name=m,s.value=e,s.classList.add(d),s.classList.add("magicfeedback-input"),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.style.margin="0",s.addEventListener("change",(()=>{o&&o()})),i.appendChild(s),i.appendChild(a),w.appendChild(i)})),c.appendChild(w);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),d="magicfeedback-rating";const L=document.createElement("div");L.classList.add("magicfeedback-rating-container");const S=b.max?Number(b.max):5,A=b.min?Number(b.min):1,T=document.createElement("div");if(T.classList.add("magicfeedback-rating-placeholder"),T.style.display="flex",T.style.justifyContent="space-between",T.style.width="90%",T.style.margin="auto",b.minPlaceholder){const ie=document.createElement("span");ie.textContent=b.minPlaceholder,ie.classList.add("magicfeedback-rating-placeholder-min"),ie.style.fontStyle="italic",ie.style.fontSize="0.8em",T.appendChild(ie)}if(b.maxPlaceholder){const ae=document.createElement("span");ae.textContent=b.maxPlaceholder,ae.classList.add("magicfeedback-rating-placeholder-max"),ae.style.fontStyle="italic",ae.style.fontSize="0.8em",T.appendChild(ae)}for(let se=A;se<=S;se++){const ne=document.createElement("div");ne.classList.add("magicfeedback-rating-option");const oe=document.createElement("label");oe.htmlFor=`rating-${m}-${se}`,oe.classList.add("magicfeedback-rating-option-label-container");const re=document.createElement("label");re.htmlFor=`rating-${m}-${se}`,re.textContent=se.toString();const ce=document.createElement("img");if(ce.alt=`face-${m}-${se}`,ce.className=`rating-image${se}`,0===A&&10===S)ce.src=`https://magicfeedback-c6458-dev.web.app/assets/${se}.svg`;else if(1===A&&5===S)switch(se){case 1:ce.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:ce.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:ce.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:ce.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:ce.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const le=Math.round(10/(S-A)*(se-A));ce.src=`https://magicfeedback-c6458-dev.web.app/assets/${le}.svg`}const de=document.createElement("input");de.id=`rating-${m}-${se}`,de.type="radio",de.name=m,de.value=se.toString(),de.classList.add(d),de.classList.add("magicfeedback-input"),oe.appendChild(de),oe.appendChild(ce),oe.appendChild(re),ne.appendChild(oe),L.appendChild(ne)}if(b.extraOption&&b.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 me=document.createElement("label");me.htmlFor=`rating-${m}-extra`,me.textContent=b.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 fe=document.createElement("input");fe.id=`rating-${m}-extra`,fe.type="radio",fe.name=m,fe.value="-",fe.classList.add(d),fe.classList.add("magicfeedback-input"),pe.appendChild(fe),pe.appendChild(he),pe.appendChild(me),ue.appendChild(pe),L.appendChild(ue)}c.appendChild(T),c.appendChild(L);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),d="magicfeedback-rating-number";const O=document.createElement("div");O.classList.add("magicfeedback-rating-number-container");const I=b.max?Number(b.max):5,P=b.min?Number(b.min):1,N=function(e,t,i,a,s){const n=document.createElement("div");n.classList.add("magicfeedback-rating-placeholder"),n.style.display="flex",n.style.justifyContent="space-between",n.style.width="100%",n.style.margin="auto",window.innerWidth<600&&(n.style.flexDirection="column");const o=s?t+1:t;for(let s=e;s<=o;s++)if(s===e){const t=document.createElement("span");t.textContent=i,t.classList.add("magicfeedback-rating-placeholder-value"),t.style.fontStyle="italic",t.style.fontSize="0.8em",t.style.width=`calc(100% / ${o})`,window.innerWidth<600&&(t.textContent=`${e} ➜ ${i}`,t.style.width="100%",t.style.textAlign="left"),n.appendChild(t)}else if(s===t){const e=document.createElement("span");e.textContent=a,e.classList.add("magicfeedback-rating-placeholder-value"),e.style.fontStyle="italic",e.style.fontSize="0.8em",e.style.width=`calc(100% / ${o})`,window.innerWidth<600&&(e.textContent=`${t} ➜ ${a}`,e.style.width="100%",e.style.textAlign="left"),n.appendChild(e)}else{const e=document.createElement("span");e.textContent="",e.classList.add("magicfeedback-rating-placeholder-value"),e.style.fontStyle="italic",e.style.fontSize="0.8em",e.style.width=`calc(100% / ${o})`,n.appendChild(e)}return n}(P,I,b.minPlaceholder,b.maxPlaceholder,b.extraOption);for(let ge=P;ge<=I;ge++){const be=document.createElement("div");be.classList.add("magicfeedback-rating-number-option");const ve=document.createElement("label");ve.htmlFor=`rating-${m}-${ge}`,ve.classList.add("magicfeedback-rating-number-option-label-container");const ye=document.createElement("label");ye.htmlFor=`rating-${m}-${ge}`,ye.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(d),Ee.classList.add("magicfeedback-input"),ve.appendChild(Ee),ve.appendChild(ye),be.appendChild(ve),O.appendChild(be)}if(b.extraOption&&b.extraOptionText){const ke=document.createElement("div");ke.classList.add("magicfeedback-rating-number-option");const Ce=document.createElement("label");Ce.htmlFor=`rating-${m}-extra`,Ce.classList.add("magicfeedback-rating-number-option-label-container");const xe=document.createElement("label");xe.htmlFor=`rating-${m}-extra`,xe.textContent=b.extraOptionText;const we=document.createElement("input");we.id=`rating-${m}-extra`,we.type="radio",we.name=m,we.value="-",we.classList.add(d),we.classList.add("magicfeedback-input"),Ce.appendChild(we),Ce.appendChild(xe),ke.appendChild(Ce),O.appendChild(ke)}c.appendChild(N),c.appendChild(O);break;case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),d="magicfeedback-rating-star";const $=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let a=1;a<=5;a++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${a}`,n.type="radio",n.name=e,n.value=a.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(n.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),s.appendChild(n);const o=document.createElement("label");o.htmlFor=`rating-${e}-${a}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",s.appendChild(o),i.appendChild(s)}return i}(m);c.appendChild($);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),d="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 D=f.length;let F=1,_=1;switch(D){case 1:case 2:case 3:F=D,_=1;break;case 4:case 5:case 6:_=2,F=Math.ceil(D/_);break;case 7:case 8:case 9:_=3,F=Math.ceil(D/_);break;default:_=4,F=Math.ceil(D/_)}const q=void 0!==(null==b?void 0:b.addTitle)&&b.addTitle,R=void 0!==(null==b?void 0:b.multiOption)&&b.multiOption,j=void 0!==(null==b?void 0:b.randomPosition)&&b.randomPosition,B=void 0!==(null==b?void 0:b.extraOption)&&b.extraOption;function U(e){try{const{position:t,url:i,value:a}=e,s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/F}% - 10px)`,s.style.height=`calc( ${100/_}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${m}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.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-${m}-${t}`,r.type=R?"checkbox":"radio",r.name=m,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 c=document.createElement("img");c.classList.add("magicfeedback-multiple-choice-image-image"),c.src=i,c.style.cursor="pointer",c.style.backgroundSize="cover",c.style.backgroundPosition="center",c.style.width="100%",c.style.height="100%",c.style.objectFit="cover",c.style.margin="auto",n.appendChild(r),n.appendChild(c),q&&n.appendChild(o),s.appendChild(n),M.appendChild(s)}catch(e){console.error(e)}}j&&(f=f.sort((()=>Math.random()-.5))),f.forEach((e=>U(JSON.parse(e)))),B&&b.extraOptionValue&&b.extraOptionValue.length>0&&U(b.extraOptionValue[0]),c.appendChild(M);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),d="magicfeedback-select";const K=document.createElement("option");K.value="",K.text="slim"===t?n(u,i):g||"Select an option",K.disabled=!0,K.selected=!0,c.appendChild(K),f.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=h,c.placeholder=y||s.placeholder.date(i||"en"),d="magicfeedback-date";break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),d="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${l}`,c.name=m,c.value="true",c.required=h,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input");break;case a.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=h,c.placeholder=y||"you@example.com",d="magicfeedback-email";break;case a.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=h,c.placeholder=y||s.placeholder.password(i||"en"),d="magicfeedback-password";break;case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),d="magicfeedback-multi-question-matrix";const W=document.createElement("div");W.classList.add("magicfeedback-multi-question-matrix-container");const Q=document.createElement("table");Q.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 G=document.createElement("tr");["",...f].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",G.appendChild(t)})),Y.appendChild(G);const H=document.createElement("tbody");(null===(r=null==b?void 0:b.options)||void 0===r?void 0:r.length)>0&&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),f.forEach((i=>{const a=document.createElement("td"),s=document.createElement("input");s.type="checkbox",s.name=m,s.value=i,s.id=`matrix-${e}`,s.classList.add("magicfeedback-input"),s.style.padding="0 10px",a.appendChild(s),t.appendChild(a)})),H.appendChild(t)})),Q.appendChild(Y),Q.appendChild(H),W.appendChild(Q),c.appendChild(W);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),d="magicfeedback-priority-list";const J=document.createElement("div");J.classList.add("magicfeedback-priority-list-container");const V=document.createElement("ul");V.classList.add("magicfeedback-priority-list-list"),f.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-${m}`,a.name=m,a.value=`${t+1}. ${e}`,i.appendChild(a);const s=document.createElement("label");s.classList.add("magicfeedback-priority-list-item-label"),s.textContent=`${t+1}. ${e}`,i.appendChild(s);const n=document.createElement("div");n.style.display="flex",n.style.alignItems="center",n.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,n;const c=i.previousElementSibling;if(c){const d=Number(a.value.split(".")[0])-1;a.value=`${d}. ${e}`,s.textContent=`${d}. ${e}`,o.style.visibility=1===d?"hidden":"visible",r.style.visibility=d===f.length?"hidden":"visible";const l=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=c.querySelector(".magicfeedback-priority-list-item-label"),p=c.querySelector(".magicfeedback-priority-list-arrow-up"),m=c.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===(n=u.textContent)||void 0===n?void 0:n.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===f.length?"hidden":"visible"}V.insertBefore(i,c)}})),n.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===f.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,n;const c=i.nextElementSibling;if(c){const d=Number(a.value.split(".")[0])+1;a.value=d.toString(),s.textContent=`${d.toString()}. ${e}`,o.style.visibility=1===d?"hidden":"visible",r.style.visibility=d===f.length?"hidden":"visible";const l=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=c.querySelector(".magicfeedback-priority-list-item-label"),p=c.querySelector(".magicfeedback-priority-list-arrow-up"),m=c.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===(n=u.textContent)||void 0===n?void 0:n.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===f.length?"hidden":"visible"}V.insertBefore(c,i)}})),n.appendChild(r),i.appendChild(n),V.appendChild(i)})),J.appendChild(V),c.appendChild(J);break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),d="magicfeedback-point-system";const z=document.createElement("div");z.classList.add("magicfeedback-point-system-container");const X=document.createElement("ul");X.classList.add("magicfeedback-point-system-list"),X.style.padding="0";const Z=100,ee=Z/f.length,te=document.createElement("div");te.classList.add("magicfeedback-point-system-total"),te.textContent="0 / 100 %",te.style.textAlign="right",te.style.fontSize="0.8em",te.style.color="#999",te.style.marginTop="5px",f.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 s=document.createElement("input");s.name=m,s.id=`point-system-${e}`,s.type="number",s.min="0",s.max=`${Z}`,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";const n=document.createElement("span");n.textContent="%",n.style.color="#000",s.addEventListener("input",(()=>{const e=X.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>Z&&(s.value=`${ee}%`,t-=Number(s.value)),te.textContent=`${t} / 100 %`})),a.appendChild(s),a.appendChild(n),t.appendChild(a),X.appendChild(t)})),z.appendChild(X),z.appendChild(te),c.appendChild(z);break;default:return v}c.id=`magicfeedback-${l}`,c.setAttribute("name",m),c.classList.add(d),(void 0!==g||null!==E)&&(c.value=E||g),["RADIO","MULTIPLECHOICE"].includes(p)||(c.classList.add("magicfeedback-input"),c.required=h);const x=document.createElement("label");if(x.setAttribute("for",`magicfeedback-${l}`),x.textContent=n(u,i),x.classList.add("magicfeedback-label"),["CONSENT"].includes(p))v.classList.add("magicfeedback-consent-container"),v.appendChild(c),v.appendChild(x);else{if("slim"!==t&&(v.appendChild(x),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const Le=document.createElement("img");Le.src=b.general,Le.classList.add("magicfeedback-image"),Le.style.maxWidth="auto",Le.style.height="400px",Le.style.margin="10px 0",v.appendChild(Le)}if("LONGTEXT"===p&&k>0){const Se=document.createElement("div");if(Se.classList.add("magicfeedback-counter"),Se.textContent=`${c.value.length}/${k}`,Se.style.textAlign="right",Se.style.fontSize="0.8em",Se.style.color="#999",Se.style.marginTop="5px",c.addEventListener("input",(()=>{Se.textContent=`${c.value.length}/${k}`})),v.appendChild(c),v.appendChild(Se),b.extraOption&&b.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-${m}`,Te.name=m,Te.value="-",Te.style.cursor="pointer";const Oe=document.createElement("label");Oe.htmlFor=`skip-${m}`,Oe.textContent=b.extraOptionText,Oe.style.fontSize="0.8em",Oe.style.color="#999",Oe.style.cursor="pointer",Oe.style.margin="0 5px",Te.addEventListener("click",(()=>{c.value="-",o&&o()})),Ae.appendChild(Te),Ae.appendChild(Oe),v.appendChild(Ae)}}else v.appendChild(c)}return v}(t,i,o,r);c.push(e)}})),c},t.renderActions=function(e="",t,i="Submit",a="Back",s="Next"){const n=document.createElement("div");n.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?s||"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&&n.appendChild(r),n.appendChild(o),n},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 s=document.createElement("div");s.classList.add("magicfeedback-start-message-container");const n=document.createElement("div");n.classList.add("magicfeedback-start-message"),n.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())),s.appendChild(n),i&&s.appendChild(o),s}},341:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))},s=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 n=s(i(31)),o=s(i(147)),r=i(374),c={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,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getQuestions=function(e,t,i,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),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,n.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),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.3","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 s=t[a];if(void 0!==s)return s.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,i),n.exports}(607);return i.default})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicfeedback/native",
3
- "version": "1.2.8-beta.1",
3
+ "version": "1.2.8-beta.3",
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",