@magicfeedback/native 1.2.5 → 1.2.6-beta.1
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,a=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,a="Symbol"in e&&"iterator"in Symbol,s="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),n="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 a&&(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:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:n&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&s&&(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"))},s&&(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,a=h(this);if(a)return a;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),a=0;a<t.length;a++)i[a]=String.fromCharCode(t[a]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n&&(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)},a&&(p.prototype[Symbol.iterator]=p.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,a,s=(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,s||null==e._bodyInit||(s=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=(a=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(a)>-1?a:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(s)}function E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),a=i.shift().replace(/\+/g," "),s=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(a),decodeURIComponent(s))}})),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(a,n){var r=new v(e,i);if(r.signal&&r.signal.aborted)return n(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(":"),a=i.shift().trim();if(a){var s=i.join(":").trim();t.append(a,s)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var s="response"in o?o.response:o.responseText;a(new k(s,i))},o.onerror=function(){n(new TypeError("Network request failed"))},o.ontimeout=function(){n(new TypeError("Network request failed"))},o.onabort=function(){n(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&&s&&(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})}({})}(a),a.fetch.ponyfill=!0,delete a.fetch.polyfill;var s=a;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.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 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){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(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(r,o)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(954),n=i(712),r=i(5),o=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 r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,s,n,r=!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:r,id:c,feedback:n};try{const e=yield(0,o.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)=>{"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 a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(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(r,o)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=i(5),n=i(341),r=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.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,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,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,r.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,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 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.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const r=yield this.pushAnswers("MAGICSURVEY"!==(null===(s=this.formData)||void 0===s?void 0:s.identity));r&&(this.id=r,yield this.processNextQuestion(a,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:r,loading:!1,progress:this.progress,total:this.total,error:r?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;const a=e.querySelectorAll(".magicfeedback-input");a.forEach((e=>{const s=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(s){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="";a.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"===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];o.value.push(`${t}: ${c}%`)}else o.value.push(c);const a=t.findIndex((e=>e.key===o.key));-1!==a?t[a].value=[...t[a].value,...o.value]:t.push(o)}}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return a(this,void 0,void 0,(function*(){try{if(this.answer(),"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,o;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 i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,r.renderQuestions)([i],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);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,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},244:(e,t)=>{"use strict";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)=>{"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..."}},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..."}},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..."}},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..."}},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..."}}}},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 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",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 a=document.createElement("div");a.classList.add("magicfeedback-div"),console.log(t),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=>{a.appendChild(e)})),c.push(a)}else{const e=function(e,t,i,r){var o;const{id:c,title:d,type:l,ref:u,require:p,value:h,defaultValue:m,assets:f}=e;let g,b,y=document.createElement("div");switch(y.classList.add("magicfeedback-div"),l){case a.FEEDBACKAPPANSWERTYPE.TEXT:g=document.createElement("input"),g.type="text",g.placeholder="slim"===t?n(d,i):`${f.placeholder||s.placeholder.answer(i||"en")}`,b="magicfeedback-text";break;case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:g=document.createElement("textarea"),g.rows=3,g.maxLength=300,g.placeholder="slim"===t?n(d,i):s.placeholder.answer(i||"en"),b="magicfeedback-longtext";break;case a.FEEDBACKAPPANSWERTYPE.NUMBER:g=document.createElement("input"),g.type="number",g.placeholder="slim"===t?n(d,i):`${f.placeholder||s.placeholder.number(i||"en")}`,b="magicfeedback-number",h.length&&(h.sort(((e,t)=>Number(e)-Number(t))),g.max=h[h.length-1],g.min=h[0],g.value=h[0]);break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:g=document.createElement("div"),b="magicfeedback-"+("MULTIPLECHOICE"===l?"checkbox":"radio"),f.extraOption&&h.push(f.extraOptionText),h.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===l?"checkbox":"radio"}-container`);const a=document.createElement("label"),s=document.createElement("input");if(s.id=`rating-${u}-${t}`,s.type="MULTIPLECHOICE"===l?"checkbox":"radio",s.name=u,s.value="-",s.classList.add(b),s.classList.add("magicfeedback-input"),e===m&&(s.checked=!0),a.textContent=e,a.htmlFor=`rating-${u}-${t}`,f.extraOption&&e===f.extraOptionText&&s.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${u}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),i.appendChild(s),i.appendChild(a),g.appendChild(i),f.extraOption&&e===f.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder="Custom value",e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${u}`,e.name=`extra-option-${u}`,e.style.display="none",g.appendChild(e)}}));break;case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:g=document.createElement("div"),b="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(f.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"];default:return["Yes","No"]}}(i)).forEach(((t,i)=>{const a=document.createElement("label");a.classList.add("magicfeedback-boolean-option"),a.htmlFor=`rating-${u}-${i}`,a.style.cursor="pointer",a.style.border="1px solid #000",a.style.display="flex",a.style.justifyContent="center",a.style.alignItems="center",a.style.margin="auto",a.style.padding="0",a.style.width="45%",a.style.height="38px";const s=document.createElement("label");s.htmlFor=`rating-${u}-${i}`,s.textContent=t,s.style.margin="0",s.style.padding="0";const n=document.createElement("input");n.id=`rating-${u}-${i}`,n.type="radio",n.name=u,n.value=t,n.classList.add(b),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",n.addEventListener("change",(()=>{r&&r()})),a.appendChild(n),a.appendChild(s),e.appendChild(a)})),g.appendChild(e);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:g=document.createElement("div"),b="magicfeedback-rating";const v=document.createElement("div");v.classList.add("magicfeedback-rating-container");const E=f.max?Number(f.max):5,k=f.min?Number(f.min):1,C=document.createElement("div");if(C.classList.add("magicfeedback-rating-placeholder"),C.style.display="flex",C.style.justifyContent="space-between",C.style.width="90%",C.style.margin="auto",f.minPlaceholder){const e=document.createElement("span");e.textContent=f.minPlaceholder,e.classList.add("magicfeedback-rating-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",C.appendChild(e)}if(f.maxPlaceholder){const e=document.createElement("span");e.textContent=f.maxPlaceholder,e.classList.add("magicfeedback-rating-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",C.appendChild(e)}for(let e=k;e<=E;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${u}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${u}-${e}`,a.textContent=e.toString();const s=document.createElement("img");if(s.alt=`face-${u}-${e}`,s.className=`rating-image${e}`,0===k&&10===E)s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===k&&5===E)switch(e){case 1:s.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:s.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:s.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:s.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:s.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const t=Math.round(10/(E-k)*(e-k));s.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}const n=document.createElement("input");n.id=`rating-${u}-${e}`,n.type="radio",n.name=u,n.value=e.toString(),n.classList.add(b),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(s),i.appendChild(a),t.appendChild(i),v.appendChild(t)}if(f.extraOption&&f.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-option");const t=document.createElement("label");t.htmlFor=`rating-${u}-extra`,t.classList.add("magicfeedback-rating-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${u}-extra`,i.textContent=f.extraOptionText;const a=document.createElement("img");a.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",a.alt=`face-${u}-extra`,a.className="magicfeedback-rating-image-extra";const s=document.createElement("input");s.id=`rating-${u}-extra`,s.type="radio",s.name=u,s.value="-",s.classList.add(b),s.classList.add("magicfeedback-input"),t.appendChild(s),t.appendChild(a),t.appendChild(i),e.appendChild(t),v.appendChild(e)}g.appendChild(C),g.appendChild(v);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:g=document.createElement("div"),b="magicfeedback-rating-number";const x=document.createElement("div");x.classList.add("magicfeedback-rating-number-container");const w=f.max?Number(f.max):5,A=f.min?Number(f.min):1,L=document.createElement("div");if(L.classList.add("magicfeedback-rating-number-placeholder"),L.style.display="flex",L.style.justifyContent="space-between",L.style.width="90%",L.style.margin="auto",f.minPlaceholder){const e=document.createElement("span");e.textContent=f.minPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",L.appendChild(e)}if(f.maxPlaceholder){const e=document.createElement("span");e.textContent=f.maxPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",L.appendChild(e)}for(let e=A;e<=w;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${u}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${u}-${e}`,a.textContent=e.toString();const s=document.createElement("input");s.id=`rating-${u}-${e}`,s.type="radio",s.name=u,s.value=e.toString(),s.classList.add(b),s.classList.add("magicfeedback-input"),i.appendChild(s),i.appendChild(a),t.appendChild(i),x.appendChild(t)}if(f.extraOption&&f.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-number-option");const t=document.createElement("label");t.htmlFor=`rating-${u}-extra`,t.classList.add("magicfeedback-rating-number-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${u}-extra`,i.textContent=f.extraOptionText;const a=document.createElement("input");a.id=`rating-${u}-extra`,a.type="radio",a.name=u,a.value="-",a.classList.add(b),a.classList.add("magicfeedback-input"),t.appendChild(a),t.appendChild(i),e.appendChild(t),x.appendChild(e)}g.appendChild(L),g.appendChild(x);break;case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:g=document.createElement("div"),b="magicfeedback-rating-star";const S=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 r=document.createElement("label");r.htmlFor=`rating-${e}-${a}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",s.appendChild(r),i.appendChild(s)}return i}(u);g.appendChild(S);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:g=document.createElement("div"),b="magicfeedback-multiple-choice-image";const T=document.createElement("div");T.classList.add("magicfeedback-multiple-choice-image-container"),T.style.display="flex",T.style.flexDirection="row",T.style.flexWrap="wrap",T.style.justifyContent="center";const O=h.length;let I=1,P=1;switch(O){case 1:case 2:case 3:I=O,P=1;break;case 4:case 5:case 6:P=2,I=Math.ceil(O/2);break;default:P=3,I=Math.ceil(O/3)}const N=void 0!==f.addTitle&&f.addTitle;h.forEach((e=>{try{const{position:t,url:i,value:a}=JSON.parse(e),s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/I}% - 10px)`,s.style.height=`calc( ${100/P}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${u}-${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 r=document.createElement("label");r.textContent=a,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${u}-${t}`,o.type="radio",o.name=u,o.value=a,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.width="100%",c.style.height="100%",c.style.margin="auto",n.appendChild(o),n.appendChild(c),N&&n.appendChild(r),s.appendChild(n),T.appendChild(s)}catch(e){console.error(e)}})),g.appendChild(T);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:g=document.createElement("select"),b="magicfeedback-select";const _=document.createElement("option");_.value="",_.text="slim"===t?n(d,i):m||"Select an option",_.disabled=!0,_.selected=!0,g.appendChild(_),h.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,g.appendChild(t)}));break;case a.FEEDBACKAPPANSWERTYPE.DATE:g=document.createElement("input"),g.type="date",g.required=p,g.placeholder="slim"===t?n(d,i):`${f.placeholder||s.placeholder.date(i||"en")}`,b="magicfeedback-date";break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:g=document.createElement("input"),b="magicfeedback-consent",g.type="checkbox",g.id=`magicfeedback-${c}`,g.name=u,g.value="true",g.required=p,g.classList.add("magicfeedback-consent"),g.classList.add("magicfeedback-input");break;case a.FEEDBACKAPPANSWERTYPE.EMAIL:g=document.createElement("input"),g.type="email",g.required=p,g.placeholder="slim"===t?n(d,i):`${f.placeholder||"you@example.com"}`,b="magicfeedback-email";break;case a.FEEDBACKAPPANSWERTYPE.PASSWORD:g=document.createElement("input"),g.type="password",g.required=p,g.placeholder="slim"===t?n(d,i):`${f.placeholder||s.placeholder.password(i||"en")}`,b="magicfeedback-password";break;case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:g=document.createElement("div"),b="magicfeedback-multi-question-matrix";const $=document.createElement("div");$.classList.add("magicfeedback-multi-question-matrix-container");const D=document.createElement("table");D.classList.add("magicfeedback-multi-question-matrix-table");const M=document.createElement("thead");M.classList.add("magicfeedback-multi-question-matrix-header"),M.style.paddingBottom="15px";const R=document.createElement("tr");["",...h].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",R.appendChild(t)})),M.appendChild(R);const F=document.createElement("tbody");(null===(o=null==f?void 0:f.options)||void 0===o?void 0:o.length)>0&&f.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),h.forEach((i=>{const a=document.createElement("td"),s=document.createElement("input");s.type="checkbox",s.name=u,s.value=i,s.id=`matrix-${e}`,s.classList.add("magicfeedback-input"),s.style.padding="0 10px",a.appendChild(s),t.appendChild(a)})),F.appendChild(t)})),D.appendChild(M),D.appendChild(F),$.appendChild(D),g.appendChild($);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:g=document.createElement("div"),b="magicfeedback-priority-list";const B=document.createElement("div");B.classList.add("magicfeedback-priority-list-container");const q=document.createElement("ul");q.classList.add("magicfeedback-priority-list-list"),h.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-${u}`,a.name=u,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 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,n;const c=i.previousElementSibling;if(c){const d=Number(a.value.split(".")[0])-1;a.value=`${d}. ${e}`,s.textContent=`${d}. ${e}`,r.style.visibility=1===d?"hidden":"visible",o.style.visibility=d===h.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===h.length?"hidden":"visible"}q.insertBefore(i,c)}})),n.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===h.length-1?"hidden":"visible",o.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}`,r.style.visibility=1===d?"hidden":"visible",o.style.visibility=d===h.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===h.length?"hidden":"visible"}q.insertBefore(c,i)}})),n.appendChild(o),i.appendChild(n),q.appendChild(i)})),B.appendChild(q),g.appendChild(B);break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:g=document.createElement("div"),b="magicfeedback-point-system";const j=document.createElement("div");j.classList.add("magicfeedback-point-system-container");const U=document.createElement("ul");U.classList.add("magicfeedback-point-system-list"),U.style.padding="0";const K=100,W=K/h.length,Y=document.createElement("div");Y.classList.add("magicfeedback-point-system-total"),Y.textContent="0 / 100 %",Y.style.textAlign="right",Y.style.fontSize="0.8em",Y.style.color="#999",Y.style.marginTop="5px",h.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=u,s.id=`point-system-${e}`,s.type="number",s.min="0",s.max=`${K}`,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=U.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>K&&(s.value=`${W}%`,t-=Number(s.value)),Y.textContent=`${t} / 100 %`})),a.appendChild(s),a.appendChild(n),t.appendChild(a),U.appendChild(t)})),j.appendChild(U),j.appendChild(Y),g.appendChild(j);break;default:return y}g.id=`magicfeedback-${c}`,g.setAttribute("name",u),g.classList.add(b),void 0!==m&&(g.value=m),["RADIO","MULTIPLECHOICE"].includes(l)||(g.classList.add("magicfeedback-input"),g.required=p);const v=document.createElement("label");if(v.setAttribute("for",`magicfeedback-${c}`),v.textContent=n(d,i),v.classList.add("magicfeedback-label"),["CONSENT"].includes(l))y.classList.add("magicfeedback-consent-container"),y.appendChild(g),y.appendChild(v);else{if("slim"!==t&&(y.appendChild(v),void 0!==(null==f?void 0:f.general)&&""!==(null==f?void 0:f.general))){const e=document.createElement("img");e.src=f.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",y.appendChild(e)}if("LONGTEXT"===l){const e=document.createElement("div");if(e.classList.add("magicfeedback-counter"),e.textContent="0/300",e.style.textAlign="right",e.style.fontSize="0.8em",e.style.color="#999",e.style.marginTop="5px",g.addEventListener("input",(()=>{e.textContent=`${g.value.length}/300`})),y.appendChild(g),y.appendChild(e),f.extraOption&&f.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-skip-container"),e.classList.add("magicfeedback-checkbox-container"),e.style.display="flex",e.style.justifyContent="flex-start";const t=document.createElement("input");t.classList.add("magicfeedback-skip"),t.type="checkbox",t.id=`skip-${u}`,t.name=u,t.value="-",t.style.cursor="pointer";const i=document.createElement("label");i.htmlFor=`skip-${u}`,i.textContent=f.extraOptionText,i.style.fontSize="0.8em",i.style.color="#999",i.style.cursor="pointer",i.style.margin="0 5px",t.addEventListener("click",(()=>{g.value="-",r&&r()})),e.appendChild(t),e.appendChild(i),y.appendChild(e)}}else y.appendChild(g)}return y}(t,i,r,o);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 r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?s||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=a||"Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(o),n.appendChild(r),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 r=document.createElement("button");return r.id="magicfeedback-start-message-button",r.classList.add("magicfeedback-start-message-button"),r.textContent=a,r.addEventListener("click",(()=>t())),s.appendChild(n),i&&s.appendChild(r),s}},341:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(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(r,o)}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(98)),r=s(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,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+o.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+o.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+o.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+o.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)=>{"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.5","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(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).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,s=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,s="Symbol"in e&&"iterator"in Symbol,n="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),a="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 s&&(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:n&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:a&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&n&&(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"))},n&&(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,s=h(this);if(s)return s;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),s=0;s<t.length;s++)i[s]=String.fromCharCode(t[s]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},a&&(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)},s&&(p.prototype[Symbol.iterator]=p.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,s,n=(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,n||null==e._bodyInit||(n=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=(s=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(s)>-1?s:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),s=i.shift().replace(/\+/g," "),n=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(s),decodeURIComponent(n))}})),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(s,a){var r=new v(e,i);if(r.signal&&r.signal.aborted)return a(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(":"),s=i.shift().trim();if(s){var n=i.join(":").trim();t.append(s,n)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var n="response"in o?o.response:o.responseText;s(new k(n,i))},o.onerror=function(){a(new TypeError("Network request failed"))},o.ontimeout=function(){a(new TypeError("Network request failed"))},o.onabort=function(){a(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&&n&&(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})}({})}(s),s.fetch.ponyfill=!0,delete s.fetch.polyfill;var n=s;(t=n.fetch).default=n.fetch,t.fetch=n.fetch,t.Headers=n.Headers,t.Request=n.Request,t.Response=n.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 s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(519));let a=null;a||(a=(0,n.default)()),t.default=a},519:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,a){function r(e){try{c(s.next(e))}catch(e){a(e)}}function o(e){try{c(s.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(954),a=i(712),r=i(5),o=i(341),c=i(290);t.default=function(){const e=new a.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,n,a,r=!0,c,d){return s(this,void 0,void 0,(function*(){i||t.err("No appID provided"),n||t.err("No publicKey provided"),a||t.err("No feedback provided"),a.answers||a.profile||a.metrics||a.metadata||t.err("No feedback data provided");const s=e.get("url"),l={integration:i,publicKey:n,privateKey:d,completed:r,id:c,feedback:a};try{const e=yield(0,o.sendFeedback)(s,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,s){return i||t.err("No appID provided"),s||t.err("No publicKey provided"),new n.Form(e,i,s)}}}},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 s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,a){function r(e){try{c(s.next(e))}catch(e){a(e)}}function o(e){try{c(s.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const n=i(5),a=i(341),r=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new n.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.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 s(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const s=localStorage.getItem(`magicfeedback-${this.appId}`);if(s&&new Date(JSON.parse(s).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(s),(0,a.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,s;(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===(s=this.formData.style)||void 0===s?void 0:s.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm())}))):this.formData=yield(0,a.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 s=this.generateContainer();const n=document.createElement("form");n.classList.add("magicfeedback-form"),n.id="magicfeedback-"+this.appId;const a=document.createElement("div");if(a.classList.add("magicfeedback-questions"),a.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,a.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>a.appendChild(e))),n.appendChild(a),s.appendChild(n),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);n.appendChild(e)}n.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 n;return s(this,void 0,void 0,(function*(){const s=document.getElementById("magicfeedback-container-"+this.appId),a=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,answer:this.feedback.answers,progress:this.progress,total:this.total}));const r=yield this.pushAnswers("MAGICSURVEY"!==(null===(n=this.formData)||void 0===n?void 0:n.identity));r&&(this.id=r,yield this.processNextQuestion(s,a)),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 s=e.querySelectorAll(".magicfeedback-input");s.forEach((e=>{const n=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(n){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="";s.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"===n){if(!(0,a.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 s=t.findIndex((e=>e.key===o.key));-1!==s?t[s].value=[...t[s].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 s(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 s=this.config.get("url"),n={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,a.sendFeedback)(s,this.id?Object.assign(Object.assign({},n),{sessionId:this.id}):n,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return s(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,a.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,n,a,o;return s(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(n=this.questionInProcess)||void 0===n?void 0:n.followup){const e=yield this.callFollowUpQuestion(this.questionInProcess);if(e){this.questionInProcess=e;const i=(0,r.renderQuestions)([e],null===(a=this.formOptionsConfig)||void 0===a?void 0:a.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,s;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(s=t.FEEDBACKAPPANSWERTYPE||(t.FEEDBACKAPPANSWERTYPE={})).CONTACT="CONTACT",s.MULTIPLECHOISE_IMAGE="MULTIPLECHOISE_IMAGE",s.EMAIL="EMAIL",s.RATING_STAR="RATING_STAR",s.RADIO="RADIO",s.MULTIPLECHOICE="MULTIPLECHOICE",s.SELECT="SELECT",s.TEXT="TEXT",s.LONGTEXT="LONGTEXT",s.NUMBER="NUMBER",s.RATING_EMOJI="RATING_EMOJI",s.RATING_NUMBER="RATING_NUMBER",s.DATE="DATE",s.BOOLEAN="BOOLEAN",s.PASSWORD="PASSWORD",s.CONSENT="CONSENT",s.MULTI_QUESTION_MATRIX="MULTI_QUESTION_MATRIX",s.POINT_SYSTEM="POINT_SYSTEM",s.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 s=i(244),n=i(528);function a(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 s=document.createElement("div");s.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=>{s.appendChild(e)})),c.push(s)}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?a(u,i):null==b?void 0:b.placeholder,E=(k=l,new URLSearchParams(window.location.search).get(k));var k;switch(p){case s.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=v||n.placeholder.answer(i||"en"),d="magicfeedback-text";break;case s.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,c.maxLength=300,c.placeholder=v||n.placeholder.answer(i||"en"),d="magicfeedback-longtext";break;case s.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?a(u,i):n.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 s.FEEDBACKAPPANSWERTYPE.RADIO:case s.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),d="magicfeedback-"+("MULTIPLECHOICE"===p?"checkbox":"radio"),b.extraOption&&f.push(b.extraOptionText),f.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===p?"checkbox":"radio"}-container`);const s=document.createElement("label"),n=document.createElement("input");if(n.id=`rating-${h}-${t}`,n.type="MULTIPLECHOICE"===p?"checkbox":"radio",n.name=h,n.value=e,n.classList.add(d),n.classList.add("magicfeedback-input"),e!==g&&e!==E||(n.checked=!0),s.textContent=e,s.htmlFor=`rating-${h}-${t}`,b.extraOption&&e===b.extraOptionText&&n.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${h}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),i.appendChild(n),i.appendChild(s),c.appendChild(i),b.extraOption&&e===b.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder="Custom value",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 s.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),d="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.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(((t,i)=>{const s=document.createElement("label");s.classList.add("magicfeedback-boolean-option"),s.htmlFor=`rating-${h}-${i}`,s.style.cursor="pointer",s.style.border="1px solid #000",s.style.display="flex",s.style.justifyContent="center",s.style.alignItems="center",s.style.margin="auto",s.style.padding="0",s.style.width="45%",s.style.height="38px";const n=document.createElement("label");n.htmlFor=`rating-${h}-${i}`,n.textContent=t,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${h}-${i}`,a.type="radio",a.name=h,a.value=t,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()})),s.appendChild(a),s.appendChild(n),e.appendChild(s)})),c.appendChild(e);break;case s.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),d="magicfeedback-rating";const k=document.createElement("div");k.classList.add("magicfeedback-rating-container");const C=b.max?Number(b.max):5,x=b.min?Number(b.min):1,w=document.createElement("div");if(w.classList.add("magicfeedback-rating-placeholder"),w.style.display="flex",w.style.justifyContent="space-between",w.style.width="90%",w.style.margin="auto",b.minPlaceholder){const e=document.createElement("span");e.textContent=b.minPlaceholder,e.classList.add("magicfeedback-rating-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",w.appendChild(e)}if(b.maxPlaceholder){const e=document.createElement("span");e.textContent=b.maxPlaceholder,e.classList.add("magicfeedback-rating-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",w.appendChild(e)}for(let e=x;e<=C;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${h}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const s=document.createElement("label");s.htmlFor=`rating-${h}-${e}`,s.textContent=e.toString();const n=document.createElement("img");if(n.alt=`face-${h}-${e}`,n.className=`rating-image${e}`,0===x&&10===C)n.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===x&&5===C)switch(e){case 1:n.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:n.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:n.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:n.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:n.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const t=Math.round(10/(C-x)*(e-x));n.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}const a=document.createElement("input");a.id=`rating-${h}-${e}`,a.type="radio",a.name=h,a.value=e.toString(),a.classList.add(d),a.classList.add("magicfeedback-input"),i.appendChild(a),i.appendChild(n),i.appendChild(s),t.appendChild(i),k.appendChild(t)}if(b.extraOption&&b.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-option");const t=document.createElement("label");t.htmlFor=`rating-${h}-extra`,t.classList.add("magicfeedback-rating-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${h}-extra`,i.textContent=b.extraOptionText;const s=document.createElement("img");s.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",s.alt=`face-${h}-extra`,s.className="magicfeedback-rating-image-extra";const n=document.createElement("input");n.id=`rating-${h}-extra`,n.type="radio",n.name=h,n.value="-",n.classList.add(d),n.classList.add("magicfeedback-input"),t.appendChild(n),t.appendChild(s),t.appendChild(i),e.appendChild(t),k.appendChild(e)}c.appendChild(w),c.appendChild(k);break;case s.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),d="magicfeedback-rating-number";const A=document.createElement("div");A.classList.add("magicfeedback-rating-number-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-number-placeholder"),T.style.display="flex",T.style.justifyContent="space-between",T.style.width="90%",T.style.margin="auto",b.minPlaceholder){const e=document.createElement("span");e.textContent=b.minPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",T.appendChild(e)}if(b.maxPlaceholder){const e=document.createElement("span");e.textContent=b.maxPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",T.appendChild(e)}for(let e=S;e<=L;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${h}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const s=document.createElement("label");s.htmlFor=`rating-${h}-${e}`,s.textContent=e.toString();const n=document.createElement("input");n.id=`rating-${h}-${e}`,n.type="radio",n.name=h,n.value=e.toString(),n.classList.add(d),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(s),t.appendChild(i),A.appendChild(t)}if(b.extraOption&&b.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-number-option");const t=document.createElement("label");t.htmlFor=`rating-${h}-extra`,t.classList.add("magicfeedback-rating-number-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${h}-extra`,i.textContent=b.extraOptionText;const s=document.createElement("input");s.id=`rating-${h}-extra`,s.type="radio",s.name=h,s.value="-",s.classList.add(d),s.classList.add("magicfeedback-input"),t.appendChild(s),t.appendChild(i),e.appendChild(t),A.appendChild(e)}c.appendChild(T),c.appendChild(A);break;case s.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),d="magicfeedback-rating-star";const O=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let s=1;s<=5;s++){const n=document.createElement("label");n.classList.add("magicfeedback-rating-star-option");const a=document.createElement("input");a.id=`rating-${e}-${s}`,a.type="radio",a.name=e,a.value=s.toString(),a.style.position="absolute",a.style.opacity="0",a.style.width="0",a.style.height="0",a.classList.add("magicfeedback-input"),a.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(a.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),n.appendChild(a);const r=document.createElement("label");r.htmlFor=`rating-${e}-${s}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",n.appendChild(r),i.appendChild(n)}return i}(h);c.appendChild(O);break;case s.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),d="magicfeedback-multiple-choice-image";const I=document.createElement("div");I.classList.add("magicfeedback-multiple-choice-image-container"),I.style.display="flex",I.style.flexDirection="row",I.style.flexWrap="wrap",I.style.justifyContent="center";const P=f.length;let N=1,_=1;switch(P){case 1:case 2:case 3:N=P,_=1;break;case 4:case 5:case 6:_=2,N=Math.ceil(P/_);break;case 7:case 8:case 9:_=3,N=Math.ceil(P/_);break;default:_=4,N=Math.ceil(P/_)}const D=void 0!==(null==b?void 0:b.addTitle)&&b.addTitle,$=void 0!==(null==b?void 0:b.multiOption)&&b.multiOption;void 0!==(null==b?void 0:b.randomPosition)&&b.randomPosition&&(f=f.sort((()=>Math.random()-.5))),f.forEach((e=>{try{const{position:t,url:i,value:s}=JSON.parse(e),n=document.createElement("label");n.classList.add("magicfeedback-multiple-choice-image-option"),n.style.width=`calc( ${100/N}% - 10px)`,n.style.height=`calc( ${100/_}% - 10px)`,n.style.margin="5px";const a=document.createElement("label");a.htmlFor=`rating-${h}-${t}`,a.classList.add("magicfeedback-image-option-label-container"),a.style.display="flex",a.style.flexDirection="column",a.addEventListener("mouseover",(()=>{a.style.border="2px solid #000"})),a.addEventListener("mouseout",(()=>{a.style.border="none"})),a.addEventListener("click",(()=>{a.style.border="2px solid #000"}));const r=document.createElement("label");r.textContent=s,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${h}-${t}`,o.type=$?"checkbox":"radio",o.name=h,o.value=s,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",a.appendChild(o),a.appendChild(c),D&&a.appendChild(r),n.appendChild(a),I.appendChild(n)}catch(e){console.error(e)}})),c.appendChild(I);break;case s.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),d="magicfeedback-select";const M=document.createElement("option");M.value="",M.text="slim"===t?a(u,i):g||"Select an option",M.disabled=!0,M.selected=!0,c.appendChild(M),f.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)}));break;case s.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=m,c.placeholder=v||n.placeholder.date(i||"en"),d="magicfeedback-date";break;case s.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 s.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=m,c.placeholder=v||"you@example.com",d="magicfeedback-email";break;case s.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=m,c.placeholder=v||n.placeholder.password(i||"en"),d="magicfeedback-password";break;case s.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),d="magicfeedback-multi-question-matrix";const R=document.createElement("div");R.classList.add("magicfeedback-multi-question-matrix-container");const F=document.createElement("table");F.classList.add("magicfeedback-multi-question-matrix-table");const B=document.createElement("thead");B.classList.add("magicfeedback-multi-question-matrix-header"),B.style.paddingBottom="15px";const q=document.createElement("tr");["",...f].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",q.appendChild(t)})),B.appendChild(q);const j=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 s=document.createElement("label");s.classList.add("magicfeedback-multi-question-matrix-label"),s.style.paddingRight="15px",s.textContent=e,i.appendChild(s),t.appendChild(i),f.forEach((i=>{const s=document.createElement("td"),n=document.createElement("input");n.type="checkbox",n.name=h,n.value=i,n.id=`matrix-${e}`,n.classList.add("magicfeedback-input"),n.style.padding="0 10px",s.appendChild(n),t.appendChild(s)})),j.appendChild(t)})),F.appendChild(B),F.appendChild(j),R.appendChild(F),c.appendChild(R);break;case s.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),d="magicfeedback-priority-list";const U=document.createElement("div");U.classList.add("magicfeedback-priority-list-container");const K=document.createElement("ul");K.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 s=document.createElement("input");s.classList.add("magicfeedback-input-magicfeedback-priority-list"),s.classList.add("magicfeedback-input"),s.type="hidden",s.id=`priority-list-${h}`,s.name=h,s.value=`${t+1}. ${e}`,i.appendChild(s);const n=document.createElement("label");n.classList.add("magicfeedback-priority-list-item-label"),n.textContent=`${t+1}. ${e}`,i.appendChild(n);const a=document.createElement("div");a.style.display="flex",a.style.alignItems="center",a.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,a;const c=i.previousElementSibling;if(c){const d=Number(s.value.split(".")[0])-1;s.value=`${d}. ${e}`,n.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===(a=u.textContent)||void 0===a?void 0:a.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===f.length?"hidden":"visible"}K.insertBefore(i,c)}})),a.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,a;const c=i.nextElementSibling;if(c){const d=Number(s.value.split(".")[0])+1;s.value=d.toString(),n.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===(a=u.textContent)||void 0===a?void 0:a.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===f.length?"hidden":"visible"}K.insertBefore(c,i)}})),a.appendChild(o),i.appendChild(a),K.appendChild(i)})),U.appendChild(K),c.appendChild(U);break;case s.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),d="magicfeedback-point-system";const Q=document.createElement("div");Q.classList.add("magicfeedback-point-system-container");const W=document.createElement("ul");W.classList.add("magicfeedback-point-system-list"),W.style.padding="0";const Y=100,G=Y/f.length,H=document.createElement("div");H.classList.add("magicfeedback-point-system-total"),H.textContent="0 / 100 %",H.style.textAlign="right",H.style.fontSize="0.8em",H.style.color="#999",H.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 s=document.createElement("span");s.classList.add("magicfeedback-point-system-input-container");const n=document.createElement("input");n.name=h,n.id=`point-system-${e}`,n.type="number",n.min="0",n.max=`${Y}`,n.value="0",n.classList.add("magicfeedback-input"),n.style.width="40px",n.style.border="0",n.style.textAlign="center",n.style.margin="0 5px";const a=document.createElement("span");a.textContent="%",a.style.color="#000",n.addEventListener("input",(()=>{const e=W.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>Y&&(n.value=`${G}%`,t-=Number(n.value)),H.textContent=`${t} / 100 %`})),s.appendChild(n),s.appendChild(a),t.appendChild(s),W.appendChild(t)})),Q.appendChild(W),Q.appendChild(H),c.appendChild(Q);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 C=document.createElement("label");if(C.setAttribute("for",`magicfeedback-${l}`),C.textContent=a(u,i),C.classList.add("magicfeedback-label"),["CONSENT"].includes(p))y.classList.add("magicfeedback-consent-container"),y.appendChild(c),y.appendChild(C);else{if("slim"!==t&&(y.appendChild(C),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const e=document.createElement("img");e.src=b.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",y.appendChild(e)}if("LONGTEXT"===p){const e=document.createElement("div");if(e.classList.add("magicfeedback-counter"),e.textContent="0/300",e.style.textAlign="right",e.style.fontSize="0.8em",e.style.color="#999",e.style.marginTop="5px",c.addEventListener("input",(()=>{e.textContent=`${c.value.length}/300`})),y.appendChild(c),y.appendChild(e),b.extraOption&&b.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-skip-container"),e.classList.add("magicfeedback-checkbox-container"),e.style.display="flex",e.style.justifyContent="flex-start";const t=document.createElement("input");t.classList.add("magicfeedback-skip"),t.type="checkbox",t.id=`skip-${h}`,t.name=h,t.value="-",t.style.cursor="pointer";const i=document.createElement("label");i.htmlFor=`skip-${h}`,i.textContent=b.extraOptionText,i.style.fontSize="0.8em",i.style.color="#999",i.style.cursor="pointer",i.style.margin="0 5px",t.addEventListener("click",(()=>{c.value="-",r&&r()})),e.appendChild(t),e.appendChild(i),y.appendChild(e)}}else y.appendChild(c)}return y}(t,i,r,o);c.push(e)}})),c},t.renderActions=function(e="",t,i="Submit",s="Back",n="Next"){const a=document.createElement("div");a.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?n||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=s||"Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&a.appendChild(o),a.appendChild(r),a},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,s="Go!"){const n=document.createElement("div");n.classList.add("magicfeedback-start-message-container");const a=document.createElement("div");a.classList.add("magicfeedback-start-message"),a.innerHTML=e;const r=document.createElement("button");return r.id="magicfeedback-start-message-button",r.classList.add("magicfeedback-start-message-button"),r.textContent=s,r.addEventListener("click",(()=>t())),n.appendChild(a),i&&n.appendChild(r),n}},341:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,a){function r(e){try{c(s.next(e))}catch(e){a(e)}}function o(e){try{c(s.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const a=n(i(98)),r=n(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,n){return s(this,void 0,void 0,(function*(){try{const s=yield(0,a.default)(e+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return n.log(`Received form for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),null}}))},t.getQuestions=function(e,t,i,n){return s(this,void 0,void 0,(function*(){try{const s=yield(0,a.default)(e+o.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return n.log(`Received questions for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),[]}}))},t.sendFeedback=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,a.default)(e+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield s.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,a.default)(e+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield s.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,s.status,s.statusText),new Error(s.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.6-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(s){var n=t[s];if(void 0!==n)return n.exports;var a=t[s]={exports:{}};return e[s].call(a.exports,a,a.exports,i),a.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.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.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,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,error:o?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;const a=e.querySelectorAll(".magicfeedback-input");a.forEach((e=>{const 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}pushAnswers(e=!1){var t,i;return a(this,void 0,void 0,(function*(){try{if(this.answer(),"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 i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,o.renderQuestions)([i],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:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);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,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];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..."}},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..."}},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..."}},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..."}},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..."}}}},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"),console.log(t),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;const{id:c,title:d,type:l,ref:u,require:p,value:m,defaultValue:h,assets:f}=e;let g,b,v=document.createElement("div");switch(v.classList.add("magicfeedback-div"),l){case a.FEEDBACKAPPANSWERTYPE.TEXT:g=document.createElement("input"),g.type="text",g.placeholder="slim"===t?n(d,i):`${f.placeholder||s.placeholder.answer(i||"en")}`,b="magicfeedback-text";break;case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:g=document.createElement("textarea"),g.rows=3,g.maxLength=300,g.placeholder="slim"===t?n(d,i):s.placeholder.answer(i||"en"),b="magicfeedback-longtext";break;case a.FEEDBACKAPPANSWERTYPE.NUMBER:g=document.createElement("input"),g.type="number",g.placeholder="slim"===t?n(d,i):`${f.placeholder||s.placeholder.number(i||"en")}`,b="magicfeedback-number",m.length&&(m.sort(((e,t)=>Number(e)-Number(t))),g.max=m[m.length-1],g.min=m[0],g.value=m[0]);break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:g=document.createElement("div"),b="magicfeedback-"+("MULTIPLECHOICE"===l?"checkbox":"radio"),f.extraOption&&m.push(f.extraOptionText),m.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===l?"checkbox":"radio"}-container`);const a=document.createElement("label"),s=document.createElement("input");if(s.id=`rating-${u}-${t}`,s.type="MULTIPLECHOICE"===l?"checkbox":"radio",s.name=u,s.value="-",s.classList.add(b),s.classList.add("magicfeedback-input"),e===h&&(s.checked=!0),a.textContent=e,a.htmlFor=`rating-${u}-${t}`,f.extraOption&&e===f.extraOptionText&&s.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${u}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),i.appendChild(s),i.appendChild(a),g.appendChild(i),f.extraOption&&e===f.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder="Custom value",e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${u}`,e.name=`extra-option-${u}`,e.style.display="none",g.appendChild(e)}}));break;case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:g=document.createElement("div"),b="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(f.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"];default:return["Yes","No"]}}(i)).forEach(((t,i)=>{const a=document.createElement("label");a.classList.add("magicfeedback-boolean-option"),a.htmlFor=`rating-${u}-${i}`,a.style.cursor="pointer",a.style.border="1px solid #000",a.style.display="flex",a.style.justifyContent="center",a.style.alignItems="center",a.style.margin="auto",a.style.padding="0",a.style.width="45%",a.style.height="38px";const s=document.createElement("label");s.htmlFor=`rating-${u}-${i}`,s.textContent=t,s.style.margin="0",s.style.padding="0";const n=document.createElement("input");n.id=`rating-${u}-${i}`,n.type="radio",n.name=u,n.value=t,n.classList.add(b),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",n.addEventListener("change",(()=>{o&&o()})),a.appendChild(n),a.appendChild(s),e.appendChild(a)})),g.appendChild(e);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:g=document.createElement("div"),b="magicfeedback-rating";const y=document.createElement("div");y.classList.add("magicfeedback-rating-container");const E=f.max?Number(f.max):5,k=f.min?Number(f.min):1,C=document.createElement("div");if(C.classList.add("magicfeedback-rating-placeholder"),C.style.display="flex",C.style.justifyContent="space-between",C.style.width="90%",C.style.margin="auto",f.minPlaceholder){const e=document.createElement("span");e.textContent=f.minPlaceholder,e.classList.add("magicfeedback-rating-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",C.appendChild(e)}if(f.maxPlaceholder){const e=document.createElement("span");e.textContent=f.maxPlaceholder,e.classList.add("magicfeedback-rating-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",C.appendChild(e)}for(let e=k;e<=E;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${u}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${u}-${e}`,a.textContent=e.toString();const s=document.createElement("img");if(s.alt=`face-${u}-${e}`,s.className=`rating-image${e}`,0===k&&10===E)s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===k&&5===E)switch(e){case 1:s.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:s.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:s.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:s.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:s.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const t=Math.round(10/(E-k)*(e-k));s.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}const n=document.createElement("input");n.id=`rating-${u}-${e}`,n.type="radio",n.name=u,n.value=e.toString(),n.classList.add(b),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(s),i.appendChild(a),t.appendChild(i),y.appendChild(t)}if(f.extraOption&&f.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-option");const t=document.createElement("label");t.htmlFor=`rating-${u}-extra`,t.classList.add("magicfeedback-rating-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${u}-extra`,i.textContent=f.extraOptionText;const a=document.createElement("img");a.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",a.alt=`face-${u}-extra`,a.className="magicfeedback-rating-image-extra";const s=document.createElement("input");s.id=`rating-${u}-extra`,s.type="radio",s.name=u,s.value="-",s.classList.add(b),s.classList.add("magicfeedback-input"),t.appendChild(s),t.appendChild(a),t.appendChild(i),e.appendChild(t),y.appendChild(e)}g.appendChild(C),g.appendChild(y);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:g=document.createElement("div"),b="magicfeedback-rating-number";const x=document.createElement("div");x.classList.add("magicfeedback-rating-number-container");const w=f.max?Number(f.max):5,L=f.min?Number(f.min):1,S=document.createElement("div");if(S.classList.add("magicfeedback-rating-number-placeholder"),S.style.display="flex",S.style.justifyContent="space-between",S.style.width="90%",S.style.margin="auto",f.minPlaceholder){const e=document.createElement("span");e.textContent=f.minPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",S.appendChild(e)}if(f.maxPlaceholder){const e=document.createElement("span");e.textContent=f.maxPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",S.appendChild(e)}for(let e=L;e<=w;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${u}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${u}-${e}`,a.textContent=e.toString();const s=document.createElement("input");s.id=`rating-${u}-${e}`,s.type="radio",s.name=u,s.value=e.toString(),s.classList.add(b),s.classList.add("magicfeedback-input"),i.appendChild(s),i.appendChild(a),t.appendChild(i),x.appendChild(t)}if(f.extraOption&&f.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-number-option");const t=document.createElement("label");t.htmlFor=`rating-${u}-extra`,t.classList.add("magicfeedback-rating-number-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${u}-extra`,i.textContent=f.extraOptionText;const a=document.createElement("input");a.id=`rating-${u}-extra`,a.type="radio",a.name=u,a.value="-",a.classList.add(b),a.classList.add("magicfeedback-input"),t.appendChild(a),t.appendChild(i),e.appendChild(t),x.appendChild(e)}g.appendChild(S),g.appendChild(x);break;case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:g=document.createElement("div"),b="magicfeedback-rating-star";const T=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}(u);g.appendChild(T);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:g=document.createElement("div"),b="magicfeedback-multiple-choice-image";const A=document.createElement("div");A.classList.add("magicfeedback-multiple-choice-image-container"),A.style.display="flex",A.style.flexDirection="row",A.style.flexWrap="wrap",A.style.justifyContent="center";const I=m.length;let O=1,N=1;switch(I){case 1:case 2:case 3:O=I,N=1;break;case 4:case 5:case 6:N=2,O=Math.ceil(I/2);break;default:N=3,O=Math.ceil(I/3)}const P=void 0!==f.addTitle&&f.addTitle;m.forEach((e=>{try{const{position:t,url:i,value:a}=JSON.parse(e),s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/O}% - 10px)`,s.style.height=`calc( ${100/N}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${u}-${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-${u}-${t}`,r.type="radio",r.name=u,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.width="100%",c.style.height="100%",c.style.margin="auto",n.appendChild(r),n.appendChild(c),P&&n.appendChild(o),s.appendChild(n),A.appendChild(s)}catch(e){console.error(e)}})),g.appendChild(A);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:g=document.createElement("select"),b="magicfeedback-select";const $=document.createElement("option");$.value="",$.text="slim"===t?n(d,i):h||"Select an option",$.disabled=!0,$.selected=!0,g.appendChild($),m.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,g.appendChild(t)}));break;case a.FEEDBACKAPPANSWERTYPE.DATE:g=document.createElement("input"),g.type="date",g.required=p,g.placeholder="slim"===t?n(d,i):`${f.placeholder||s.placeholder.date(i||"en")}`,b="magicfeedback-date";break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:g=document.createElement("input"),b="magicfeedback-consent",g.type="checkbox",g.id=`magicfeedback-${c}`,g.name=u,g.value="true",g.required=p,g.classList.add("magicfeedback-consent"),g.classList.add("magicfeedback-input");break;case a.FEEDBACKAPPANSWERTYPE.EMAIL:g=document.createElement("input"),g.type="email",g.required=p,g.placeholder="slim"===t?n(d,i):`${f.placeholder||"you@example.com"}`,b="magicfeedback-email";break;case a.FEEDBACKAPPANSWERTYPE.PASSWORD:g=document.createElement("input"),g.type="password",g.required=p,g.placeholder="slim"===t?n(d,i):`${f.placeholder||s.placeholder.password(i||"en")}`,b="magicfeedback-password";break;case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:g=document.createElement("div"),b="magicfeedback-multi-question-matrix";const M=document.createElement("div");M.classList.add("magicfeedback-multi-question-matrix-container");const D=document.createElement("table");D.classList.add("magicfeedback-multi-question-matrix-table");const _=document.createElement("thead");_.classList.add("magicfeedback-multi-question-matrix-header"),_.style.paddingBottom="15px";const F=document.createElement("tr");["",...m].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",F.appendChild(t)})),_.appendChild(F);const q=document.createElement("tbody");(null===(r=null==f?void 0:f.options)||void 0===r?void 0:r.length)>0&&f.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),m.forEach((i=>{const a=document.createElement("td"),s=document.createElement("input");s.type="checkbox",s.name=u,s.value=i,s.id=`matrix-${e}`,s.classList.add("magicfeedback-input"),s.style.padding="0 10px",a.appendChild(s),t.appendChild(a)})),q.appendChild(t)})),D.appendChild(_),D.appendChild(q),M.appendChild(D),g.appendChild(M);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:g=document.createElement("div"),b="magicfeedback-priority-list";const R=document.createElement("div");R.classList.add("magicfeedback-priority-list-container");const j=document.createElement("ul");j.classList.add("magicfeedback-priority-list-list"),m.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-${u}`,a.name=u,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===m.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===(n=u.textContent)||void 0===n?void 0:n.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===m.length?"hidden":"visible"}j.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===m.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===m.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===(n=u.textContent)||void 0===n?void 0:n.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===m.length?"hidden":"visible"}j.insertBefore(c,i)}})),n.appendChild(r),i.appendChild(n),j.appendChild(i)})),R.appendChild(j),g.appendChild(R);break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:g=document.createElement("div"),b="magicfeedback-point-system";const B=document.createElement("div");B.classList.add("magicfeedback-point-system-container");const U=document.createElement("ul");U.classList.add("magicfeedback-point-system-list"),U.style.padding="0";const K=100,W=K/m.length,Y=document.createElement("div");Y.classList.add("magicfeedback-point-system-total"),Y.textContent="0 / 100 %",Y.style.textAlign="right",Y.style.fontSize="0.8em",Y.style.color="#999",Y.style.marginTop="5px",m.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=u,s.id=`point-system-${e}`,s.type="number",s.min="0",s.max=`${K}`,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=U.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>K&&(s.value=`${W}%`,t-=Number(s.value)),Y.textContent=`${t} / 100 %`})),a.appendChild(s),a.appendChild(n),t.appendChild(a),U.appendChild(t)})),B.appendChild(U),B.appendChild(Y),g.appendChild(B);break;default:return v}g.id=`magicfeedback-${c}`,g.setAttribute("name",u),g.classList.add(b),void 0!==h&&(g.value=h),["RADIO","MULTIPLECHOICE"].includes(l)||(g.classList.add("magicfeedback-input"),g.required=p);const y=document.createElement("label");if(y.setAttribute("for",`magicfeedback-${c}`),y.textContent=n(d,i),y.classList.add("magicfeedback-label"),["CONSENT"].includes(l))v.classList.add("magicfeedback-consent-container"),v.appendChild(g),v.appendChild(y);else{if("slim"!==t&&(v.appendChild(y),void 0!==(null==f?void 0:f.general)&&""!==(null==f?void 0:f.general))){const e=document.createElement("img");e.src=f.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",v.appendChild(e)}if("LONGTEXT"===l){const e=document.createElement("div");if(e.classList.add("magicfeedback-counter"),e.textContent="0/300",e.style.textAlign="right",e.style.fontSize="0.8em",e.style.color="#999",e.style.marginTop="5px",g.addEventListener("input",(()=>{e.textContent=`${g.value.length}/300`})),v.appendChild(g),v.appendChild(e),f.extraOption&&f.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-skip-container"),e.classList.add("magicfeedback-checkbox-container"),e.style.display="flex",e.style.justifyContent="flex-start";const t=document.createElement("input");t.classList.add("magicfeedback-skip"),t.type="checkbox",t.id=`skip-${u}`,t.name=u,t.value="-",t.style.cursor="pointer";const i=document.createElement("label");i.htmlFor=`skip-${u}`,i.textContent=f.extraOptionText,i.style.fontSize="0.8em",i.style.color="#999",i.style.cursor="pointer",i.style.margin="0 5px",t.addEventListener("click",(()=>{g.value="-",o&&o()})),e.appendChild(t),e.appendChild(i),v.appendChild(e)}}else v.appendChild(g)}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.5","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=(k=l,new URLSearchParams(window.location.search).get(k));var k;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,c.maxLength=300,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 i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===p?"checkbox":"radio"}-container`);const a=document.createElement("label"),s=document.createElement("input");if(s.id=`rating-${m}-${t}`,s.type="MULTIPLECHOICE"===p?"checkbox":"radio",s.name=m,s.value=e,s.classList.add(d),s.classList.add("magicfeedback-input"),e!==g&&e!==E||(s.checked=!0),a.textContent=e,a.htmlFor=`rating-${m}-${t}`,b.extraOption&&e===b.extraOptionText&&s.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${m}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),i.appendChild(s),i.appendChild(a),c.appendChild(i),b.extraOption&&e===b.extraOptionText){const e=document.createElement("input");e.type="text",e.placeholder="Custom value",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 e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.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(((t,i)=>{const a=document.createElement("label");a.classList.add("magicfeedback-boolean-option"),a.htmlFor=`rating-${m}-${i}`,a.style.cursor="pointer",a.style.border="1px solid #000",a.style.display="flex",a.style.justifyContent="center",a.style.alignItems="center",a.style.margin="auto",a.style.padding="0",a.style.width="45%",a.style.height="38px";const s=document.createElement("label");s.htmlFor=`rating-${m}-${i}`,s.textContent=t,s.style.margin="0",s.style.padding="0";const n=document.createElement("input");n.id=`rating-${m}-${i}`,n.type="radio",n.name=m,n.value=t,n.classList.add(d),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",n.addEventListener("change",(()=>{o&&o()})),a.appendChild(n),a.appendChild(s),e.appendChild(a)})),c.appendChild(e);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),d="magicfeedback-rating";const k=document.createElement("div");k.classList.add("magicfeedback-rating-container");const C=b.max?Number(b.max):5,x=b.min?Number(b.min):1,w=document.createElement("div");if(w.classList.add("magicfeedback-rating-placeholder"),w.style.display="flex",w.style.justifyContent="space-between",w.style.width="90%",w.style.margin="auto",b.minPlaceholder){const e=document.createElement("span");e.textContent=b.minPlaceholder,e.classList.add("magicfeedback-rating-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",w.appendChild(e)}if(b.maxPlaceholder){const e=document.createElement("span");e.textContent=b.maxPlaceholder,e.classList.add("magicfeedback-rating-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",w.appendChild(e)}for(let e=x;e<=C;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${m}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${m}-${e}`,a.textContent=e.toString();const s=document.createElement("img");if(s.alt=`face-${m}-${e}`,s.className=`rating-image${e}`,0===x&&10===C)s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===x&&5===C)switch(e){case 1:s.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:s.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:s.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:s.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:s.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else{const t=Math.round(10/(C-x)*(e-x));s.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}const n=document.createElement("input");n.id=`rating-${m}-${e}`,n.type="radio",n.name=m,n.value=e.toString(),n.classList.add(d),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(s),i.appendChild(a),t.appendChild(i),k.appendChild(t)}if(b.extraOption&&b.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-option");const t=document.createElement("label");t.htmlFor=`rating-${m}-extra`,t.classList.add("magicfeedback-rating-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${m}-extra`,i.textContent=b.extraOptionText;const a=document.createElement("img");a.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",a.alt=`face-${m}-extra`,a.className="magicfeedback-rating-image-extra";const s=document.createElement("input");s.id=`rating-${m}-extra`,s.type="radio",s.name=m,s.value="-",s.classList.add(d),s.classList.add("magicfeedback-input"),t.appendChild(s),t.appendChild(a),t.appendChild(i),e.appendChild(t),k.appendChild(e)}c.appendChild(w),c.appendChild(k);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),d="magicfeedback-rating-number";const L=document.createElement("div");L.classList.add("magicfeedback-rating-number-container");const S=b.max?Number(b.max):5,T=b.min?Number(b.min):1,A=document.createElement("div");if(A.classList.add("magicfeedback-rating-number-placeholder"),A.style.display="flex",A.style.justifyContent="space-between",A.style.width="90%",A.style.margin="auto",b.minPlaceholder){const e=document.createElement("span");e.textContent=b.minPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-min"),e.style.fontStyle="italic",e.style.fontSize="0.8em",A.appendChild(e)}if(b.maxPlaceholder){const e=document.createElement("span");e.textContent=b.maxPlaceholder,e.classList.add("magicfeedback-rating-number-placeholder-max"),e.style.fontStyle="italic",e.style.fontSize="0.8em",A.appendChild(e)}for(let e=T;e<=S;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${m}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${m}-${e}`,a.textContent=e.toString();const s=document.createElement("input");s.id=`rating-${m}-${e}`,s.type="radio",s.name=m,s.value=e.toString(),s.classList.add(d),s.classList.add("magicfeedback-input"),i.appendChild(s),i.appendChild(a),t.appendChild(i),L.appendChild(t)}if(b.extraOption&&b.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-rating-number-option");const t=document.createElement("label");t.htmlFor=`rating-${m}-extra`,t.classList.add("magicfeedback-rating-number-option-label-container");const i=document.createElement("label");i.htmlFor=`rating-${m}-extra`,i.textContent=b.extraOptionText;const a=document.createElement("input");a.id=`rating-${m}-extra`,a.type="radio",a.name=m,a.value="-",a.classList.add(d),a.classList.add("magicfeedback-input"),t.appendChild(a),t.appendChild(i),e.appendChild(t),L.appendChild(e)}c.appendChild(A),c.appendChild(L);break;case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),d="magicfeedback-rating-star";const I=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(I);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),d="magicfeedback-multiple-choice-image";const O=document.createElement("div");O.classList.add("magicfeedback-multiple-choice-image-container"),O.style.display="flex",O.style.flexDirection="row",O.style.flexWrap="wrap",O.style.justifyContent="center";const N=f.length;let P=1,$=1;switch(N){case 1:case 2:case 3:P=N,$=1;break;case 4:case 5:case 6:$=2,P=Math.ceil(N/$);break;case 7:case 8:case 9:$=3,P=Math.ceil(N/$);break;default:$=4,P=Math.ceil(N/$)}const M=void 0!==(null==b?void 0:b.addTitle)&&b.addTitle,D=void 0!==(null==b?void 0:b.multiOption)&&b.multiOption;void 0!==(null==b?void 0:b.randomPosition)&&b.randomPosition&&(f=f.sort((()=>Math.random()-.5))),f.forEach((e=>{try{const{position:t,url:i,value:a}=JSON.parse(e),s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/P}% - 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=D?"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),M&&n.appendChild(o),s.appendChild(n),O.appendChild(s)}catch(e){console.error(e)}})),c.appendChild(O);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),d="magicfeedback-select";const _=document.createElement("option");_.value="",_.text="slim"===t?n(u,i):g||"Select an option",_.disabled=!0,_.selected=!0,c.appendChild(_),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 F=document.createElement("div");F.classList.add("magicfeedback-multi-question-matrix-container");const q=document.createElement("table");q.classList.add("magicfeedback-multi-question-matrix-table");const R=document.createElement("thead");R.classList.add("magicfeedback-multi-question-matrix-header"),R.style.paddingBottom="15px";const j=document.createElement("tr");["",...f].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",j.appendChild(t)})),R.appendChild(j);const B=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)})),B.appendChild(t)})),q.appendChild(R),q.appendChild(B),F.appendChild(q),c.appendChild(F);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),d="magicfeedback-priority-list";const U=document.createElement("div");U.classList.add("magicfeedback-priority-list-container");const K=document.createElement("ul");K.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"}K.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"}K.insertBefore(c,i)}})),n.appendChild(r),i.appendChild(n),K.appendChild(i)})),U.appendChild(K),c.appendChild(U);break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),d="magicfeedback-point-system";const Q=document.createElement("div");Q.classList.add("magicfeedback-point-system-container");const W=document.createElement("ul");W.classList.add("magicfeedback-point-system-list"),W.style.padding="0";const Y=100,G=Y/f.length,H=document.createElement("div");H.classList.add("magicfeedback-point-system-total"),H.textContent="0 / 100 %",H.style.textAlign="right",H.style.fontSize="0.8em",H.style.color="#999",H.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=`${Y}`,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=W.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>Y&&(s.value=`${G}%`,t-=Number(s.value)),H.textContent=`${t} / 100 %`})),a.appendChild(s),a.appendChild(n),t.appendChild(a),W.appendChild(t)})),Q.appendChild(W),Q.appendChild(H),c.appendChild(Q);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 C=document.createElement("label");if(C.setAttribute("for",`magicfeedback-${l}`),C.textContent=n(u,i),C.classList.add("magicfeedback-label"),["CONSENT"].includes(p))v.classList.add("magicfeedback-consent-container"),v.appendChild(c),v.appendChild(C);else{if("slim"!==t&&(v.appendChild(C),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const e=document.createElement("img");e.src=b.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",v.appendChild(e)}if("LONGTEXT"===p){const e=document.createElement("div");if(e.classList.add("magicfeedback-counter"),e.textContent="0/300",e.style.textAlign="right",e.style.fontSize="0.8em",e.style.color="#999",e.style.marginTop="5px",c.addEventListener("input",(()=>{e.textContent=`${c.value.length}/300`})),v.appendChild(c),v.appendChild(e),b.extraOption&&b.extraOptionText){const e=document.createElement("div");e.classList.add("magicfeedback-skip-container"),e.classList.add("magicfeedback-checkbox-container"),e.style.display="flex",e.style.justifyContent="flex-start";const t=document.createElement("input");t.classList.add("magicfeedback-skip"),t.type="checkbox",t.id=`skip-${m}`,t.name=m,t.value="-",t.style.cursor="pointer";const i=document.createElement("label");i.htmlFor=`skip-${m}`,i.textContent=b.extraOptionText,i.style.fontSize="0.8em",i.style.color="#999",i.style.cursor="pointer",i.style.margin="0 5px",t.addEventListener("click",(()=>{c.value="-",o&&o()})),e.appendChild(t),e.appendChild(i),v.appendChild(e)}}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.6-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})()));
|
|
@@ -16,6 +16,7 @@ export declare class Form {
|
|
|
16
16
|
private readonly feedback;
|
|
17
17
|
questions: NativeQuestion[];
|
|
18
18
|
private questionInProcess;
|
|
19
|
+
private censorQuestions;
|
|
19
20
|
private readonly history;
|
|
20
21
|
private elementQuestions;
|
|
21
22
|
progress: number;
|
|
@@ -74,6 +75,17 @@ export declare class Form {
|
|
|
74
75
|
* TODO: Required
|
|
75
76
|
*/
|
|
76
77
|
answer(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Finish the form
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
finish(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Censure questions form the form
|
|
85
|
+
* @param questions
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
censureQuestions(questions: string[]): void;
|
|
77
89
|
/**
|
|
78
90
|
* Send
|
|
79
91
|
* @param completed
|
|
@@ -96,7 +108,6 @@ export declare class Form {
|
|
|
96
108
|
/**
|
|
97
109
|
* Render next question
|
|
98
110
|
* @param form
|
|
99
|
-
* @param container
|
|
100
111
|
* @private
|
|
101
112
|
*/
|
|
102
113
|
private renderNextQuestion;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const placeholder: {
|
|
2
|
-
answer: (language: string) => "Write your answer here..." | "Escribe tu respuesta aquí..." | "Skriv dit svar her..." | "Kirjoita vastauksesi tähän..." | "Skriv ditt svar här..." | "Skriv svaret ditt her...";
|
|
3
|
-
number: (language: string) => "Write your number here..." | "Escribe tu número aquí..." | "Skriv dit nummer her..." | "Kirjoita numerosi tähän..." | "Skriv ditt nummer här..." | "Skriv nummeret ditt her...";
|
|
4
|
-
email: (language: string) => "Write your email here..." | "Escribe tu correo electrónico aquí..." | "Skriv din e-mail her..." | "Kirjoita sähköpostiosoitteesi tähän..." | "Skriv din e-post här..." | "Skriv e-posten din her...";
|
|
5
|
-
date: (language: string) => "Write your date here..." | "Escribe tu fecha aquí..." | "Skriv din dato her..." | "Kirjoita päivämääräsi tähän..." | "Skriv ditt datum här..." | "Skriv datoen din her...";
|
|
6
|
-
password: (language: string) => "Write your password here..." | "Escribe tu contraseña aquí..." | "Skriv dit kodeord her..." | "Kirjoita salasanasi tähän..." | "Skriv ditt lösenord här..." | "Skriv passordet ditt her...";
|
|
2
|
+
answer: (language: string) => "Write your answer here..." | "Escribe tu respuesta aquí..." | "Skriv dit svar her..." | "Kirjoita vastauksesi tähän..." | "Skriv ditt svar här..." | "Skriv svaret ditt her..." | "اكتب إجابتك هنا..." | "এখানে আপনার";
|
|
3
|
+
number: (language: string) => "এখানে আপনার" | "Write your number here..." | "Escribe tu número aquí..." | "Skriv dit nummer her..." | "Kirjoita numerosi tähän..." | "Skriv ditt nummer här..." | "Skriv nummeret ditt her..." | "اكتب رقمك هنا...";
|
|
4
|
+
email: (language: string) => "এখানে আপনার" | "Write your email here..." | "Escribe tu correo electrónico aquí..." | "Skriv din e-mail her..." | "Kirjoita sähköpostiosoitteesi tähän..." | "Skriv din e-post här..." | "Skriv e-posten din her..." | "اكتب بريدك الإلكتروني هنا...";
|
|
5
|
+
date: (language: string) => "এখানে আপনার" | "Write your date here..." | "Escribe tu fecha aquí..." | "Skriv din dato her..." | "Kirjoita päivämääräsi tähän..." | "Skriv ditt datum här..." | "Skriv datoen din her..." | "اكتب تاريخك هنا...";
|
|
6
|
+
password: (language: string) => "এখানে আপনার" | "Write your password here..." | "Escribe tu contraseña aquí..." | "Skriv dit kodeord her..." | "Kirjoita salasanasi tähän..." | "Skriv ditt lösenord här..." | "Skriv passordet ditt her..." | "اكتب كلمة المرور الخاصة بك هنا...";
|
|
7
7
|
};
|