@magicfeedback/native 1.2.5-beta.5 → 1.2.5-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -291,7 +291,8 @@ Feel free to adapt and expand upon the provided styles to match your desired des
|
|
|
291
291
|
.magicfeedback-rating-option-label-container,
|
|
292
292
|
.magicfeedback-number,
|
|
293
293
|
.magicfeedback-longtext,
|
|
294
|
-
.magicfeedback-text
|
|
294
|
+
.magicfeedback-text,
|
|
295
|
+
.magicfeedback-priority-list{
|
|
295
296
|
/* ... add your generic input styles here ... */
|
|
296
297
|
}
|
|
297
298
|
|
|
@@ -312,7 +313,8 @@ Feel free to adapt and expand upon the provided styles to match your desired des
|
|
|
312
313
|
.magicfeedback-boolean-container,
|
|
313
314
|
.magicfeedback-consent-container,
|
|
314
315
|
.magicfeedback-checkbox-container,
|
|
315
|
-
.magicfeedback-longtext-container
|
|
316
|
+
.magicfeedback-longtext-container,
|
|
317
|
+
.magicfeedback-priority-list-container{
|
|
316
318
|
/* ... add styles for radio/checkbox containers ... */
|
|
317
319
|
}
|
|
318
320
|
|
|
@@ -414,7 +416,24 @@ Feel free to adapt and expand upon the provided styles to match your desired des
|
|
|
414
416
|
/* ... add your multiple choice image image styles here ... */
|
|
415
417
|
}
|
|
416
418
|
|
|
417
|
-
|
|
419
|
+
/* Section for priority-list */
|
|
420
|
+
.magicfeedback-priority-list-container {
|
|
421
|
+
/* ... add your priority list container styles here ... */
|
|
422
|
+
}
|
|
423
|
+
.magicfeedback-priority-list-list {
|
|
424
|
+
/* ... add your priority list list styles here ... */
|
|
425
|
+
}
|
|
426
|
+
.magicfeedback-priority-list-item{
|
|
427
|
+
/* ... add your priority list item styles here ... */
|
|
428
|
+
}
|
|
429
|
+
.magicfeedback-priority-list-item-label{
|
|
430
|
+
/* ... add your priority list item label styles here ... */
|
|
431
|
+
}
|
|
432
|
+
.magicfeedback-priority-list-arrow-up,
|
|
433
|
+
.magicfeedback-priority-list-arrow-down{
|
|
434
|
+
/* ... add your priority list arrow up styles here ... */
|
|
435
|
+
|
|
436
|
+
}
|
|
418
437
|
/* Action buttons container */
|
|
419
438
|
.magicfeedback-action-container {
|
|
420
439
|
/* ... add your action button container styles here ... */
|
|
@@ -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,n="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,r="ArrayBuffer"in e;if(r)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return 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:n&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&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,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)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[d(e)]},p.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},p.prototype.set=function(e,t){this.map[d(e)]=l(t)},p.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},p.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},p.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},p.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},a&&(p.prototype[Symbol.iterator]=p.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,a,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=(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)&&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("="),a=i.shift().replace(/\+/g," "),n=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(a),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(a,s){var r=new v(e,i);if(r.signal&&r.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function c(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new p,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),a=i.shift().trim();if(a){var n=i.join(":").trim();t.append(a,n)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var n="response"in o?o.response:o.responseText;a(new k(n,i))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(r.method,r.url,!0),"include"===r.credentials?o.withCredentials=!0:"omit"===r.credentials&&(o.withCredentials=!1),"responseType"in o&&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})}({})}(a),a.fetch.ponyfill=!0,delete a.fetch.polyfill;var n=a;(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 a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=a(i(519));let s=null;s||(s=(0,n.default)()),t.default=s},519:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function r(e){try{c(a.next(e))}catch(e){s(e)}}function o(e){try{c(a.throw(e))}catch(e){s(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((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(954),s=i(712),r=i(5),o=i(341),c=i(290);t.default=function(){const e=new s.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,n,s,r=!0,c,d){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),n||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:n,privateKey:d,completed:r,id:c,feedback:s};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 n.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(n,s){function r(e){try{c(a.next(e))}catch(e){s(e)}}function o(e){try{c(a.throw(e))}catch(e){s(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((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const n=i(5),s=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.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,s.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,a;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,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,s.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i;try{this.questions.sort(((e,t)=>e.position-t.position));let a=this.generateContainer();const n=document.createElement("form");n.classList.add("magicfeedback-form"),n.id="magicfeedback-"+this.appId;const s=document.createElement("div");if(s.classList.add("magicfeedback-questions"),s.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,r.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,s.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>s.appendChild(e))),n.appendChild(s),a.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 a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-container-"+this.appId),s=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,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(a,s)),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;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const a=e.type,n=e.classList[0],r={key:e.name,value:[]},o="magicfeedback-consent"===n?e.checked.toString():e.value;if(r.key&&""!==r.key)switch(a){case"radio":case"checkbox":if("magicfeedback-consent"===n||e.checked){r.value.push(o);const e=t.findIndex((e=>e.key===r.key));-1!==e?t[e].value=[...t[e].value,...r.value]:t.push(r)}break;default:if(""!==o){if("email"===a){if(!(0,s.validateEmail)(o)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[o]})}r.value.push(o);const e=t.findIndex((e=>e.key===r.key));console.log(e,t),-1!==e?t[e].value=[...t[e].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"),n={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(a,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 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,s.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,n,s,o;return a(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 i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,r.renderQuestions)([i],null===(s=this.formOptionsConfig)||void 0===s?void 0:s.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object: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),n=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",r="en",o){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var d,l;if((null===(l=null===(d=null==t?void 0:t.questionType)||void 0===d?void 0:d.conf)||void 0===l?void 0:l.length)>0){let 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?s(d,i):`${f.placeholder||n.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?s(d,i):n.placeholder.answer(i||"en"),b="magicfeedback-longtext";break;case a.FEEDBACKAPPANSWERTYPE.NUMBER:g=document.createElement("input"),g.type="number",g.placeholder="slim"===t?s(d,i):`${f.placeholder||n.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"),n=document.createElement("input");if(n.id=`rating-${u}-${t}`,n.type="MULTIPLECHOICE"===l?"checkbox":"radio",n.name=u,n.value="-",n.classList.add(b),n.classList.add("magicfeedback-input"),e===m&&(n.checked=!0),a.textContent=e,a.htmlFor=`rating-${u}-${t}`,f.extraOption&&e===f.extraOptionText&&n.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${u}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),i.appendChild(n),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 n=document.createElement("label");n.htmlFor=`rating-${u}-${i}`,n.textContent=t,n.style.margin="0",n.style.padding="0";const s=document.createElement("input");s.id=`rating-${u}-${i}`,s.type="radio",s.name=u,s.value=t,s.classList.add(b),s.classList.add("magicfeedback-input"),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.style.margin="0",a.appendChild(s),a.appendChild(n),e.appendChild(a)})),g.appendChild(e);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:g=document.createElement("div"),b="magicfeedback-rating";const r=document.createElement("div");r.classList.add("magicfeedback-rating-container");const v=f.max?Number(f.max):5,E=f.min?Number(f.min):1,k=document.createElement("div");if(k.classList.add("magicfeedback-rating-placeholder"),k.style.display="flex",k.style.justifyContent="space-between",k.style.width="90%",k.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",k.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",k.appendChild(e)}for(let e=E;e<=v;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 n=document.createElement("img");if(n.alt=`face-${u}-${e}`,n.className=`rating-image${e}`,0===E&&10===v)n.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===E&&5===v)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/(v-E)*(e-E));n.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}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(n),i.appendChild(a),t.appendChild(i),r.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 n=document.createElement("input");n.id=`rating-${u}-extra`,n.type="radio",n.name=u,n.value="-",n.classList.add(b),n.classList.add("magicfeedback-input"),t.appendChild(n),t.appendChild(a),t.appendChild(i),e.appendChild(t),r.appendChild(e)}g.appendChild(k),g.appendChild(r);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:g=document.createElement("div"),b="magicfeedback-rating-number";const C=document.createElement("div");C.classList.add("magicfeedback-rating-number-container");const x=f.max?Number(f.max):5,w=f.min?Number(f.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",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",A.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",A.appendChild(e)}for(let e=w;e<=x;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 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(a),t.appendChild(i),C.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),C.appendChild(e)}g.appendChild(A),g.appendChild(C);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 n=document.createElement("label");n.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${a}`,s.type="radio",s.name=e,s.value=a.toString(),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.classList.add("magicfeedback-input"),s.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(s.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),n.appendChild(s);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",n.appendChild(r),i.appendChild(n)}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 L=h.length;let O=1,I=1;switch(L){case 1:case 2:case 3:O=L,I=1;break;case 4:case 5:case 6:I=2,O=Math.ceil(L/2);break;default:I=3,O=Math.ceil(L/3)}const P=void 0!==f.addTitle&&f.addTitle;h.forEach((e=>{try{const{position:t,url:i,value:a}=JSON.parse(e),n=document.createElement("label");n.classList.add("magicfeedback-multiple-choice-image-option"),n.style.width=`calc( ${100/O}% - 10px)`,n.style.height=`calc( ${100/I}% - 10px)`,n.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${u}-${t}`,s.classList.add("magicfeedback-image-option-label-container"),s.style.display="flex",s.style.flexDirection="column",s.addEventListener("mouseover",(()=>{s.style.border="2px solid #000"})),s.addEventListener("mouseout",(()=>{s.style.border="none"})),s.addEventListener("click",(()=>{s.style.border="2px solid #000"}));const r=document.createElement("label");r.textContent=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",s.appendChild(o),s.appendChild(c),P&&s.appendChild(r),n.appendChild(s),T.appendChild(n)}catch(e){console.error(e)}})),g.appendChild(T);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:g=document.createElement("select"),b="magicfeedback-select";const N=document.createElement("option");N.value="",N.text="slim"===t?s(d,i):m||"Select an option",N.disabled=!0,N.selected=!0,g.appendChild(N),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?s(d,i):`${f.placeholder||n.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?s(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?s(d,i):`${f.placeholder||n.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 $=document.createElement("thead"),M=document.createElement("tr");["",...h].forEach((e=>{const t=document.createElement("th");t.textContent=e,M.appendChild(t)})),$.appendChild(M);const R=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"),i=document.createElement("td");i.textContent=e,t.appendChild(i),h.forEach((i=>{const a=document.createElement("td"),n=document.createElement("input");n.type="checkbox",n.name=`${e}`,n.value=i,n.classList.add("magicfeedback-input"),a.appendChild(n),t.appendChild(a)})),R.appendChild(t)})),D.appendChild($),D.appendChild(R),_.appendChild(D),g.appendChild(_);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:g=document.createElement("div"),b="magicfeedback-priority-list";const F=document.createElement("div");F.classList.add("magicfeedback-priority-list-container");const B=document.createElement("ul");B.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-lis"),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 n=document.createElement("label");n.classList.add("magicfeedback-priority-list-item-label"),n.textContent=`${t+1}. ${e}`,i.appendChild(n);const s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between";const r=document.createElement("span");r.classList.add("magicfeedback-priority-list-arrow-up"),r.textContent=">",r.style.fontSize="1.5em",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(-90deg)",r.style.visibility=0===t?"hidden":"visible",r.addEventListener("click",(()=>{var t,s;const o=i.previousElementSibling;if(o){const c=Number(a.value.split(".")[0])-1;a.value=`${c}. ${e}`,n.textContent=`${c}. ${e}`,r.style.visibility=1===c?"hidden":"visible";const d=o.querySelector(".magicfeedback-input-magicfeedback-priority-lis"),l=o.querySelector(".magicfeedback-priority-list-item-label"),u=o.querySelector(".magicfeedback-priority-list-arrow-up"),p=o.querySelector(".magicfeedback-priority-list-arrow-down");if(d&&l&&u&&p){const e=Number(d.value.split(".")[0])+1;d.value=`${e}.${null===(t=l.textContent)||void 0===t?void 0:t.split(".")[1]}`,l.textContent=`${e}.${null===(s=l.textContent)||void 0===s?void 0:s.split(".")[1]}`,u.style.visibility=0===e?"hidden":"visible",p.style.visibility=e===h.length?"hidden":"visible"}B.insertBefore(i,o)}})),s.appendChild(r);const o=document.createElement("span");o.classList.add("magicfeedback-priority-list-arrow-down"),o.textContent=">",o.style.fontSize="1.5em",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.transform="rotate(90deg)",o.style.visibility=t===h.length-1?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const r=i.nextElementSibling;if(r){const c=Number(a.value.split(".")[0])+1;a.value=c.toString(),n.textContent=`${c.toString()}. ${e}`,o.style.visibility=c===h.length?"hidden":"visible";const d=r.querySelector(".magicfeedback-input-magicfeedback-priority-lis"),l=r.querySelector(".magicfeedback-priority-list-item-label"),u=r.querySelector(".magicfeedback-priority-list-arrow-up"),p=r.querySelector(".magicfeedback-priority-list-arrow-down");if(d&&l&&u&&p){const e=Number(d.value.split(".")[0])-1;d.value=`${e}.${null===(t=l.textContent)||void 0===t?void 0:t.split(".")[1]}`,l.textContent=`${e}.${null===(s=l.textContent)||void 0===s?void 0:s.split(".")[1]}`,u.style.visibility=0===Number(d.value)?"hidden":"visible",p.style.visibility=Number(d.value)===h.length-1?"hidden":"visible"}B.insertBefore(r,i)}})),s.appendChild(o),i.appendChild(s),B.appendChild(i)})),F.appendChild(B),g.appendChild(F);break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:g=document.createElement("div"),b="magicfeedback-point-system";const q=document.createElement("div");q.classList.add("magicfeedback-point-system-container");const j=document.createElement("ul");j.classList.add("magicfeedback-point-system-list"),j.style.padding="0";const U=100,K=U/h.length,W=document.createElement("div");W.classList.add("magicfeedback-point-system-total"),W.textContent="0 / 100 %",W.style.textAlign="right",W.style.fontSize="0.8em",W.style.color="#999",W.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"),n=document.createElement("input");n.name=`point-system-${u}-${e}`,n.id=`point-system-${u}-${e}`,n.type="number",n.min="0",n.max=`${U}`,n.value="0",n.classList.add("magicfeedback-input"),n.style.width="40px",n.style.border="0",n.style.textAlign="center",n.style.margin="0 5px";const s=document.createElement("span");s.textContent="%",s.style.color="#000",n.addEventListener("input",(()=>{const e=j.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>U&&(n.value=`${K}%`,t-=Number(n.value)),W.textContent=`${t} / 100 %`})),a.appendChild(n),a.appendChild(s),t.appendChild(a),j.appendChild(t)})),q.appendChild(j),q.appendChild(W),g.appendChild(q);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=s(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.style.display="flex",e.style.justifyContent="space-between";const t=document.createElement("button");t.textContent=f.extraOptionText,t.classList.add("magicfeedback-skip"),t.style.cursor="pointer",t.type="button",t.addEventListener("click",(()=>{g.value="-",r&&r()})),e.appendChild(t),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",n="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?n||"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&&s.appendChild(o),s.appendChild(r),s},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,i=!1,a="Go!"){const n=document.createElement("div");n.classList.add("magicfeedback-start-message-container");const s=document.createElement("div");s.classList.add("magicfeedback-start-message"),s.innerHTML=e;const 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())),n.appendChild(s),i&&n.appendChild(r),n}},341:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function r(e){try{c(a.next(e))}catch(e){s(e)}}function o(e){try{c(a.throw(e))}catch(e){s(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((a=a.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const s=n(i(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 a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return n.log(`Received form for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),null}}))},t.getQuestions=function(e,t,i,n){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+o.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return n.log(`Received questions for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+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,s.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-beta.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 n=t[a];if(void 0!==n)return n.exports;var s=t[a]={exports:{}};return e[a].call(s.exports,s,s.exports,i),s.exports}(607).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,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,n="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,r="ArrayBuffer"in e;if(r)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return 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:n&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&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,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)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[d(e)]},p.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},p.prototype.set=function(e,t){this.map[d(e)]=l(t)},p.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},p.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},p.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},p.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},a&&(p.prototype[Symbol.iterator]=p.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,a,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=(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)&&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("="),a=i.shift().replace(/\+/g," "),n=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(a),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(a,s){var r=new v(e,i);if(r.signal&&r.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function c(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new p,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),a=i.shift().trim();if(a){var n=i.join(":").trim();t.append(a,n)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var n="response"in o?o.response:o.responseText;a(new k(n,i))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(r.method,r.url,!0),"include"===r.credentials?o.withCredentials=!0:"omit"===r.credentials&&(o.withCredentials=!1),"responseType"in o&&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})}({})}(a),a.fetch.ponyfill=!0,delete a.fetch.polyfill;var n=a;(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 a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=a(i(519));let s=null;s||(s=(0,n.default)()),t.default=s},519:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function r(e){try{c(a.next(e))}catch(e){s(e)}}function o(e){try{c(a.throw(e))}catch(e){s(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((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(954),s=i(712),r=i(5),o=i(341),c=i(290);t.default=function(){const e=new s.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,n,s,r=!0,c,d){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),n||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:n,privateKey:d,completed:r,id:c,feedback:s};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 n.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(n,s){function r(e){try{c(a.next(e))}catch(e){s(e)}}function o(e){try{c(a.throw(e))}catch(e){s(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((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const n=i(5),s=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.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,s.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,a;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,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,s.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(i=this.formData.style)||void 0===i?void 0:i.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i;try{this.questions.sort(((e,t)=>e.position-t.position));let a=this.generateContainer();const n=document.createElement("form");n.classList.add("magicfeedback-form"),n.id="magicfeedback-"+this.appId;const s=document.createElement("div");if(s.classList.add("magicfeedback-questions"),s.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,r.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],(()=>this.send())),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,s.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>s.appendChild(e))),n.appendChild(s),a.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 a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-container-"+this.appId),s=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,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(a,s)),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 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="";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"===n){if(!(0,s.validateEmail)(c)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[c]})}if(e.id.includes("point-system")){const t=e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${c}%`)}else o.value.push(c);const 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"),n={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(a,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 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,s.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,n,s,o;return a(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 i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,r.renderQuestions)([i],null===(s=this.formOptionsConfig)||void 0===s?void 0:s.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object: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),n=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",r="en",o){if(!t)throw new Error("[MagicFeedback] No questions provided");const c=[];return t.forEach((t=>{var d,l;if((null===(l=null===(d=null==t?void 0:t.questionType)||void 0===d?void 0:d.conf)||void 0===l?void 0:l.length)>0){let 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?s(d,i):`${f.placeholder||n.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?s(d,i):n.placeholder.answer(i||"en"),b="magicfeedback-longtext";break;case a.FEEDBACKAPPANSWERTYPE.NUMBER:g=document.createElement("input"),g.type="number",g.placeholder="slim"===t?s(d,i):`${f.placeholder||n.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"),n=document.createElement("input");if(n.id=`rating-${u}-${t}`,n.type="MULTIPLECHOICE"===l?"checkbox":"radio",n.name=u,n.value="-",n.classList.add(b),n.classList.add("magicfeedback-input"),e===m&&(n.checked=!0),a.textContent=e,a.htmlFor=`rating-${u}-${t}`,f.extraOption&&e===f.extraOptionText&&n.addEventListener("change",(e=>{const t=document.getElementById(`extra-option-${u}`);t&&(e.target.checked?t.style.display="block":t.style.display="none")})),i.appendChild(n),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 n=document.createElement("label");n.htmlFor=`rating-${u}-${i}`,n.textContent=t,n.style.margin="0",n.style.padding="0";const s=document.createElement("input");s.id=`rating-${u}-${i}`,s.type="radio",s.name=u,s.value=t,s.classList.add(b),s.classList.add("magicfeedback-input"),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.style.margin="0",s.addEventListener("change",(()=>{r&&r()})),a.appendChild(s),a.appendChild(n),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 n=document.createElement("img");if(n.alt=`face-${u}-${e}`,n.className=`rating-image${e}`,0===k&&10===E)n.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===k&&5===E)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/(E-k)*(e-k));n.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`}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(n),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 n=document.createElement("input");n.id=`rating-${u}-extra`,n.type="radio",n.name=u,n.value="-",n.classList.add(b),n.classList.add("magicfeedback-input"),t.appendChild(n),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,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=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 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(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 L=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 n=document.createElement("label");n.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${a}`,s.type="radio",s.name=e,s.value=a.toString(),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.classList.add("magicfeedback-input"),s.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(s.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),n.appendChild(s);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",n.appendChild(r),i.appendChild(n)}return i}(u);g.appendChild(L);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),n=document.createElement("label");n.classList.add("magicfeedback-multiple-choice-image-option"),n.style.width=`calc( ${100/I}% - 10px)`,n.style.height=`calc( ${100/P}% - 10px)`,n.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${u}-${t}`,s.classList.add("magicfeedback-image-option-label-container"),s.style.display="flex",s.style.flexDirection="column",s.addEventListener("mouseover",(()=>{s.style.border="2px solid #000"})),s.addEventListener("mouseout",(()=>{s.style.border="none"})),s.addEventListener("click",(()=>{s.style.border="2px solid #000"}));const r=document.createElement("label");r.textContent=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",s.appendChild(o),s.appendChild(c),N&&s.appendChild(r),n.appendChild(s),T.appendChild(n)}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?s(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?s(d,i):`${f.placeholder||n.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?s(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?s(d,i):`${f.placeholder||n.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"),R=document.createElement("tr");["",...h].forEach((e=>{const t=document.createElement("th");t.textContent=e,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"),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.textContent=e,i.appendChild(a),t.appendChild(i),h.forEach((i=>{const a=document.createElement("td"),n=document.createElement("input");n.type="checkbox",n.name=u,n.value=i,n.id=`matrix-${e}`,n.classList.add("magicfeedback-input"),a.appendChild(n),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 n=document.createElement("label");n.classList.add("magicfeedback-priority-list-item-label"),n.textContent=`${t+1}. ${e}`,i.appendChild(n);const s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between";const r=document.createElement("span");r.classList.add("magicfeedback-priority-list-arrow-up"),r.textContent=">",r.style.fontSize="1.5em",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(-90deg)",r.style.visibility=0===t?"hidden":"visible",r.addEventListener("click",(()=>{var t,s;const c=i.previousElementSibling;if(c){const d=Number(a.value.split(".")[0])-1;a.value=`${d}. ${e}`,n.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===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===h.length?"hidden":"visible"}q.insertBefore(i,c)}})),s.appendChild(r);const o=document.createElement("span");o.classList.add("magicfeedback-priority-list-arrow-down"),o.textContent=">",o.style.fontSize="1.5em",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.transform="rotate(90deg)",o.style.visibility=t===h.length-1?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const c=i.nextElementSibling;if(c){const d=Number(a.value.split(".")[0])+1;a.value=d.toString(),n.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===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===h.length?"hidden":"visible"}q.insertBefore(c,i)}})),s.appendChild(o),i.appendChild(s),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"),n=document.createElement("input");n.name=u,n.id=`point-system-${e}`,n.type="number",n.min="0",n.max=`${K}`,n.value="0",n.classList.add("magicfeedback-input"),n.style.width="40px",n.style.border="0",n.style.textAlign="center",n.style.margin="0 5px";const s=document.createElement("span");s.textContent="%",s.style.color="#000",n.addEventListener("input",(()=>{const e=U.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>K&&(n.value=`${W}%`,t-=Number(n.value)),Y.textContent=`${t} / 100 %`})),a.appendChild(n),a.appendChild(s),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=s(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",n="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?n||"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&&s.appendChild(o),s.appendChild(r),s},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t,i=!1,a="Go!"){const n=document.createElement("div");n.classList.add("magicfeedback-start-message-container");const s=document.createElement("div");s.classList.add("magicfeedback-start-message"),s.innerHTML=e;const 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())),n.appendChild(s),i&&n.appendChild(r),n}},341:function(e,t,i){"use strict";var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(n,s){function r(e){try{c(a.next(e))}catch(e){s(e)}}function o(e){try{c(a.throw(e))}catch(e){s(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((a=a.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const s=n(i(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 a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return n.log(`Received form for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),null}}))},t.getQuestions=function(e,t,i,n){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+o.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return n.log(`Received questions for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,s.default)(e+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,s.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-beta.7","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 n=t[a];if(void 0!==n)return n.exports;var s=t[a]={exports:{}};return e[a].call(s.exports,s,s.exports,i),s.exports}(607).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;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const a=e.type,s=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===s?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(a){case"radio":case"checkbox":if("magicfeedback-consent"===s||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===a){if(!(0,n.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}o.value.push(r);const e=t.findIndex((e=>e.key===o.key));console.log(e,t),-1!==e?t[e].value=[...t[e].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,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",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 o=document.createElement("div");o.classList.add("magicfeedback-rating-container");const y=f.max?Number(f.max):5,E=f.min?Number(f.min):1,k=document.createElement("div");if(k.classList.add("magicfeedback-rating-placeholder"),k.style.display="flex",k.style.justifyContent="space-between",k.style.width="90%",k.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",k.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",k.appendChild(e)}for(let e=E;e<=y;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===E&&10===y)s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;else if(1===E&&5===y)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/(y-E)*(e-E));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),o.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),o.appendChild(e)}g.appendChild(k),g.appendChild(o);break;case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:g=document.createElement("div"),b="magicfeedback-rating-number";const C=document.createElement("div");C.classList.add("magicfeedback-rating-number-container");const x=f.max?Number(f.max):5,w=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=w;e<=x;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),C.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),C.appendChild(e)}g.appendChild(L),g.appendChild(C);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 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(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 A=m.length;let I=1,O=1;switch(A){case 1:case 2:case 3:I=A,O=1;break;case 4:case 5:case 6:O=2,I=Math.ceil(A/2);break;default:O=3,I=Math.ceil(A/3)}const N=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/I}% - 10px)`,s.style.height=`calc( ${100/O}% - 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),N&&n.appendChild(o),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 P=document.createElement("option");P.value="",P.text="slim"===t?n(d,i):h||"Select an option",P.disabled=!0,P.selected=!0,g.appendChild(P),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 $=document.createElement("div");$.classList.add("magicfeedback-multi-question-matrix-container");const M=document.createElement("table");M.classList.add("magicfeedback-multi-question-matrix-table");const D=document.createElement("thead"),_=document.createElement("tr");["",...m].forEach((e=>{const t=document.createElement("th");t.textContent=e,_.appendChild(t)})),D.appendChild(_);const F=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"),i=document.createElement("td");i.textContent=e,t.appendChild(i),m.forEach((i=>{const a=document.createElement("td"),s=document.createElement("input");s.type="checkbox",s.name=`${e}`,s.value=i,s.classList.add("magicfeedback-input"),a.appendChild(s),t.appendChild(a)})),F.appendChild(t)})),M.appendChild(D),M.appendChild(F),$.appendChild(M),g.appendChild($);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:g=document.createElement("div"),b="magicfeedback-priority-list";const q=document.createElement("div");q.classList.add("magicfeedback-priority-list-container");const R=document.createElement("ul");R.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-lis"),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("span");o.classList.add("magicfeedback-priority-list-arrow-up"),o.textContent=">",o.style.fontSize="1.5em",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.transform="rotate(-90deg)",o.style.visibility=0===t?"hidden":"visible",o.addEventListener("click",(()=>{var t,n;const r=i.previousElementSibling;if(r){const c=Number(a.value.split(".")[0])-1;a.value=`${c}. ${e}`,s.textContent=`${c}. ${e}`,o.style.visibility=1===c?"hidden":"visible";const d=r.querySelector(".magicfeedback-input-magicfeedback-priority-lis"),l=r.querySelector(".magicfeedback-priority-list-item-label"),u=r.querySelector(".magicfeedback-priority-list-arrow-up"),p=r.querySelector(".magicfeedback-priority-list-arrow-down");if(d&&l&&u&&p){const e=Number(d.value.split(".")[0])+1;d.value=`${e}.${null===(t=l.textContent)||void 0===t?void 0:t.split(".")[1]}`,l.textContent=`${e}.${null===(n=l.textContent)||void 0===n?void 0:n.split(".")[1]}`,u.style.visibility=0===e?"hidden":"visible",p.style.visibility=e===m.length?"hidden":"visible"}R.insertBefore(i,r)}})),n.appendChild(o);const r=document.createElement("span");r.classList.add("magicfeedback-priority-list-arrow-down"),r.textContent=">",r.style.fontSize="1.5em",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(90deg)",r.style.visibility=t===m.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,n;const o=i.nextElementSibling;if(o){const c=Number(a.value.split(".")[0])+1;a.value=c.toString(),s.textContent=`${c.toString()}. ${e}`,r.style.visibility=c===m.length?"hidden":"visible";const d=o.querySelector(".magicfeedback-input-magicfeedback-priority-lis"),l=o.querySelector(".magicfeedback-priority-list-item-label"),u=o.querySelector(".magicfeedback-priority-list-arrow-up"),p=o.querySelector(".magicfeedback-priority-list-arrow-down");if(d&&l&&u&&p){const e=Number(d.value.split(".")[0])-1;d.value=`${e}.${null===(t=l.textContent)||void 0===t?void 0:t.split(".")[1]}`,l.textContent=`${e}.${null===(n=l.textContent)||void 0===n?void 0:n.split(".")[1]}`,u.style.visibility=0===Number(d.value)?"hidden":"visible",p.style.visibility=Number(d.value)===m.length-1?"hidden":"visible"}R.insertBefore(o,i)}})),n.appendChild(r),i.appendChild(n),R.appendChild(i)})),q.appendChild(R),g.appendChild(q);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 B=document.createElement("ul");B.classList.add("magicfeedback-point-system-list"),B.style.padding="0";const U=100,K=U/m.length,W=document.createElement("div");W.classList.add("magicfeedback-point-system-total"),W.textContent="0 / 100 %",W.style.textAlign="right",W.style.fontSize="0.8em",W.style.color="#999",W.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"),s=document.createElement("input");s.name=`point-system-${u}-${e}`,s.id=`point-system-${u}-${e}`,s.type="number",s.min="0",s.max=`${U}`,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=B.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>U&&(s.value=`${K}%`,t-=Number(s.value)),W.textContent=`${t} / 100 %`})),a.appendChild(s),a.appendChild(n),t.appendChild(a),B.appendChild(t)})),j.appendChild(B),j.appendChild(W),g.appendChild(j);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.style.display="flex",e.style.justifyContent="space-between";const t=document.createElement("button");t.textContent=f.extraOptionText,t.classList.add("magicfeedback-skip"),t.style.cursor="pointer",t.type="button",t.addEventListener("click",(()=>{g.value="-",o&&o()})),e.appendChild(t),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-beta.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.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"),F=document.createElement("tr");["",...m].forEach((e=>{const t=document.createElement("th");t.textContent=e,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"),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.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"),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("span");o.classList.add("magicfeedback-priority-list-arrow-up"),o.textContent=">",o.style.fontSize="1.5em",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.transform="rotate(-90deg)",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("span");r.classList.add("magicfeedback-priority-list-arrow-down"),r.textContent=">",r.style.fontSize="1.5em",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(90deg)",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"),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-beta.7","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})()));
|